Replies: 1 comment 4 replies
-
@sokra, @alexander-akait, do you guys have any ideas for how I could achive a side-effect free "maxSize" behavior? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a quite large legacy code base that we still need to keep around for some time. In this legacy code we define an enormous chunk group, called "main-chunk", that contains a lot of the modules needed for the application to start up. In total, this chunk group adds up to around 30MB in total, minified. Yeah.
By default, splitChunks divides this big chunk group up into a reasonably decent set of chunks, with the biggest ones being fairly manageable and no one chunk being too much bigger than the others. With parallel loading, this works OK. There are 44 chunks in total for this chunk group and here's a sample of the sizes of the top 10 biggest:
Recently we removed a dependency that affected the relationship between quite a number of modules. The code didn't change almost at all -- it was a 1 line change -- but the dependency graph looks quite different. Now splitChunks produced something a lot less optimal than what is shown above. The main-chunk group is now split into 42 chunks with the top 10 looking like this:
That giant 19MB chunk causes a performance problem because all chunks from this group need to be loaded before execution can continue. And that one chunk, being so much bigger than the others, causes a lag waiting for it to complete.
So we want to go back to something like we had before, where the biggest chunk is around 9MB and -- more importantly -- the very largest chunks are roughly the same size.
From the documentation, it looks like maxSize is the splitChunks setting we want. But I can't get it to work the way I want. I would like to it to do nothing more than to just take the one chunk that is too big, and split that chunk into 2 roughly equal sized parts. But maxSize seems to do a lot more than that.
After playing around to find the right size (because maxSize works based on the size of non-minified modules) I landed on
maxSize: 25 * 1024 * 1024
being the setting that would bring the biggest chunk down to what it was before. But the problem is with the side effects. With that setting in place, splitChunks now produces 50 chunks (instead of 44 like before), with the top 10 looking like this:You can see that it doesn't just split the one chunk that exceeds the maxSize threshold, but instead it juggles a whole bunch of other stuff around, resulting in more modules than before and a different size distribution from top to bottom. The fact that there are now 50 modules instead of 44 negates any performance benefit that we see from reducing the size of the largest chunk. So we're no better off.
What I'm really looking for is just is a simple setting that does nothing else but take a chunk that exceeds a maximum size and divide that chunk into 2 (or more, as necessary) chunks of roughly equal size. It should not touch any other chunk.
This is not what maxSize does. Is there another plugin I can use for this? Or is there another configuration option that might behave like this?
I'm open to any ideas you might have. If you're still reading this far, thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions