bun
bun copied to clipboard
[bun build] tree-shaking not working for my project: tips on how to best debug?
howdy. I'm trying to run bun build
for a production TypeScript web app. long story short, tree shaking isn't working with a component library I'm using, resulting in a 4.5mb
output dist file (compare to about 750kb
for webpack & parcel builds of the same library, which seem to implement efficient tree shaking here). I've narrowed it down to a test case where I'm simply importing one component, which still results in the 4.5mb
output file.
my guess is that the component library I'm using is constructed in such a way that the bun builder can't tree-shake it, however I have no idea how to troubleshoot to confirm this. I can confirm that bun tree shaking in general is working because very simple examples do work (like the tree-shaking rollup REPL example).
so what can I do to determine whether bun build
should be able to tree shake my project? this component library is tree-shakeable with other builders so I'm hoping bun can eventually tree shake it as well. any advice?
(happy to produce a repo to replicate the issue, if that'd help anyone)
I am experiencing the same problem. With esbuild I had a 1,6MB bundled output file. With bun it's almost twice the size at 2.7MB. Were you able to solve your problem?
I am experiencing the same problem. With esbuild I had a 1,6MB bundled output file. With bun it's almost twice the size at 2.7MB. Were you able to solve your problem?
@cimchd I haven't solved it, no. I was also unable to produce a simplified example to replicate the problem; each simplified version I built did not exhibit the problem.
Try adding "sideEffects": false
in your package.json
and run the build again, I think this will solve your problem.