Skip to content

Commit

Permalink
Modify splitChunksPlugin to give shared CSS chunks different names
Browse files Browse the repository at this point in the history
  • Loading branch information
atcastle committed Feb 4, 2020
1 parent 9bbf31c commit befc190
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -410,7 +414,7 @@ export default async function getBaseWebpackConfig(
''
)
)
.digest('hex')
.digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
},
priority: 10,
minChunks: 2,
Expand Down

0 comments on commit befc190

Please sign in to comment.