Skip to content

Commit 355f729

Browse files
docs: update (#820)
1 parent 0ccdb64 commit 355f729

File tree

52 files changed

+303
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+303
-67
lines changed

README.md

+8-28
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,6 @@ module.exports = {
753753
styles: {
754754
name: "styles",
755755
type: "css/mini-extract",
756-
// For webpack@4
757-
// test: /\.css$/,
758756
chunks: "all",
759757
enforce: true,
760758
},
@@ -789,24 +787,6 @@ This also prevents the CSS duplication issue one had with the ExtractTextPlugin.
789787
const path = require("path");
790788
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
791789

792-
function recursiveIssuer(m, c) {
793-
const issuer = c.moduleGraph.getIssuer(m);
794-
// For webpack@4 issuer = m.issuer
795-
796-
if (issuer) {
797-
return recursiveIssuer(issuer, c);
798-
}
799-
800-
const chunks = c.chunkGraph.getModuleChunks(m);
801-
// For webpack@4 chunks = m._chunks
802-
803-
for (const chunk of chunks) {
804-
return chunk.name;
805-
}
806-
807-
return false;
808-
}
809-
810790
module.exports = {
811791
entry: {
812792
foo: path.resolve(__dirname, "src/foo"),
@@ -816,19 +796,19 @@ module.exports = {
816796
splitChunks: {
817797
cacheGroups: {
818798
fooStyles: {
799+
type: "css/mini-extract",
819800
name: "styles_foo",
820-
test: (m, c, entry = "foo") =>
821-
m.constructor.name === "CssModule" &&
822-
recursiveIssuer(m, c) === entry,
823-
chunks: "all",
801+
chunks: (chunk) => {
802+
return chunk.name === "foo";
803+
},
824804
enforce: true,
825805
},
826806
barStyles: {
807+
type: "css/mini-extract",
827808
name: "styles_bar",
828-
test: (m, c, entry = "bar") =>
829-
m.constructor.name === "CssModule" &&
830-
recursiveIssuer(m, c) === entry,
831-
chunks: "all",
809+
chunks: (chunk) => {
810+
return chunk.name === "bar";
811+
},
832812
enforce: true,
833813
},
834814
},

package-lock.json

+36-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ __webpack_require__.r(__webpack_exports__);
6666
/******/ (() => {
6767
/******/ // This function allow to reference all chunks
6868
/******/ __webpack_require__.miniCssF = (chunkId) => {
69+
/******/ // return url for filenames not based on template
70+
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
6971
/******/ // return url for filenames based on template
7072
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
7173
/******/ };

test/cases/chunkFilename-fullhash/expected/webpack-5/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ __webpack_require__.r(__webpack_exports__);
6666
/******/ (() => {
6767
/******/ // This function allow to reference all chunks
6868
/******/ __webpack_require__.miniCssF = (chunkId) => {
69+
/******/ // return url for filenames not based on template
70+
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
6971
/******/ // return url for filenames based on template
7072
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
7173
/******/ };

test/cases/es-named-export-output-module/expected/main.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __webpack_require__.r(__webpack_exports__);
7979

8080

8181
// eslint-disable-next-line no-console
82-
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 });
82+
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 });
8383

8484
})();
8585

test/cases/es-named-export/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ __webpack_require__.r(__webpack_exports__);
8181

8282

8383
// eslint-disable-next-line no-console
84-
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 });
84+
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 });
8585

8686
})();
8787

test/cases/hmr/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ module.exports = function (urlString) {
365365
/******/ // This function allow to reference all chunks
366366
/******/ __webpack_require__.miniCssF = (chunkId) => {
367367
/******/ // return url for filenames based on template
368-
/******/ return undefined;
368+
/******/ return "" + "main" + ".css";
369369
/******/ };
370370
/******/ })();
371371
/******/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_a {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./a.css";
2+
3+
import(/* webpackChunkName: "common" */ "./common");
4+
5+
import(/* webpackChunkName: "comp1" */ "./components/comp1");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_b {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./b.css";
2+
3+
import(/* webpackChunkName: "common" */ "./common");
4+
5+
import(/* webpackChunkName: "comp2" */ "./components/comp2");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.common {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./common.css";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: yellow;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./comp1.css";
2+
3+
import(/* webpackChunkName: "common" */ "../common");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: green;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./comp2.css";
2+
3+
import(/* webpackChunkName: "common" */ "../common");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.class_a {
2+
background: red;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.class_b {
2+
background: red;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.common {
2+
color: red;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background-color: yellow;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background-color: green;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
entry: {
5+
a: "./a.js",
6+
b: "./b.js",
7+
},
8+
output: {
9+
filename: "[name]/index.js",
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.css$/,
15+
use: [Self.loader, "css-loader"],
16+
},
17+
],
18+
},
19+
optimization: {
20+
splitChunks: {
21+
cacheGroups: {
22+
aStyles: {
23+
type: "css/mini-extract",
24+
name: "a",
25+
chunks: (chunk) => chunk.name === "a",
26+
enforce: true,
27+
},
28+
bStyles: {
29+
type: "css/mini-extract",
30+
name: "b",
31+
chunks: (chunk) => chunk.name === "b",
32+
enforce: true,
33+
},
34+
},
35+
},
36+
},
37+
plugins: [
38+
new Self({
39+
filename: "[name]/index.css",
40+
}),
41+
],
42+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_a {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./a.css";
2+
3+
import(/* webpackChunkName: "common" */ "./common");
4+
5+
import(/* webpackChunkName: "comp1" */ "./components/comp1");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class_b {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./b.css";
2+
3+
import(/* webpackChunkName: "common" */ "./common");
4+
5+
import(/* webpackChunkName: "comp2" */ "./components/comp2");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.common {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./common.css";

0 commit comments

Comments
 (0)