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
When using dynamic imports, dead code elimination no longer works for chunks. #7500
Comments
|
This is the expected behavior. Tree shaking is not supported on async chunks. |
|
Why? I'm using dynamic imports as the mechanism to split journeys, where the main entrypoint loads the journey and configures the app in a way common to all journeys (ReactDOM render, store setup, etc.). The chunks being loaded are effectively standalone, and could be statically analysed and have dead code marked per-chunk. Is there a technical reason that DCE can't be achieved in this configuration? |
|
cc @sokra |
Sadly this is not true. You could load both chunks at the same time. In this case module caching kicks in and same module must not be evaulated twice. Note that this doesn't matter in your case because you only exporting pure functions, but technically both function could share a common counter. Because of this (edge-case) modules must be equal in all chunks (or at least in all chunks sharing a runtime chunk). Currently you have to split your module into two if you want to have per-chunk tree shaking. You can do |
|
That is a shame 😕. It looks like to get the sort of configuration I want I'll have to look at using Thanks for weighing in. |
Bug report
When using dynamic imports, tree shaking no longer works for generated chunks.
A small reproducible example can be found here.
Working:
If the entrypoint does not use dynamic imports and imports statically, the dead code is removed from the bundle.
Expected:
Each chunk should have its own static analysis context, and the
sum.jschunk should not include theproductfunction fromlib.js, and vice versa for theproduct.jschunk.Versions
webpack version: 4.11.1
Node.js version: 10.2.0
Operating System: macOS 10.12
Additional tools:
The text was updated successfully, but these errors were encountered: