Skip to content

Commit 4d2a8fd

Browse files
feat: update cssnano to 5.0.0 version
BREAKING CHANGE: update `cssnano` to `5.0.0` version
1 parent 39404cd commit 4d2a8fd

7 files changed

+1808
-2263
lines changed

package-lock.json

+1,767-2,212
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -49,44 +49,44 @@
4949
}
5050
},
5151
"dependencies": {
52-
"cssnano": "^4.1.11",
52+
"cssnano": "^5.0.0",
5353
"jest-worker": "^26.3.0",
5454
"p-limit": "^3.0.2",
55+
"postcss": "^8.2.9",
5556
"schema-utils": "^3.0.0",
5657
"serialize-javascript": "^5.0.1",
5758
"source-map": "^0.6.1"
5859
},
5960
"devDependencies": {
60-
"@babel/cli": "^7.11.6",
61-
"@babel/core": "^7.11.6",
62-
"@babel/preset-env": "^7.11.5",
63-
"@commitlint/cli": "^12.0.1",
64-
"@commitlint/config-conventional": "^12.0.1",
61+
"@babel/cli": "^7.13.14",
62+
"@babel/core": "^7.13.15",
63+
"@babel/preset-env": "^7.13.15",
64+
"@commitlint/cli": "^12.1.1",
65+
"@commitlint/config-conventional": "^12.1.1",
6566
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
6667
"babel-jest": "^26.3.0",
67-
"clean-css": "^5.1.1",
68-
"copy-webpack-plugin": "^8.0.0",
68+
"clean-css": "^5.1.2",
69+
"copy-webpack-plugin": "^8.1.1",
6970
"cross-env": "^7.0.2",
70-
"css-loader": "^5.0.1",
71+
"css-loader": "^5.2.1",
7172
"csso": "^4.0.3",
7273
"del": "^6.0.0",
7374
"del-cli": "^3.0.1",
74-
"eslint": "^7.9.0",
75+
"eslint": "^7.24.0",
7576
"eslint-config-prettier": "^8.1.0",
7677
"eslint-plugin-import": "^2.22.0",
7778
"husky": "^5.1.3",
7879
"jest": "^26.4.2",
7980
"lint-staged": "^10.4.0",
80-
"memfs": "^3.2.0",
81-
"mini-css-extract-plugin": "^1.3.3",
81+
"memfs": "^3.2.2",
82+
"mini-css-extract-plugin": "^1.4.1",
8283
"npm-run-all": "^4.1.5",
83-
"postcss": "^7.0.32",
8484
"prettier": "^2.1.2",
8585
"sass": "^1.32.8",
8686
"sass-loader": "^11.0.1",
87-
"standard-version": "^9.0.0",
87+
"standard-version": "^9.2.0",
8888
"sugarss": "^3.0.3",
89-
"webpack": "^5.25.0"
89+
"webpack": "^5.31.2"
9090
},
9191
"keywords": [
9292
"cssnano",

src/index.js

-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as os from 'os';
33
import { SourceMapConsumer } from 'source-map';
44
import { validate } from 'schema-utils';
55
import serialize from 'serialize-javascript';
6-
import * as cssNanoPackageJson from 'cssnano/package.json';
76
import pLimit from 'p-limit';
87
import Worker from 'jest-worker';
98

@@ -408,20 +407,6 @@ class CssMinimizerPlugin {
408407
);
409408

410409
compiler.hooks.compilation.tap(pluginName, (compilation) => {
411-
const hooks = compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
412-
compilation
413-
);
414-
415-
const data = serialize({
416-
terser: cssNanoPackageJson.version,
417-
terserOptions: this.options.terserOptions,
418-
});
419-
420-
hooks.chunkHash.tap(pluginName, (chunk, hash) => {
421-
hash.update('CssMinimizerPlugin');
422-
hash.update(data);
423-
});
424-
425410
compilation.hooks.processAssets.tapPromise(
426411
{
427412
name: pluginName,

src/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ async function cssnanoMinify(
4848
};
4949
}
5050

51+
// eslint-disable-next-line global-require
52+
const postcss = require('postcss');
5153
// eslint-disable-next-line global-require
5254
const cssnano = require('cssnano');
53-
const result = await cssnano.process(input, postcssOptions, minimizerOptions);
55+
const result = await postcss([cssnano(minimizerOptions)]).process(
56+
input,
57+
postcssOptions
58+
);
5459

5560
return {
5661
code: result.css,

test/__snapshots__/CssMinimizerPlugin.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `
6161

6262
exports[`CssMinimizerPlugin should run plugin against assets added later by plugins: assets 1`] = `
6363
Object {
64-
"newFile.css": ".a{display:block;color:coral}",
64+
"newFile.css": ".a{color:coral;display:block}",
6565
}
6666
`;
6767

@@ -104,7 +104,7 @@ exports[`CssMinimizerPlugin should work and do not use memory cache when the "ca
104104

105105
exports[`CssMinimizerPlugin should work and generate real content hash: assets 1`] = `
106106
Object {
107-
"entry.19e4764f9c1d9fe130e2.165f000b9611e0038819.7a1dbea4fbce70afbf18.css": "body{color:red}a{color:#00f}",
107+
"entry.19e4764f9c1d9fe130e2.3a8d5aac970c41cb40b6.4e0651debb6658533ab9.css": "body{color:red}a{color:#00f}",
108108
}
109109
`;
110110

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and
7878

7979
exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": assets 1`] = `
8080
Object {
81-
"foo.css": "body{font-weight:700;color:red}body a{text-align:center}
81+
"foo.css": "body{color:red;font-weight:700}body a{text-align:center}
8282
/*# sourceMappingURL=foo.css.map*/",
83-
"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\\":\\"\\"}",
83+
"foo.css.map": "{\\"version\\":3,\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KCGE,UDFA,eCCF,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

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Array [
2828

2929
exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): assets 1`] = `
3030
Object {
31-
"dist/entry.css": "body{font-weight:700;color:red}body a{text-align:center}
31+
"dist/entry.css": "body{color:red;font-weight:700}body a{text-align:center}
3232
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry.css.map*/",
33-
"dist/entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
33+
"dist/entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
3434
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry2.css.map*/",
3535
"sourcemaps/entry.css.map": {
3636
"version": 3,
@@ -39,7 +39,7 @@ Object {
3939
"webpack:///./sourcemap/foo.scss"
4040
],
4141
"names": [],
42-
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
42+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
4343
"file": "dist/entry.css",
4444
"sourcesContent": [
4545
"body {\\n font-weight: bold;\\n}",
@@ -54,7 +54,7 @@ Object {
5454
"webpack:///./sourcemap/foo.css"
5555
],
5656
"names": [],
57-
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
57+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
5858
"file": "dist/entry2.css",
5959
"sourcesContent": [
6060
"body {\\n font-weight: bold;\\n}",
@@ -71,7 +71,7 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP
7171

7272
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
7373
Object {
74-
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
74+
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
7575
/*# sourceMappingURL=entry.css.map*/",
7676
"entry.css.map": {
7777
"version": 3,
@@ -80,15 +80,15 @@ Object {
8080
"webpack:///./sourcemap/foo.scss"
8181
],
8282
"names": [],
83-
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
83+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
8484
"file": "entry.css",
8585
"sourcesContent": [
8686
"body {\\n font-weight: bold;\\n}",
8787
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
8888
],
8989
"sourceRoot": ""
9090
},
91-
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
91+
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
9292
/*# sourceMappingURL=entry2.css.map*/",
9393
"entry2.css.map": {
9494
"version": 3,
@@ -97,7 +97,7 @@ Object {
9797
"webpack:///./sourcemap/foo.css"
9898
],
9999
"names": [],
100-
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
100+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
101101
"file": "entry2.css",
102102
"sourcesContent": [
103103
"body {\\n font-weight: bold;\\n}",
@@ -114,7 +114,7 @@ exports[`when applied with "sourceMap" option should work with the "devtool" opt
114114

115115
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
116116
Object {
117-
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
117+
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
118118
/*# sourceMappingURL=entry.css.map*/",
119119
"entry.css.map": {
120120
"version": 3,
@@ -123,15 +123,15 @@ Object {
123123
"webpack:///./sourcemap/foo.scss"
124124
],
125125
"names": [],
126-
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
126+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
127127
"file": "entry.css",
128128
"sourcesContent": [
129129
"body {\\n font-weight: bold;\\n}",
130130
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
131131
],
132132
"sourceRoot": ""
133133
},
134-
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
134+
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
135135
/*# sourceMappingURL=entry2.css.map*/",
136136
"entry2.css.map": {
137137
"version": 3,
@@ -140,7 +140,7 @@ Object {
140140
"webpack:///./sourcemap/foo.css"
141141
],
142142
"names": [],
143-
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
143+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
144144
"file": "entry2.css",
145145
"sourcesContent": [
146146
"body {\\n font-weight: bold;\\n}",
@@ -157,7 +157,7 @@ exports[`when applied with "sourceMap" option should work with the "devtool" opt
157157

158158
exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
159159
Object {
160-
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
160+
"entry.css": "body{color:red;font-weight:700}body a{text-align:center}
161161
/*# sourceMappingURL=entry.css.map*/",
162162
"entry.css.map": {
163163
"version": 3,
@@ -166,15 +166,15 @@ Object {
166166
"webpack:///./sourcemap/foo.scss"
167167
],
168168
"names": [],
169-
"mappings": "AAAA,KACE,gBCEA,SADF,CAEE,OACE,iBAIJ",
169+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAEE,OACE,iBAIJ",
170170
"file": "entry.css",
171171
"sourcesContent": [
172172
"body {\\n font-weight: bold;\\n}",
173173
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
174174
],
175175
"sourceRoot": ""
176176
},
177-
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
177+
"entry2.css": "body{color:red;font-weight:700}body a{text-align:center}
178178
/*# sourceMappingURL=entry2.css.map*/",
179179
"entry2.css.map": {
180180
"version": 3,
@@ -183,7 +183,7 @@ Object {
183183
"webpack:///./sourcemap/foo.css"
184184
],
185185
"names": [],
186-
"mappings": "AAAA,KACE,gBCEA,SADF,CAIA,OACE,iBAGF",
186+
"mappings": "AAAA,KCGE,UDFA,eCCF,CAIA,OACE,iBAGF",
187187
"file": "entry2.css",
188188
"sourcesContent": [
189189
"body {\\n font-weight: bold;\\n}",

0 commit comments

Comments
 (0)