Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify splitChunksPlugin to give shared CSS chunks different names #10408

Merged
merged 4 commits into from Feb 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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