From d057b49b7c058a310500adb761b5b99fc7f001ee Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 2 Sep 2021 18:52:48 +0300 Subject: [PATCH 1/3] docs: update --- README.md | 36 ++++------------ .../a.css | 3 ++ .../a.js | 5 +++ .../b.css | 3 ++ .../b.js | 5 +++ .../common.css | 3 ++ .../common.js | 1 + .../components/comp1.css | 3 ++ .../components/comp1.js | 3 ++ .../components/comp2.css | 3 ++ .../components/comp2.js | 3 ++ .../expected/a/index.css | 4 ++ .../expected/b/index.css | 4 ++ .../expected/common/index.css | 3 ++ .../expected/comp1/index.css | 4 ++ .../expected/comp2/index.css | 4 ++ .../webpack.config.js | 42 +++++++++++++++++++ .../a.css | 3 ++ .../a.js | 5 +++ .../b.css | 3 ++ .../b.js | 5 +++ .../common.css | 3 ++ .../common.js | 1 + .../components/comp1.css | 3 ++ .../components/comp1.js | 3 ++ .../components/comp2.css | 3 ++ .../components/comp2.js | 3 ++ .../expected/common.css | 3 ++ .../expected/comp1.css | 4 ++ .../expected/comp2.css | 4 ++ .../expected/styles_a.css | 4 ++ .../expected/styles_b.css | 4 ++ .../webpack.config.js | 35 ++++++++++++++++ test/cases/split-chunks-based-on-entry/a.css | 3 ++ test/cases/split-chunks-based-on-entry/a.js | 3 ++ test/cases/split-chunks-based-on-entry/b.css | 3 ++ test/cases/split-chunks-based-on-entry/b.js | 3 ++ .../components/comp1.css | 3 ++ .../components/comp1.js | 1 + .../components/comp2.css | 3 ++ .../components/comp2.js | 1 + .../expected/comp1.css | 4 ++ .../expected/comp2.css | 4 ++ .../expected/styles_a.css | 4 ++ .../expected/styles_b.css | 4 ++ .../webpack.config.js | 35 ++++++++++++++++ 46 files changed, 258 insertions(+), 28 deletions(-) create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/a/index.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/b/index.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp1/index.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp2/index.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/webpack.config.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/a.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/a.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/b.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/b.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/common.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/common.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.js create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp1.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp2.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_a.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_b.css create mode 100644 test/cases/split-chunks-based-on-entry-with-common-chunk/webpack.config.js create mode 100644 test/cases/split-chunks-based-on-entry/a.css create mode 100644 test/cases/split-chunks-based-on-entry/a.js create mode 100644 test/cases/split-chunks-based-on-entry/b.css create mode 100644 test/cases/split-chunks-based-on-entry/b.js create mode 100644 test/cases/split-chunks-based-on-entry/components/comp1.css create mode 100644 test/cases/split-chunks-based-on-entry/components/comp1.js create mode 100644 test/cases/split-chunks-based-on-entry/components/comp2.css create mode 100644 test/cases/split-chunks-based-on-entry/components/comp2.js create mode 100644 test/cases/split-chunks-based-on-entry/expected/comp1.css create mode 100644 test/cases/split-chunks-based-on-entry/expected/comp2.css create mode 100644 test/cases/split-chunks-based-on-entry/expected/styles_a.css create mode 100644 test/cases/split-chunks-based-on-entry/expected/styles_b.css create mode 100644 test/cases/split-chunks-based-on-entry/webpack.config.js diff --git a/README.md b/README.md index 27cbe724..1c0905b0 100644 --- a/README.md +++ b/README.md @@ -753,8 +753,6 @@ module.exports = { styles: { name: "styles", type: "css/mini-extract", - // For webpack@4 - // test: /\.css$/, chunks: "all", enforce: true, }, @@ -789,24 +787,6 @@ This also prevents the CSS duplication issue one had with the ExtractTextPlugin. const path = require("path"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); -function recursiveIssuer(m, c) { - const issuer = c.moduleGraph.getIssuer(m); - // For webpack@4 issuer = m.issuer - - if (issuer) { - return recursiveIssuer(issuer, c); - } - - const chunks = c.chunkGraph.getModuleChunks(m); - // For webpack@4 chunks = m._chunks - - for (const chunk of chunks) { - return chunk.name; - } - - return false; -} - module.exports = { entry: { foo: path.resolve(__dirname, "src/foo"), @@ -816,19 +796,19 @@ module.exports = { splitChunks: { cacheGroups: { fooStyles: { + type: "css/mini-extract", name: "styles_foo", - test: (m, c, entry = "foo") => - m.constructor.name === "CssModule" && - recursiveIssuer(m, c) === entry, - chunks: "all", + chunks: (chunk) => { + return chunk.name === "foo"; + }, enforce: true, }, barStyles: { + type: "css/mini-extract", name: "styles_bar", - test: (m, c, entry = "bar") => - m.constructor.name === "CssModule" && - recursiveIssuer(m, c) === entry, - chunks: "all", + chunks: (chunk) => { + return chunk.name === "bar"; + }, enforce: true, }, }, diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.css new file mode 100644 index 00000000..f3292008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.css @@ -0,0 +1,3 @@ +.class_a { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.js new file mode 100644 index 00000000..4ddb75ee --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/a.js @@ -0,0 +1,5 @@ +import "./a.css"; + +import(/* webpackChunkName: "common" */ "./common"); + +import(/* webpackChunkName: "comp1" */ "./components/comp1"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.css new file mode 100644 index 00000000..49970958 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.css @@ -0,0 +1,3 @@ +.class_b { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.js new file mode 100644 index 00000000..887b900f --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/b.js @@ -0,0 +1,5 @@ +import "./b.css"; + +import(/* webpackChunkName: "common" */ "./common"); + +import(/* webpackChunkName: "comp2" */ "./components/comp2"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.css new file mode 100644 index 00000000..ff488448 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.css @@ -0,0 +1,3 @@ +.common { + color: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.js new file mode 100644 index 00000000..3b529e8a --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/common.js @@ -0,0 +1 @@ +import "./common.css"; diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.css new file mode 100644 index 00000000..87de0008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.css @@ -0,0 +1,3 @@ +body { + background-color: yellow; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.js new file mode 100644 index 00000000..1310d883 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp1.js @@ -0,0 +1,3 @@ +import "./comp1.css"; + +import(/* webpackChunkName: "common" */ "../common"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.css new file mode 100644 index 00000000..9d9d772f --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.css @@ -0,0 +1,3 @@ +body { + background-color: green; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.js new file mode 100644 index 00000000..06e9cbbb --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/components/comp2.js @@ -0,0 +1,3 @@ +import "./comp2.css"; + +import(/* webpackChunkName: "common" */ "../common"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/a/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/a/index.css new file mode 100644 index 00000000..9629618e --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/a/index.css @@ -0,0 +1,4 @@ +.class_a { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/b/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/b/index.css new file mode 100644 index 00000000..999b8411 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/b/index.css @@ -0,0 +1,4 @@ +.class_b { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css new file mode 100644 index 00000000..1923a6ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css @@ -0,0 +1,3 @@ +.common { + color: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp1/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp1/index.css new file mode 100644 index 00000000..7f9729ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp1/index.css @@ -0,0 +1,4 @@ +body { + background-color: yellow; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp2/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp2/index.css new file mode 100644 index 00000000..cefdf104 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/comp2/index.css @@ -0,0 +1,4 @@ +body { + background-color: green; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/webpack.config.js b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/webpack.config.js new file mode 100644 index 00000000..7ff01b86 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/webpack.config.js @@ -0,0 +1,42 @@ +import Self from "../../../src"; + +module.exports = { + entry: { + a: "./a.js", + b: "./b.js", + }, + output: { + filename: "[name]/index.js", + }, + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, "css-loader"], + }, + ], + }, + optimization: { + splitChunks: { + cacheGroups: { + aStyles: { + type: "css/mini-extract", + name: "a", + chunks: (chunk) => chunk.name === "a", + enforce: true, + }, + bStyles: { + type: "css/mini-extract", + name: "b", + chunks: (chunk) => chunk.name === "b", + enforce: true, + }, + }, + }, + }, + plugins: [ + new Self({ + filename: "[name]/index.css", + }), + ], +}; diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/a.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/a.css new file mode 100644 index 00000000..f3292008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/a.css @@ -0,0 +1,3 @@ +.class_a { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/a.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/a.js new file mode 100644 index 00000000..4ddb75ee --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/a.js @@ -0,0 +1,5 @@ +import "./a.css"; + +import(/* webpackChunkName: "common" */ "./common"); + +import(/* webpackChunkName: "comp1" */ "./components/comp1"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/b.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/b.css new file mode 100644 index 00000000..49970958 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/b.css @@ -0,0 +1,3 @@ +.class_b { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/b.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/b.js new file mode 100644 index 00000000..887b900f --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/b.js @@ -0,0 +1,5 @@ +import "./b.css"; + +import(/* webpackChunkName: "common" */ "./common"); + +import(/* webpackChunkName: "comp2" */ "./components/comp2"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/common.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/common.css new file mode 100644 index 00000000..ff488448 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/common.css @@ -0,0 +1,3 @@ +.common { + color: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/common.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/common.js new file mode 100644 index 00000000..3b529e8a --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/common.js @@ -0,0 +1 @@ +import "./common.css"; diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.css new file mode 100644 index 00000000..87de0008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.css @@ -0,0 +1,3 @@ +body { + background-color: yellow; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.js new file mode 100644 index 00000000..1310d883 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp1.js @@ -0,0 +1,3 @@ +import "./comp1.css"; + +import(/* webpackChunkName: "common" */ "../common"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.css new file mode 100644 index 00000000..9d9d772f --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.css @@ -0,0 +1,3 @@ +body { + background-color: green; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.js new file mode 100644 index 00000000..06e9cbbb --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/components/comp2.js @@ -0,0 +1,3 @@ +import "./comp2.css"; + +import(/* webpackChunkName: "common" */ "../common"); diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css new file mode 100644 index 00000000..1923a6ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css @@ -0,0 +1,3 @@ +.common { + color: red; +} diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp1.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp1.css new file mode 100644 index 00000000..7f9729ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp1.css @@ -0,0 +1,4 @@ +body { + background-color: yellow; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp2.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp2.css new file mode 100644 index 00000000..cefdf104 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/comp2.css @@ -0,0 +1,4 @@ +body { + background-color: green; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_a.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_a.css new file mode 100644 index 00000000..9629618e --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_a.css @@ -0,0 +1,4 @@ +.class_a { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_b.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_b.css new file mode 100644 index 00000000..999b8411 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/styles_b.css @@ -0,0 +1,4 @@ +.class_b { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/webpack.config.js b/test/cases/split-chunks-based-on-entry-with-common-chunk/webpack.config.js new file mode 100644 index 00000000..507bea5d --- /dev/null +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/webpack.config.js @@ -0,0 +1,35 @@ +import Self from "../../../src"; + +module.exports = { + entry: { + a: "./a.js", + b: "./b.js", + }, + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, "css-loader"], + }, + ], + }, + optimization: { + splitChunks: { + cacheGroups: { + aStyles: { + type: "css/mini-extract", + name: "styles_a", + chunks: (chunk) => chunk.name === "a", + enforce: true, + }, + bStyles: { + type: "css/mini-extract", + name: "styles_b", + chunks: (chunk) => chunk.name === "b", + enforce: true, + }, + }, + }, + }, + plugins: [new Self()], +}; diff --git a/test/cases/split-chunks-based-on-entry/a.css b/test/cases/split-chunks-based-on-entry/a.css new file mode 100644 index 00000000..f3292008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/a.css @@ -0,0 +1,3 @@ +.class_a { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry/a.js b/test/cases/split-chunks-based-on-entry/a.js new file mode 100644 index 00000000..0c13bc98 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/a.js @@ -0,0 +1,3 @@ +import "./a.css"; + +import(/* webpackChunkName: "comp1" */ "./components/comp1"); diff --git a/test/cases/split-chunks-based-on-entry/b.css b/test/cases/split-chunks-based-on-entry/b.css new file mode 100644 index 00000000..49970958 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/b.css @@ -0,0 +1,3 @@ +.class_b { + background: red; +} diff --git a/test/cases/split-chunks-based-on-entry/b.js b/test/cases/split-chunks-based-on-entry/b.js new file mode 100644 index 00000000..c3f9e8ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/b.js @@ -0,0 +1,3 @@ +import "./b.css"; + +import(/* webpackChunkName: "comp2" */ "./components/comp2"); diff --git a/test/cases/split-chunks-based-on-entry/components/comp1.css b/test/cases/split-chunks-based-on-entry/components/comp1.css new file mode 100644 index 00000000..87de0008 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/components/comp1.css @@ -0,0 +1,3 @@ +body { + background-color: yellow; +} diff --git a/test/cases/split-chunks-based-on-entry/components/comp1.js b/test/cases/split-chunks-based-on-entry/components/comp1.js new file mode 100644 index 00000000..d9122966 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/components/comp1.js @@ -0,0 +1 @@ +import "./comp1.css"; diff --git a/test/cases/split-chunks-based-on-entry/components/comp2.css b/test/cases/split-chunks-based-on-entry/components/comp2.css new file mode 100644 index 00000000..9d9d772f --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/components/comp2.css @@ -0,0 +1,3 @@ +body { + background-color: green; +} diff --git a/test/cases/split-chunks-based-on-entry/components/comp2.js b/test/cases/split-chunks-based-on-entry/components/comp2.js new file mode 100644 index 00000000..232dd5bd --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/components/comp2.js @@ -0,0 +1 @@ +import "./comp2.css"; diff --git a/test/cases/split-chunks-based-on-entry/expected/comp1.css b/test/cases/split-chunks-based-on-entry/expected/comp1.css new file mode 100644 index 00000000..7f9729ec --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/expected/comp1.css @@ -0,0 +1,4 @@ +body { + background-color: yellow; +} + diff --git a/test/cases/split-chunks-based-on-entry/expected/comp2.css b/test/cases/split-chunks-based-on-entry/expected/comp2.css new file mode 100644 index 00000000..cefdf104 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/expected/comp2.css @@ -0,0 +1,4 @@ +body { + background-color: green; +} + diff --git a/test/cases/split-chunks-based-on-entry/expected/styles_a.css b/test/cases/split-chunks-based-on-entry/expected/styles_a.css new file mode 100644 index 00000000..9629618e --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/expected/styles_a.css @@ -0,0 +1,4 @@ +.class_a { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry/expected/styles_b.css b/test/cases/split-chunks-based-on-entry/expected/styles_b.css new file mode 100644 index 00000000..999b8411 --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/expected/styles_b.css @@ -0,0 +1,4 @@ +.class_b { + background: red; +} + diff --git a/test/cases/split-chunks-based-on-entry/webpack.config.js b/test/cases/split-chunks-based-on-entry/webpack.config.js new file mode 100644 index 00000000..507bea5d --- /dev/null +++ b/test/cases/split-chunks-based-on-entry/webpack.config.js @@ -0,0 +1,35 @@ +import Self from "../../../src"; + +module.exports = { + entry: { + a: "./a.js", + b: "./b.js", + }, + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, "css-loader"], + }, + ], + }, + optimization: { + splitChunks: { + cacheGroups: { + aStyles: { + type: "css/mini-extract", + name: "styles_a", + chunks: (chunk) => chunk.name === "a", + enforce: true, + }, + bStyles: { + type: "css/mini-extract", + name: "styles_b", + chunks: (chunk) => chunk.name === "b", + enforce: true, + }, + }, + }, + }, + plugins: [new Self()], +}; From 5229fbfccc27b2de8f346750adb9d46f2ba64a15 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 2 Sep 2021 19:00:18 +0300 Subject: [PATCH 2/3] test: fix --- .../expected/common/index.css | 3 ++- .../expected/common.css | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css index 1923a6ec..9a9d5c60 100644 --- a/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk-and-inside-dir/expected/common/index.css @@ -1,3 +1,4 @@ .common { - color: red; + color: red; } + diff --git a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css index 1923a6ec..9a9d5c60 100644 --- a/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css +++ b/test/cases/split-chunks-based-on-entry-with-common-chunk/expected/common.css @@ -1,3 +1,4 @@ .common { - color: red; + color: red; } + From 7c98bdb470aa728f0d54a0618ec786ddbfc3d4b8 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 2 Sep 2021 19:08:04 +0300 Subject: [PATCH 3/3] test: fix --- package-lock.json | 72 +++++++++---------- .../expected/webpack-5-importModule/main.js | 2 + .../expected/webpack-5/main.js | 2 + .../expected/main.mjs | 2 +- test/cases/es-named-export/expected/main.js | 2 +- test/cases/hmr/expected/main.js | 2 +- 6 files changed, 43 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index f090b6de..cf11e1ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3710,9 +3710,9 @@ } }, "node_modules/are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", "dev": true, "dependencies": { "delegates": "^1.0.0", @@ -5322,9 +5322,9 @@ } }, "node_modules/core-js-compat": { - "version": "3.16.4", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.16.4.tgz", - "integrity": "sha512-IzCSomxRdahCYb6G3HiN6pl3JCiM0NMunRcNa1pIeC7g17Vd6Ue3AT9anQiENPIm/svThUVer1pIbLMDERIsFw==", + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.17.1.tgz", + "integrity": "sha512-Oqp6qybMdCFcWSroh/6Q8j7YNOjRD0ThY02cAd6rugr//FCkMYonizLV8AryLU5wNJOweauIBxQYCZoV3emfcw==", "dev": true, "dependencies": { "browserslist": "^4.16.8", @@ -6124,9 +6124,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.3.826", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.826.tgz", - "integrity": "sha512-bpLc4QU4B8PYmdO4MSu2ZBTMD8lAaEXRS43C09lB31BvYwuk9UxgBRXbY5OJBw7VuMGcg2MZG5FyTaP9u4PQnw==", + "version": "1.3.827", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.827.tgz", + "integrity": "sha512-ye+4uQOY/jbjRutMcE/EmOcNwUeo1qo9aKL2tPyb09cU3lmxNeyDF4RWiemmkknW+p29h7dyDqy02higTxc9/A==", "dev": true }, "node_modules/emittery": { @@ -7495,9 +7495,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.2.tgz", - "integrity": "sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==", + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz", + "integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==", "dev": true, "funding": [ { @@ -16328,9 +16328,9 @@ } }, "node_modules/terser-webpack-plugin": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.0.tgz", - "integrity": "sha512-FpR4Qe0Yt4knSQ5u2bA1wkM0R8VlVsvhyfSHvomXRivS4vPLk0dJV2IhRBIHRABh7AFutdMeElIA5y1dETwMBg==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.1.tgz", + "integrity": "sha512-mUAWsS2RDNL3rEr0ZTr7hm/R1DDxNwrED7Kf59F2rgFTfy+LrnciwA51MNWhGGQcqHnqvbPHgkW9LYr5HGBhfw==", "dev": true, "dependencies": { "jest-worker": "^27.0.6", @@ -17057,9 +17057,9 @@ } }, "node_modules/webpack": { - "version": "5.51.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.51.1.tgz", - "integrity": "sha512-xsn3lwqEKoFvqn4JQggPSRxE4dhsRcysWTqYABAZlmavcoTmwlOb9b1N36Inbt/eIispSkuHa80/FJkDTPos1A==", + "version": "5.51.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.51.2.tgz", + "integrity": "sha512-odydxP4WA3XYYzwSQUivPxywdzMlY42bbfxMwCaEtHb+i/N9uzKSHcLgWkXo/Gsa+4Zlzf3Jg0hEHn1FnZpk2Q==", "dev": true, "dependencies": { "@types/eslint-scope": "^3.7.0", @@ -20352,9 +20352,9 @@ } }, "are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", "dev": true, "requires": { "delegates": "^1.0.0", @@ -21629,9 +21629,9 @@ "optional": true }, "core-js-compat": { - "version": "3.16.4", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.16.4.tgz", - "integrity": "sha512-IzCSomxRdahCYb6G3HiN6pl3JCiM0NMunRcNa1pIeC7g17Vd6Ue3AT9anQiENPIm/svThUVer1pIbLMDERIsFw==", + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.17.1.tgz", + "integrity": "sha512-Oqp6qybMdCFcWSroh/6Q8j7YNOjRD0ThY02cAd6rugr//FCkMYonizLV8AryLU5wNJOweauIBxQYCZoV3emfcw==", "dev": true, "requires": { "browserslist": "^4.16.8", @@ -22208,9 +22208,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.826", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.826.tgz", - "integrity": "sha512-bpLc4QU4B8PYmdO4MSu2ZBTMD8lAaEXRS43C09lB31BvYwuk9UxgBRXbY5OJBw7VuMGcg2MZG5FyTaP9u4PQnw==", + "version": "1.3.827", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.827.tgz", + "integrity": "sha512-ye+4uQOY/jbjRutMcE/EmOcNwUeo1qo9aKL2tPyb09cU3lmxNeyDF4RWiemmkknW+p29h7dyDqy02higTxc9/A==", "dev": true }, "emittery": { @@ -23281,9 +23281,9 @@ "dev": true }, "follow-redirects": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.2.tgz", - "integrity": "sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==", + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz", + "integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==", "dev": true }, "for-in": { @@ -30025,9 +30025,9 @@ } }, "terser-webpack-plugin": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.0.tgz", - "integrity": "sha512-FpR4Qe0Yt4knSQ5u2bA1wkM0R8VlVsvhyfSHvomXRivS4vPLk0dJV2IhRBIHRABh7AFutdMeElIA5y1dETwMBg==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.1.tgz", + "integrity": "sha512-mUAWsS2RDNL3rEr0ZTr7hm/R1DDxNwrED7Kf59F2rgFTfy+LrnciwA51MNWhGGQcqHnqvbPHgkW9LYr5HGBhfw==", "dev": true, "requires": { "jest-worker": "^27.0.6", @@ -30589,9 +30589,9 @@ "dev": true }, "webpack": { - "version": "5.51.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.51.1.tgz", - "integrity": "sha512-xsn3lwqEKoFvqn4JQggPSRxE4dhsRcysWTqYABAZlmavcoTmwlOb9b1N36Inbt/eIispSkuHa80/FJkDTPos1A==", + "version": "5.51.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.51.2.tgz", + "integrity": "sha512-odydxP4WA3XYYzwSQUivPxywdzMlY42bbfxMwCaEtHb+i/N9uzKSHcLgWkXo/Gsa+4Zlzf3Jg0hEHn1FnZpk2Q==", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js index dfa3c64b..12c6b04e 100644 --- a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js +++ b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js @@ -66,6 +66,8 @@ __webpack_require__.r(__webpack_exports__); /******/ (() => { /******/ // This function allow to reference all chunks /******/ __webpack_require__.miniCssF = (chunkId) => { +/******/ // return url for filenames not based on template +/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css"; /******/ // return url for filenames based on template /******/ return "" + chunkId + "." + __webpack_require__.h() + ".css"; /******/ }; diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js b/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js index 039647d8..177b5318 100644 --- a/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js +++ b/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js @@ -66,6 +66,8 @@ __webpack_require__.r(__webpack_exports__); /******/ (() => { /******/ // This function allow to reference all chunks /******/ __webpack_require__.miniCssF = (chunkId) => { +/******/ // return url for filenames not based on template +/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css"; /******/ // return url for filenames based on template /******/ return "" + chunkId + "." + __webpack_require__.h() + ".css"; /******/ }; diff --git a/test/cases/es-named-export-output-module/expected/main.mjs b/test/cases/es-named-export-output-module/expected/main.mjs index 048d5ed7..8e964ca1 100644 --- a/test/cases/es-named-export-output-module/expected/main.mjs +++ b/test/cases/es-named-export-output-module/expected/main.mjs @@ -79,7 +79,7 @@ __webpack_require__.r(__webpack_exports__); // eslint-disable-next-line no-console -console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__.default, aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); +console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); })(); diff --git a/test/cases/es-named-export/expected/main.js b/test/cases/es-named-export/expected/main.js index 8cf22c2c..76d82ff6 100644 --- a/test/cases/es-named-export/expected/main.js +++ b/test/cases/es-named-export/expected/main.js @@ -81,7 +81,7 @@ __webpack_require__.r(__webpack_exports__); // eslint-disable-next-line no-console -console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__.default, aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); +console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); })(); diff --git a/test/cases/hmr/expected/main.js b/test/cases/hmr/expected/main.js index 2c6dd521..31721465 100644 --- a/test/cases/hmr/expected/main.js +++ b/test/cases/hmr/expected/main.js @@ -365,7 +365,7 @@ module.exports = function (urlString) { /******/ // This function allow to reference all chunks /******/ __webpack_require__.miniCssF = (chunkId) => { /******/ // return url for filenames based on template -/******/ return undefined; +/******/ return "" + "main" + ".css"; /******/ }; /******/ })(); /******/