-
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
Tree-shaking seems to not work with Re-exporting / Aggregating #613
Comments
What do the files contain? If the files have side effects, they have to be bundled even if they aren't used since removing code with side effects would be incorrect. |
Oh wow that was fast. The repo i am talking about is here https://github.com/okikio/native/blob/master/packages/native/src/api.ts The surrounding files and folders should give a good understanding of the situation, however, I don't think the cause are side effects. |
I did some more testing and if I directly import from the file I need without any re-exports, the bundle is much smaller, so, I conclude the problem isn't from side-effects, it's that If you need me to create a demo, or something else I would be happy to help. |
The repo was helpful. It looks like this is due to the top-level use of imported symbols: import { Service } from "./service";
export class Router extends Service {
...
} In this case This is obviously a pretty extreme edge case. I could try to solve this such that it only works for non-CommonJS files which would preserve the getter with side-effect scenario. But arguably doing so would almost never be helpful and would likely still violate user expectations the vast majority of the time. So perhaps I should just consider all imported symbols to be side-effect free even if you could technically make one that isn't, since it's likely that no real-world code does that and it would prohibit tree shaking for side-effect free CommonJS modules. I'll think more about what to do here. |
Well if the problem is that esbuild doesn't know the type of file it should expect, why not use tsconfig to let it know that this is a module, as I already specified isolatedModules in the tsconfig so it is safe to assume that its a module with no side effects. |
Thanks |
Esbuild is awesome but I have found that Tree-shaking seems to not work with Re-exporting / Aggregating.
What I mean is that given an example like this:
The bundle will result in all modules being bundled together, even though only one of the modules is in use.
The text was updated successfully, but these errors were encountered: