-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to disable tree shaking? #1518
Comments
Just don't |
@hyrious Thank you for answer. |
Do you have bundling enabled? There shouldn’t be any observable difference between bundling with tree shaking enabled and bundling with it disabled, so there is no way to disable tree shaking while bundling. Can you say why you need to do this? The one thing you can control is to disable user-specified tree shaking annotations, which is sometimes useful as these annotations can sometimes be incorrect: https://esbuild.github.io/api/#manual-tree-shaking-annotations. |
@evanw |
I’m guessing your desire for disabling tree shaking is coming from a misunderstanding of how export formats work. There are currently three supported output formats when bundling is enabled: CommonJS, ES modules, and global code that is wrapped in a closure (a.k.a. IIFE). There is no output format for global code that’s not wrapped in a closure, so unexported module-level variables can never be accessed outside of the output file and tree shaking is always valid. See https://esbuild.github.io/api/#format. If you are running code in the browser, you need to pick either ESM or IIFE. Neither of these formats allow module-level variables to leak into the global scope, so it’s ok for esbuild to remove unused code as it cannot possibly be referenced. If you want to expose exports from your code on the global object when your script is run, you should use the IIFE format and either use the global name setting or manually assign your exports to properties on the global scope with You should only be using the ESM format with |
@evanw Thank you. |
Hello.
Build with unused functions or variables included. Please tell me how to disable tree shake.
Thanks.
The text was updated successfully, but these errors were encountered: