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
No tree shaking after dead code removal in dynamic import #16271
Comments
I found some relates issue #13028, and understand this could not be done right now. But still got some related questions @vankop @alexander-akait :
export { b } from "./await-import-modules"; treeshaking-test.ts import { b } from "./intermediate";
export const treeShakingTestAsync = async () => {
console.log('treeShakingTestAsync');
const { b } = await import('./intermediate');
return b;
}; in this way, unused function 'FuncA' cant't be found in the output file, as expected. |
@icy0307 This is not hard, the main problem is babel and another transpilers and renaming variables, yes it's fixable, but need more work, if you want to help us feel free to continue dicussion here #14800 and ask questions There is a PR with attempts to resolve, so you can build own solution let's close this, because the root of the problem is #14800 |
Bug report
With mode: production on, and "sideEffects:false", exported function that are unused after dead code removal remain in the bundle, if the module is imported dynamically.
https://stackblitz.com/edit/github-2yf5yf?file=dist/main.js
What is the current behavior?
unused function not get removed if the file is imported dynamically
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
"treeShakingTestAsync" cannot be found in the output file, as expected.
But 'FuncA' can be found, not get tree-shaken or deadcode removed.
'FuncA' should be tree-shaken
Other relevant information:
webpack version: 5.74.0
Node.js version: v14.15.0
Operating System: macOS 12.0.1
Additional tools:
The text was updated successfully, but these errors were encountered: