Skip to content

Commit 074b1a8

Browse files
refactor: code
1 parent 919c8c4 commit 074b1a8

File tree

8 files changed

+35
-39
lines changed

8 files changed

+35
-39
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ module.exports = {
188188
### `minify`
189189

190190
Type: `Function|Array<Function>`
191-
Default: `CssMinimizerPlugin.cssnano`
191+
Default: `CssMinimizerPlugin.cssnanoMinify`
192192

193193
Allows to override default minify function.
194194
By default plugin uses [cssnano](https://github.com/cssnano/cssnano) package.
195195
Useful for using and testing unpublished versions or forks.
196196

197197
Possible options:
198198

199-
- CssMinimizerPlugin.cssnano
200-
- CssMinimizerPlugin.csso
201-
- CssMinimizerPlugin.cleanCss
199+
- CssMinimizerPlugin.cssnanoMinify
200+
- CssMinimizerPlugin.cssoMinify
201+
- CssMinimizerPlugin.cleanCssMinify
202202
- async (data, inputMap, minimizerOptions) => {return {code: `a{color: red}`, map: `...`, warnings: []}}
203203

204204
> ⚠️ **Always use `require` inside `minify` function when `parallel` option enabled**.
@@ -263,13 +263,13 @@ module.exports = {
263263
minimizer: [
264264
new CssMinimizerPlugin({
265265
minimizerOptions: [
266-
{}, // Options for the first function (CssMinimizerPlugin.cssnano)
267-
{}, // Options for the second function (CssMinimizerPlugin.cssClean)
266+
{}, // Options for the first function (CssMinimizerPlugin.cssnanoMinify)
267+
{}, // Options for the second function (CssMinimizerPlugin.cleanCssMinify)
268268
{}, // Options for the third function
269269
],
270270
minify: [
271-
CssMinimizerPlugin.cssnano,
272-
CssMinimizerPlugin.cssClean,
271+
CssMinimizerPlugin.cssnanoMinify,
272+
CssMinimizerPlugin.cleanCssMinify,
273273
async (data, inputMap, minimizerOptions) => {
274274
// To do something
275275
return {

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
"dist"
3939
],
4040
"peerDependencies": {
41-
"clean-css": "^5.1.2",
42-
"csso": "^4.2.0",
4341
"webpack": "^5.0.0"
4442
},
4543
"peerDependenciesMeta": {

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ class CssMinimizerPlugin {
449449
}
450450
}
451451

452-
CssMinimizerPlugin.cssnano = cssnanoMinify;
453-
CssMinimizerPlugin.csso = cssoMinify;
454-
CssMinimizerPlugin.cleanCss = cleanCssMinify;
452+
CssMinimizerPlugin.cssnanoMinify = cssnanoMinify;
453+
CssMinimizerPlugin.cssoMinify = cssoMinify;
454+
CssMinimizerPlugin.cleanCssMinify = cleanCssMinify;
455455

456456
export default CssMinimizerPlugin;

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function cssnanoMinify(
8989

9090
/* istanbul ignore next */
9191
async function cssoMinify(data, inputSourceMap, minimizerOptions) {
92-
// eslint-disable-next-line global-require
92+
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
9393
const csso = require('csso');
9494
// eslint-disable-next-line global-require
9595
const sourcemap = require('source-map');
@@ -115,7 +115,7 @@ async function cssoMinify(data, inputSourceMap, minimizerOptions) {
115115

116116
/* istanbul ignore next */
117117
async function cleanCssMinify(data, inputSourceMap, minimizerOptions) {
118-
// eslint-disable-next-line global-require
118+
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
119119
const CleanCSS = require('clean-css');
120120
const [[name, input]] = Object.entries(data);
121121
const result = await new CleanCSS({

test/__snapshots__/minify-option.test.js.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,45 +60,45 @@ exports[`"minify" option should work if minify is array && minimizerOptions is o
6060

6161
exports[`"minify" option should work if minify is array && minimizerOptions is object: warning 1`] = `Array []`;
6262

63-
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCss" minifier: assets 1`] = `
63+
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier: assets 1`] = `
6464
Object {
6565
"foo.css": "body{color:red}a{color:#00f}
6666
/*# sourceMappingURL=foo.css.map*/",
6767
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./foo.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KACE,MAAO,IAET,EACE,MAAO\\",\\"file\\":\\"foo.css\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}",
6868
}
6969
`;
7070

71-
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCss" minifier: error 1`] = `Array []`;
71+
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier: error 1`] = `Array []`;
7272

73-
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCss" minifier: warning 1`] = `Array []`;
73+
exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier: warning 1`] = `Array []`;
7474

75-
exports[`"minify" option should work with "CssMinimizerPlugin.cssnano" and parser option as "String": entry.js.map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///webpack/bootstrap\\",\\"webpack:///webpack/runtime/define property getters\\",\\"webpack:///webpack/runtime/hasOwnProperty shorthand\\",\\"webpack:///webpack/runtime/make namespace object\\",\\"webpack:///./sugarss.js\\"],\\"names\\":[],\\"mappings\\":\\";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,wCAAwC,yCAAyC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,sDAAsD,kBAAkB;WACxE;WACA,+CAA+C,cAAc;WAC7D,E;;;;;;;;;;;;ACNO\\",\\"file\\":\\"entry.js\\",\\"sourcesContent\\":[\\"// The require scope\\\\nvar __webpack_require__ = {};\\\\n\\\\n\\",\\"// define getter functions for harmony exports\\\\n__webpack_require__.d = (exports, definition) => {\\\\n\\\\tfor(var key in definition) {\\\\n\\\\t\\\\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\\\\n\\\\t\\\\t\\\\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\\\\n\\\\t\\\\t}\\\\n\\\\t}\\\\n};\\",\\"__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\\",\\"// define __esModule on exports\\\\n__webpack_require__.r = (exports) => {\\\\n\\\\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\\\\n\\\\t\\\\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\\\\n\\\\t}\\\\n\\\\tObject.defineProperty(exports, '__esModule', { value: true });\\\\n};\\",\\"export const foo = 'foo';\\\\n\\"],\\"sourceRoot\\":\\"\\"}"`;
75+
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String": entry.js.map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///webpack/bootstrap\\",\\"webpack:///webpack/runtime/define property getters\\",\\"webpack:///webpack/runtime/hasOwnProperty shorthand\\",\\"webpack:///webpack/runtime/make namespace object\\",\\"webpack:///./sugarss.js\\"],\\"names\\":[],\\"mappings\\":\\";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,wCAAwC,yCAAyC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,sDAAsD,kBAAkB;WACxE;WACA,+CAA+C,cAAc;WAC7D,E;;;;;;;;;;;;ACNO\\",\\"file\\":\\"entry.js\\",\\"sourcesContent\\":[\\"// The require scope\\\\nvar __webpack_require__ = {};\\\\n\\\\n\\",\\"// define getter functions for harmony exports\\\\n__webpack_require__.d = (exports, definition) => {\\\\n\\\\tfor(var key in definition) {\\\\n\\\\t\\\\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\\\\n\\\\t\\\\t\\\\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\\\\n\\\\t\\\\t}\\\\n\\\\t}\\\\n};\\",\\"__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\\",\\"// define __esModule on exports\\\\n__webpack_require__.r = (exports) => {\\\\n\\\\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\\\\n\\\\t\\\\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\\\\n\\\\t}\\\\n\\\\tObject.defineProperty(exports, '__esModule', { value: true });\\\\n};\\",\\"export const foo = 'foo';\\\\n\\"],\\"sourceRoot\\":\\"\\"}"`;
7676

77-
exports[`"minify" option should work with "CssMinimizerPlugin.cssnano" and parser option as "String": index.sss 1`] = `"a{color:#000}"`;
77+
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String": index.sss 1`] = `"a{color:#000}"`;
7878

79-
exports[`"minify" option should work with "CssMinimizerPlugin.cssnano": assets 1`] = `
79+
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": assets 1`] = `
8080
Object {
8181
"foo.css": "body{font-weight:700;color:red}body a{text-align:center}
8282
/*# sourceMappingURL=foo.css.map*/",
8383
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ\\",\\"file\\":\\"foo.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}",
8484
}
8585
`;
8686

87-
exports[`"minify" option should work with "CssMinimizerPlugin.cssnano": error 1`] = `Array []`;
87+
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": error 1`] = `Array []`;
8888

89-
exports[`"minify" option should work with "CssMinimizerPlugin.cssnano": warning 1`] = `Array []`;
89+
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": warning 1`] = `Array []`;
9090

91-
exports[`"minify" option should work with "CssMinimizerPlugin.csso" minifier: assets 1`] = `
91+
exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier: assets 1`] = `
9292
Object {
9393
"foo.css": "body{font-weight:700;color:red}body a{text-align:center}
9494
/*# sourceMappingURL=foo.css.map*/",
9595
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,I,CACE,e,CCEA,S,CACA,M,CACE,iB\\",\\"file\\":\\"foo.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}",
9696
}
9797
`;
9898

99-
exports[`"minify" option should work with "CssMinimizerPlugin.csso" minifier: error 1`] = `Array []`;
99+
exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier: error 1`] = `Array []`;
100100

101-
exports[`"minify" option should work with "CssMinimizerPlugin.csso" minifier: warning 1`] = `Array []`;
101+
exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier: warning 1`] = `Array []`;
102102

103103
exports[`"minify" option should work with "clean-css" minifier: assets 1`] = `
104104
Object {

test/minify-option.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('"minify" option', () => {
225225
expect(getWarnings(stats)).toMatchSnapshot('warning');
226226
});
227227

228-
it('should work with "CssMinimizerPlugin.cssnano"', async () => {
228+
it('should work with "CssMinimizerPlugin.cssnanoMinify"', async () => {
229229
const compiler = getCompiler({
230230
devtool: 'source-map',
231231
entry: {
@@ -249,7 +249,7 @@ describe('"minify" option', () => {
249249
minimizerOptions: {
250250
preset: 'default',
251251
},
252-
minify: [CssMinimizerPlugin.cssnano],
252+
minify: [CssMinimizerPlugin.cssnanoMinify],
253253
}).apply(compiler);
254254

255255
const stats = await compile(compiler);
@@ -261,7 +261,7 @@ describe('"minify" option', () => {
261261
expect(getWarnings(stats)).toMatchSnapshot('warning');
262262
});
263263

264-
it('should work with "CssMinimizerPlugin.cssnano" and parser option as "String"', async () => {
264+
it('should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String"', async () => {
265265
const compiler = getCompiler({
266266
devtool: 'source-map',
267267
entry: {
@@ -290,7 +290,7 @@ describe('"minify" option', () => {
290290
parser: 'sugarss',
291291
},
292292
},
293-
minify: [CssMinimizerPlugin.cssnano],
293+
minify: [CssMinimizerPlugin.cssnanoMinify],
294294
}).apply(compiler);
295295

296296
return compile(compiler).then((stats) => {
@@ -305,7 +305,7 @@ describe('"minify" option', () => {
305305
});
306306
});
307307

308-
it('should work with "CssMinimizerPlugin.csso" minifier', async () => {
308+
it('should work with "CssMinimizerPlugin.cssoMinify" minifier', async () => {
309309
const compiler = getCompiler({
310310
devtool: 'source-map',
311311
entry: {
@@ -326,7 +326,7 @@ describe('"minify" option', () => {
326326
});
327327

328328
new CssMinimizerPlugin({
329-
minify: CssMinimizerPlugin.csso,
329+
minify: CssMinimizerPlugin.cssoMinify,
330330
}).apply(compiler);
331331

332332
const stats = await compile(compiler);
@@ -338,7 +338,7 @@ describe('"minify" option', () => {
338338
expect(getWarnings(stats)).toMatchSnapshot('warning');
339339
});
340340

341-
it('should work with "CssMinimizerPlugin.cleanCss" minifier', async () => {
341+
it('should work with "CssMinimizerPlugin.cleanCssMinify" minifier', async () => {
342342
const compiler = getCompiler({
343343
devtool: 'source-map',
344344
entry: {
@@ -347,7 +347,7 @@ describe('"minify" option', () => {
347347
});
348348

349349
new CssMinimizerPlugin({
350-
minify: CssMinimizerPlugin.cleanCss,
350+
minify: CssMinimizerPlugin.cleanCssMinify,
351351
}).apply(compiler);
352352

353353
const stats = await compile(compiler);

test/worker.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('worker', () => {
2020
sourcesContent: ['.foo{color:red;}', '.bar{color:coral;}'],
2121
},
2222
minimizerOptions: { discardComments: false },
23-
minify: CssMinimizerPlugin.cssnano,
23+
minify: CssMinimizerPlugin.cssnanoMinify,
2424
};
2525
const { code, map } = await transform(serialize(options));
2626

@@ -41,7 +41,7 @@ describe('worker', () => {
4141
file: 'x',
4242
sourcesContent: ['.foo{color:red;}', '.bar{color:coral;}'],
4343
},
44-
minify: CssMinimizerPlugin.cssnano,
44+
minify: CssMinimizerPlugin.cssnanoMinify,
4545
};
4646
const { code, map } = await transform(serialize(options));
4747

@@ -69,7 +69,7 @@ describe('worker', () => {
6969
name: 'entry.css',
7070
input: false,
7171
minimizerOptions: { preset: 'default' },
72-
minify: CssMinimizerPlugin.cssnano,
72+
minify: CssMinimizerPlugin.cssnanoMinify,
7373
};
7474

7575
try {

0 commit comments

Comments
 (0)