Open patrickomeara opened 3 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is a valid issue.
Mix 6 disables webpacks's default cacheGroups, preventing code splitting (and grouping) inside dynamic imports. https://github.com/JeffreyWay/laravel-mix/blob/d27a77abb5a32f42e47d6e3d344ba757d85ad89a/src/Chunks.js#L165
what is involved in getting the common modules in separate chunks again as it was in v5.
The simplest solution seems like is to reenable webpack's default cacheGroups from config. Something like this:
mix.webpackConfig({
optimization: {
splitChunks: {
cacheGroups: {
customDefaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
customDefault: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
});
See https://webpack.js.org/plugins/split-chunks-plugin/ for more information.
Yeah we explicitly disabled it because it can produce chunks with very inconsistent names. I think this would be a good feature to add back that can be explicitly enabled though.
@thecrypticace
Any update on this? I would appreciate it if it's handled by default to produce consistent output and avoid issues.
Description:
In Mix 5 using dynamic imports produced common modules in chunks:
In Mix 6 the common modules are placed in each chunk:
This adds duplicate code and a bigger overall download.
I understand that I can extract all the modules to a
vendor.js
but this doesn't help with the initial download time if a user doesn't need the modules in the current section of the app.I'm wondering if this was a planned change or a byproduct of something else during the v5 to v6 releases, and what is involved in getting the common modules in separate chunks again as it was in v5.
Thanks.