We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 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:
import { unique } from 'lodash-es'
It works great on static imports. However, sometimes when you want to make some part lazy-load, treeshaking stopped to work:
const { unique } = await import ('lodash-es') // entire `lodash-es` will be bundled
There is a workaround to this, is that you can create a temporary module that does the reexport:
// ./re-export.js import { unique } from 'lodash-es'
const { unique } = await import ('./re-export.js') // now you have tree-shaking
However, this makes it verbose to use and easy to miss.
Support tree-shaking dynamic imports that are known at build time. Namely, doing object destructure and directly assigning with await import()
await import()
const { foo, default: anotherName } = await import('foo')
const { foo } = await import('foo') const { bar } = await import('foo')
(await import('foo')).foo
(Tree shaking is not applicable, to the current behavior.)
// full bundle const foo = await import('foo')
// not waiting const promise = import('foo')
// rest const { foo, ...bar } = await import('foo')
// imported multiple times, but one of them is not tree shakable const { foo } = await import('foo') const foo = await import('foo')
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:
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 :)
Sorry, something went wrong.
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 npm install rollup.
npm install rollup
Successfully merging a pull request may close this issue.
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: