-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Treeshake "static" dynamic import #4951
Labels
Comments
Let me know if you think this is a good direction. I am already working on it locally, might need sometime to get familiar with the codebase :) |
9 tasks
Linking some related issues: #3417, #3447, vitejs/vite#11080 |
Thanks for the reference! |
This issue has been resolved via #4952 as part of rollup@3.21.0. You can test it via |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Use Case
Treeshake is such a brilliant idea. Nowadays, it powers so many frameworks/libraries to innovate without worries too much about the bundle size.
It's great that you can take some parts from a package, without paying the cost of the entire bundle:
It works great on static imports. However, sometimes when you want to make some part lazy-load, treeshaking stopped to work:
Workaround
There is a workaround to this, is that you can create a temporary module that does the reexport:
However, this makes it verbose to use and easy to miss.
Feature Proposal
Support tree-shaking dynamic imports that are known at build time. Namely, doing object destructure and directly assigning with
await import()
Valid cases
Invalid cases
(Tree shaking is not applicable, to the current behavior.)
Even though the "valid cases" are a bit strict, I believe it's still a very common pattern for people to benefit from.
Idea credits: Webpack 5.80 https://twitter.com/TheLarkInn/status/1648739331807510528
The text was updated successfully, but these errors were encountered: