From f6953df427dda5bdf490fe0b63d37eb91f43e2b3 Mon Sep 17 00:00:00 2001 From: Daniil Veremchuk Date: Wed, 2 May 2018 09:13:48 -0400 Subject: [PATCH 1/3] Added CSS extract based on entry --- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/README.md b/README.md index 2d2ae6c3..9b7b77c4 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,87 @@ module.exports = { } ``` +<<<<<<< HEAD +======= +#### Extracting CSS based on entry + +You may also extract the CSS based on the webpack entry name. This is especially useful if you import routes dynamically +but want to keep your CSS bundled according to entry. This also prevents the CSS duplication issue one had with the +ExtractTextPlugin. + +```javascript +const path = require('path'); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); + +function recursiveIssuer(m) { + if (m.issuer) { + return recursiveIssuer(m.issuer); + } else if (m.name) { + return m.name; + } else { + return false; + } +} + +module.exports = { + entry: { + foo: path.resolve(__dirname, 'src/foo'), + bar: path.resolve(__dirname, 'src/bar') + }, + optimization: { + splitChunks: { + cacheGroups: { + fooStyles: { + name: 'foo', + test: (m,c,entry = 'foo') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === e, + chunks: 'all', + enforce: true + }, + barStyles: { + name: 'bar', + test: (m,c,entry = 'bar') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === e, + chunks: 'all', + enforce: true + } + } + } + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "[name].css", + }) + ], + module: { + rules: [ + { + test: /\.css$/, + use: [ + MiniCssExtractPlugin.loader, + "css-loader" + ] + } + ] + } +} +``` + +

Maintainers

+ + + + + + + +
+ + +
+ Tobias Koppers +
+
+ +>>>>>>> Added CSS extract based on entry #### Long Term Caching For long term caching use `filename: "[contenthash].css"`. Optionally add `[name]`. From 9cd5822e017ef3d3123c93a8e656a0e781e116d0 Mon Sep 17 00:00:00 2001 From: Daniil Veremchuk Date: Wed, 2 May 2018 09:20:18 -0400 Subject: [PATCH 2/3] woops,typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b7b77c4..a34918a1 100644 --- a/README.md +++ b/README.md @@ -231,13 +231,13 @@ module.exports = { cacheGroups: { fooStyles: { name: 'foo', - test: (m,c,entry = 'foo') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === e, + test: (m,c,entry = 'foo') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, chunks: 'all', enforce: true }, barStyles: { name: 'bar', - test: (m,c,entry = 'bar') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === e, + test: (m,c,entry = 'bar') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry, chunks: 'all', enforce: true } From 6628067acf3b7fe1f0a05661dbdcb1cc4528ec6d Mon Sep 17 00:00:00 2001 From: Daniil Veremchuk Date: Mon, 7 May 2018 10:09:36 -0400 Subject: [PATCH 3/3] fixed rebase artifact --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index a34918a1..1803f42c 100644 --- a/README.md +++ b/README.md @@ -199,8 +199,6 @@ module.exports = { } ``` -<<<<<<< HEAD -======= #### Extracting CSS based on entry You may also extract the CSS based on the webpack entry name. This is especially useful if you import routes dynamically @@ -279,7 +277,6 @@ module.exports = { ->>>>>>> Added CSS extract based on entry #### Long Term Caching For long term caching use `filename: "[contenthash].css"`. Optionally add `[name]`.