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(
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
const splitChunksConfigs: {
[propName: string]: webpack.Options.SplitChunksOptions
......@@ -368,14 +379,7 @@ export default async function getBaseWebpackConfig(
updateHash: (hash: crypto.Hash) => void
}): string {
const hash = crypto.createHash('sha1')
if (
// 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`
) {
if (isModuleCSS(module)) {
module.updateHash(hash)
} else {
if (!module.libIdent) {
......@@ -400,17 +404,19 @@ export default async function getBaseWebpackConfig(
},
shared: {
name(module, chunks) {
return crypto
.createHash('sha1')
.update(
chunks.reduce(
(acc: string, chunk: webpack.compilation.Chunk) => {
return acc + chunk.name
},
''
return (
crypto
.createHash('sha1')
.update(
chunks.reduce(
(acc: string, chunk: webpack.compilation.Chunk) => {
return acc + chunk.name
},
''
)
)
)
.digest('hex')
.digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
)
},
priority: 10,
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