Skip to content

Commit

Permalink
Modify splitChunksPlugin to give shared CSS chunks different names (v…
Browse files Browse the repository at this point in the history
…ercel#10408)

* Modify splitChunksPlugin to give shared CSS chunks different names

* fix lint

Co-authored-by: Joe Haddad <timer150@gmail.com>
  • Loading branch information
2 people authored and chibicode committed Feb 11, 2020
1 parent 731391d commit eaf3759
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions packages/next/build/webpack-config.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit eaf3759

Please sign in to comment.