Unverified Commit 21fea2ce authored by Alex Castle's avatar Alex Castle Committed by GitHub

Modify splitChunksPlugin to give shared CSS chunks different names (#10408)

* Modify splitChunksPlugin to give shared CSS chunks different names

* fix lint
Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent e3d298dc
...@@ -311,6 +311,17 @@ export default async function getBaseWebpackConfig( ...@@ -311,6 +311,17 @@ export default async function getBaseWebpackConfig(
const devtool = dev ? 'cheap-module-source-map' : false const devtool = dev ? 'cheap-module-source-map' : false
const isModuleCSS = (module: { type: string }): boolean => {
return (
// mini-css-extract-plugin
module.type === `css/mini-extract` ||
// extract-css-chunks-webpack-plugin (old)
module.type === `css/extract-chunks` ||
// extract-css-chunks-webpack-plugin (new)
module.type === `css/extract-css-chunks`
)
}
// Contains various versions of the Webpack SplitChunksPlugin used in different build types // Contains various versions of the Webpack SplitChunksPlugin used in different build types
const splitChunksConfigs: { const splitChunksConfigs: {
[propName: string]: webpack.Options.SplitChunksOptions [propName: string]: webpack.Options.SplitChunksOptions
...@@ -368,14 +379,7 @@ export default async function getBaseWebpackConfig( ...@@ -368,14 +379,7 @@ export default async function getBaseWebpackConfig(
updateHash: (hash: crypto.Hash) => void updateHash: (hash: crypto.Hash) => void
}): string { }): string {
const hash = crypto.createHash('sha1') const hash = crypto.createHash('sha1')
if ( if (isModuleCSS(module)) {
// mini-css-extract-plugin
module.type === `css/mini-extract` ||
// extract-css-chunks-webpack-plugin (old)
module.type === `css/extract-chunks` ||
// extract-css-chunks-webpack-plugin (new)
module.type === `css/extract-css-chunks`
) {
module.updateHash(hash) module.updateHash(hash)
} else { } else {
if (!module.libIdent) { if (!module.libIdent) {
...@@ -400,7 +404,8 @@ export default async function getBaseWebpackConfig( ...@@ -400,7 +404,8 @@ export default async function getBaseWebpackConfig(
}, },
shared: { shared: {
name(module, chunks) { name(module, chunks) {
return crypto return (
crypto
.createHash('sha1') .createHash('sha1')
.update( .update(
chunks.reduce( chunks.reduce(
...@@ -410,7 +415,8 @@ export default async function getBaseWebpackConfig( ...@@ -410,7 +415,8 @@ export default async function getBaseWebpackConfig(
'' ''
) )
) )
.digest('hex') .digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
)
}, },
priority: 10, priority: 10,
minChunks: 2, minChunks: 2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment