bun icon indicating copy to clipboard operation
bun copied to clipboard

[bun build] tree-shaking not working for my project: tips on how to best debug?

Open i-a-n opened this issue 1 year ago • 3 comments

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?

i-a-n avatar Oct 26 '23 02:10 i-a-n

(happy to produce a repo to replicate the issue, if that'd help anyone)

i-a-n avatar Oct 26 '23 20:10 i-a-n

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 avatar Mar 09 '24 12:03 cimchd

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.

i-a-n avatar Apr 05 '24 21:04 i-a-n

Try adding "sideEffects": false in your package.json and run the build again, I think this will solve your problem.

devcaeg avatar Apr 13 '24 05:04 devcaeg