Skip to content

Commit 44bebd7

Browse files
committed
feature #966 Upgrade to css-minimize-webpack-plugin 2.0 (stof, weaverryan)
This PR was merged into the main branch. Discussion ---------- Upgrade to css-minimize-webpack-plugin 2.0 This upgrades cssnano to version 5, which fixes a bunch of bugs and uses postcss 8 (avoiding to install multiple versions of postcss). The BC breaks in the plugin are dropping support for webpack 4 (not impacted Encore as we already dropped it), removing some options which were only for webpack 4 and the fact that cssnano 5 requires node 10.13+ (not impacting Encore as we already require 10.19+) Closes #965 Commits ------- 6afb5a3 cleaning up dfe0262 bumping out-of-date lock file ed39adf making a test more resistant to chunk id changes 3d31646 Bump min versions of dependencies 325bf18 Fix tests 4a533ee Upgrade to css-minimize-webpack-plugin 2.0 58bc358 Update locked dependencies
2 parents d074101 + 6afb5a3 commit 44bebd7

File tree

5 files changed

+1349
-1598
lines changed

5 files changed

+1349
-1598
lines changed

lib/plugins/optimize-css-assets.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const applyOptionsCallback = require('../utils/apply-options-callback');
1818
* @return {object}
1919
*/
2020
module.exports = function(webpackConfig) {
21-
const minimizerPluginOptions = {
22-
sourceMap: webpackConfig.useSourceMaps
23-
};
21+
const minimizerPluginOptions = {};
2422

2523
return new CssMinimizerPlugin(
2624
applyOptionsCallback(webpackConfig.cssMinimizerPluginOptionsCallback, minimizerPluginOptions)

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
3030
"@babel/preset-env": "^7.10.0",
3131
"assets-webpack-plugin": "^7.0.0",
32-
"babel-loader": "^8.0.0",
32+
"babel-loader": "^8.2.2",
3333
"chalk": "^4.0.0",
3434
"clean-webpack-plugin": "^3.0.0",
35-
"css-loader": "^5.0.1",
36-
"css-minimizer-webpack-plugin": "^1.1.5",
35+
"css-loader": "^5.2.4",
36+
"css-minimizer-webpack-plugin": "^2.0.0",
3737
"fast-levenshtein": "^3.0.0",
38-
"friendly-errors-webpack-plugin": "^2.0.0-beta.1",
38+
"friendly-errors-webpack-plugin": "^2.0.0-beta.2",
3939
"loader-utils": "^2.0.0",
40-
"mini-css-extract-plugin": "^1.0.0",
40+
"mini-css-extract-plugin": "^1.5.0",
4141
"pkg-up": "^3.1.0",
4242
"pretty-error": "^3.0.3",
4343
"resolve-url-loader": "^3.1.2",
4444
"semver": "^7.3.2",
4545
"style-loader": "^2.0.0",
4646
"terser-webpack-plugin": "^5.1.1",
4747
"tmp": "^0.2.1",
48-
"webpack": "^5.12",
48+
"webpack": "^5.35",
4949
"webpack-cli": "^4",
5050
"webpack-dev-server": "^4.0.0-beta.0",
5151
"yargs-parser": "^20.2.4"

test/bin/encore.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ module.exports = Encore.getWebpackConfig();
101101
expect(parsedOutput).to.be.an('object');
102102
expect(parsedOutput.modules).to.be.an('array');
103103

104-
// We expect 3 modules there:
104+
// We expect 4 modules there:
105+
// - webpack/runtime/chunk loaded
105106
// - webpack/runtime/jsonp chunk loading
106107
// - webpack/runtime/hasOwnProperty shorthand
107108
// - ./js/no_require.js
108-
expect(parsedOutput.modules.length).to.equal(3);
109+
expect(parsedOutput.modules.length).to.equal(4);
109110

110111

111112
done();

test/functional.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,23 +2661,23 @@ module.exports = {
26612661
splitChunks.minSize = 0;
26622662
});
26632663

2664-
testSetup.runWebpack(config, (webpackAssert) => {
2664+
testSetup.runWebpack(config, () => {
26652665
// in production, we hash the chunk names to avoid exposing any extra details
2666-
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
2667-
entrypoints: {
2668-
main: {
2669-
js: ['/build/runtime.js', '/build/961.js', '/build/38.js', '/build/main.js'],
2670-
css: ['/build/38.css']
2671-
},
2672-
other: {
2673-
js: ['/build/runtime.js', '/build/961.js', '/build/38.js', '/build/other.js'],
2674-
css: ['/build/38.css']
2675-
}
2676-
}
2677-
});
2666+
const entrypointsData = JSON.parse(readOutputFileContents('entrypoints.json', config));
2667+
const mainJsFiles = entrypointsData.entrypoints.main.js;
2668+
expect(mainJsFiles).to.have.length(4);
2669+
expect(mainJsFiles[0]).equals('/build/runtime.js');
2670+
// keys 1 and 2 are "split files" with an integer name that sometimes changes
2671+
expect(mainJsFiles[3]).equals('/build/main.js');
2672+
2673+
expect(entrypointsData.entrypoints.main.css[0]).matches(/\/build\/(\d)+\.css/);
26782674

26792675
// make split chunks are correct in manifest
2680-
webpackAssert.assertManifestKeyExists('build/961.js');
2676+
const manifestData = JSON.parse(readOutputFileContents('manifest.json', config));
2677+
mainJsFiles.forEach((file) => {
2678+
// file.substring(1) => /build/main.js -> build/main.js
2679+
expect(Object.keys(manifestData)).includes(file.substring(1));
2680+
});
26812681

26822682
done();
26832683
});

0 commit comments

Comments
 (0)