Skip to content

Commit

Permalink
docs: update (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 2, 2021
1 parent 0ccdb64 commit 355f729
Show file tree
Hide file tree
Showing 52 changed files with 303 additions and 67 deletions.
36 changes: 8 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ module.exports = {
styles: {
name: "styles",
type: "css/mini-extract",
// For webpack@4
// test: /\.css$/,
chunks: "all",
enforce: true,
},
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
},
},
Expand Down
72 changes: 36 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
/******/ };
Expand Down
2 changes: 2 additions & 0 deletions test/cases/chunkFilename-fullhash/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/******/ };
Expand Down
2 changes: 1 addition & 1 deletion test/cases/es-named-export-output-module/expected/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

})();

2 changes: 1 addition & 1 deletion test/cases/es-named-export/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

})();

Expand Down
2 changes: 1 addition & 1 deletion test/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/******/ };
/******/ })();
/******/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.class_a {
background: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./a.css";

import(/* webpackChunkName: "common" */ "./common");

import(/* webpackChunkName: "comp1" */ "./components/comp1");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.class_b {
background: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./b.css";

import(/* webpackChunkName: "common" */ "./common");

import(/* webpackChunkName: "comp2" */ "./components/comp2");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.common {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./common.css";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: yellow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./comp1.css";

import(/* webpackChunkName: "common" */ "../common");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: green;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./comp2.css";

import(/* webpackChunkName: "common" */ "../common");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.class_a {
background: red;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.class_b {
background: red;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.common {
color: red;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: yellow;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: green;
}

Original file line number Diff line number Diff line change
@@ -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",
}),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.class_a {
background: red;
}
5 changes: 5 additions & 0 deletions test/cases/split-chunks-based-on-entry-with-common-chunk/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./a.css";

import(/* webpackChunkName: "common" */ "./common");

import(/* webpackChunkName: "comp1" */ "./components/comp1");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.class_b {
background: red;
}
5 changes: 5 additions & 0 deletions test/cases/split-chunks-based-on-entry-with-common-chunk/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./b.css";

import(/* webpackChunkName: "common" */ "./common");

import(/* webpackChunkName: "comp2" */ "./components/comp2");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.common {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./common.css";
Loading

0 comments on commit 355f729

Please sign in to comment.