Replies: 2 comments 2 replies
-
when using http2 this is not a problem (mostly). you should control this by using https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksmaxasyncrequests https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksmaxinitialrequests
you can set min size https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksminsize For long-term caching you can use https://webpack.js.org/plugins/split-chunks-plugin/#splitchunkslayer , module layer could be set in |
Beta Was this translation helpful? Give feedback.
-
Could you post your webpack 3 CommonsChunkPlugin configuration here? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
TL;DR: Would it be possible/feasible to bring back
CommonsChunkPlugin
as an optional alternative toSplitChunksPlugin
?I'm working in an enormous code base that
SplitChunksPlugin
doesn't seem to handle very well. Or, at least, I haven't been able to find a SplitChunks configuration that works well for us, despite literally dozens of hours spent debugging into the plugin and analyzing the internals. No matter what I do, our build output always has:In Webpack 3, we had things working pretty well by using
CommonsChunkPlugin
in combination with some coarse-grained "webpackChunkName" magic comments in dynamic imports that were structured such that we (a) had a relatively small number of well-named chunks, and (b) had a single parent chunk that all other chunks were children of.Organizing the async chunks like this, of course, made for a lot of duplicated modules. To resolve this we relied on 2 plugins:
This approach relied on the fact that Webpack executes
RemoveParentModulesPlugin
before every separate instance ofCommonsChunkPlugin
. So after a new "functional-area-common" chunk is created as a child of the main parent chunk, the next invocation ofRemoveParentModulesPlugin
will have a new chance to push the modules up into the parent.This approach was pretty easy to understand, reason about and control, and it seemed to work well. The loaded chunks were well-named and coarse-grained and the duplication was pretty minimal. Indeed we ended up with a very large main parent chunk (and associated common chunk) but that is fine because that code is needed by all workflows and should be always be loaded. The number of requests at runtime was fairly low.
With Webpack 5 and
SplitChunksPlugin
, I've become convinced after an enormous effort that there is no way to replicate this behaviour. The new heuristics-based approach is very difficult to reason about in a large code base and even with explicitly named cache groups I can't get close to what we had before. Even with debugging, I honestly can't predict (or even understand in some cases) which configuration changes are going to control what output. Configuration is a lot of guesswork and when you're dealing with 100K modules, there's really no way to guess right.Additionally, the iterative effect I described above between
RemoveParentModulesPlugin
andCommonsChunkPlugin
is no longer there because all cache groups are handled inside a singleSplitChunksPlugin
invocation. This means there's only a singleRemoveParentModulesPlugin
invocation and a singleSplitChunksPlugin
invocation.Which bring me to my question. 😄
Would it be possible/feasible to bring back
CommonsChunkPlugin
as a possible (of course, optional) alternative toSplitChunksPlugin
? I guess it was removed because it was felt that the functionality was superseded by SplitChunks, but that's clearly not the case for all kinds of code bases. Maybe having a choice here would be better?If you're still with me at this point, thanks for your attention. 😄
Beta Was this translation helpful? Give feedback.
All reactions