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,17 +404,19 @@ export default async function getBaseWebpackConfig( ...@@ -400,17 +404,19 @@ export default async function getBaseWebpackConfig(
}, },
shared: { shared: {
name(module, chunks) { name(module, chunks) {
return crypto return (
.createHash('sha1') crypto
.update( .createHash('sha1')
chunks.reduce( .update(
(acc: string, chunk: webpack.compilation.Chunk) => { chunks.reduce(
return acc + chunk.name (acc: string, chunk: webpack.compilation.Chunk) => {
}, return acc + chunk.name
'' },
''
)
) )
) .digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
.digest('hex') )
}, },
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