Skip to content

Commit

Permalink
Fix build of large css with Webpack (#1844)
Browse files Browse the repository at this point in the history
* Fix build of large css with Webpack

* Rename to isCss
  • Loading branch information
DreierF authored Dec 7, 2020
1 parent 5c1176d commit ac70a4a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion plugins/plugin-webpack/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function emitHTMLFiles({doms, jsEntries, stats, baseUrl, buildDirectory, htmlMin
}

function getSplitChunksConfig({numEntries}) {
const isCss = module => module.type === `css/mini-extract`
/**
* Implements a version of granular chunking, as described at https://web.dev/granular-chunking-nextjs/.
*/
Expand All @@ -115,7 +116,7 @@ function getSplitChunksConfig({numEntries}) {
*/
lib: {
test(module) {
return module.size() > 100000 && /web_modules[/\\]/.test(module.identifier());
return !isCss(module) && module.size() > 100000 && /web_modules[/\\]/.test(module.identifier());
},
name(module) {
/**
Expand All @@ -136,13 +137,19 @@ function getSplitChunksConfig({numEntries}) {
},
// modules used by all entrypoints end up in commons
commons: {
test(module) {
return !isCss(module)
},
name: 'commons',
// don't create a commons chunk until there are 2+ entries
minChunks: Math.max(2, numEntries),
priority: 20,
},
// modules used by multiple chunks can be pulled into shared chunks
shared: {
test(module) {
return !isCss(module)
},
name(module, chunks) {
const hash = crypto
.createHash(`sha1`)
Expand All @@ -155,6 +162,15 @@ function getSplitChunksConfig({numEntries}) {
minChunks: 2,
reuseExistingChunk: true,
},
// Bundle all css & lazy css into one stylesheet to make sure lazy components do not break
styles: {
test(module) {
return isCss(module)
},
name: `styles`,
priority: 40,
enforce: true,
},
},
};
}
Expand Down

1 comment on commit ac70a4a

@vercel
Copy link

@vercel vercel bot commented on ac70a4a Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.