-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Document why tree shaking is not performed on async chunks #2684
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
Comments
One can't say this in general. Here are two cases were tree-shaking may not work as expected from user perspective, but there are reasons why it works this way:
|
Makes sense, thanks for explanations! 👍 |
So, in your example above, if module B doesn't exist and module A looks like this:
import('./module-X').then(({ exportD }) => ...); If |
How about this pattern: // page-1.js define everything in same file
export const route = {
path: '/page-1',
...other
};
export function Component(){
return h('div')
} // route.js
import { route } from './page-1.js'; // tree shake, route only
const router = [
{
...route,
// tree shake, Component only
component: import('./page-1.js').then(({ Component }) => Component);
}
] or top-level-await: const { Component } = await import('./page-1.js') |
can a comment annotation be supported? like: import(/* webpackOnlyImport: A0 */'./A').then(({ A0 }) => ...); |
Yes that was added in the meantime. It's called |
Is there any workaround to get this working in webpack 4? |
* chore: npm outdated * chore: update notistack * chore: update webpack * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * perf: less bytes for platform icons * chore: remove constants * perf: remove useless function * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: add sizes * chore: refactor * perf: remove useless props spread operation * perf: remove dummy workaround * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * chore: npm outdated * perf: add webpackExports for await import webpack/webpack.js.org#2684 * chore: npm outdated * chore: revert to notistack 2.0.5 * chore: revert previous commit * chore: update package.json
Feature to document
Tree shaking aka dead code elimination
Details
According to this comment, tree shaking is not supported for async chunks, but there's no mention of this in the tree shaking guide.
Additional information
I've read this comment from @sokra but it's quite terse and since the OP deleted his repo, it's not clear to me: does webpack always disable tree shaking for async chunks, or only in case when there are 2+ async chunks which share the same module, say
foo.js
? Are there any other gotchas to know about?I can send a patch but I need to understand this better.
The text was updated successfully, but these errors were encountered: