From befc190487a49fe1d457d5f2ce26d7d0bf0c8686 Mon Sep 17 00:00:00 2001 From: atcastle Date: Mon, 3 Feb 2020 16:44:59 -0800 Subject: [PATCH 1/2] Modify splitChunksPlugin to give shared CSS chunks different names --- packages/next/build/webpack-config.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 9993f1201ee4d..1b8c9117a72e1 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -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) { @@ -410,7 +414,7 @@ export default async function getBaseWebpackConfig( '' ) ) - .digest('hex') + .digest('hex') + (isModuleCSS(module) ? '_CSS' : '') }, priority: 10, minChunks: 2, From 33bd99c940e215f38a2b20215969b3dec2573448 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 4 Feb 2020 13:58:56 -0500 Subject: [PATCH 2/2] fix lint --- packages/next/build/webpack-config.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 8eb03c37c7722..12aedaf210d43 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -311,7 +311,7 @@ export default async function getBaseWebpackConfig( const devtool = dev ? 'cheap-module-source-map' : false - const isModuleCSS = (module: {type: string}): boolean => { + const isModuleCSS = (module: { type: string }): boolean => { return ( // mini-css-extract-plugin module.type === `css/mini-extract` || @@ -404,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') + (isModuleCSS(module) ? '_CSS' : '') + .digest('hex') + (isModuleCSS(module) ? '_CSS' : '') + ) }, priority: 10, minChunks: 2,