Closed thoughtspile closed 1 year ago
@thoughtspile Sorry, for the delay, but after a through analysis of the bundl, a deconstruction and re-write of the virtual filesystem of bundlejs, it seems it keeps trying to bundle in the parser, and I can't quite figure out why.
It doesn't really make any sense as to why it keeps trying to bundle the parser, this might be an esbuild-wasm bug of some sort, it's super inconsistent, and due to the lack of an AST it's really difficult to debug where it's messing up
After a couple more experiments it seems for treeshaking to work in an ideal way it needs to have all the files it needs to traverse up front, the problem is that is double the build time versus just bundling it once.
I've setup a seperate branch with the treeshaking exeriments https://bundle-git-treeshaking-fix-okikio-dev.vercel.app/?q=date-fns&treeshake=%5B%7B+isAfter+%7D%5D&config=%7B%22esbuild%22%3A%7B%22minify%22%3Afalse%7D%7D
Good news, I seem to have a permanent solution to the problem of poor treeshaking. It seems this issue is caused by esbuild being unable to determine if it should include sideEffects or not.
On a local file system esbuild can easily just look up the package.json
files but it can't quite do that when using a virtual fs, so the solution is to just let esbuild know to use sideEffects
if it's stated in the package.json
file
Hi again my friend @okikio! Got a chance to roll out the fix? Still seeing odd sizes in badges:
I was able to fix it, I just hadn't found a chance to publish it. This weekend is a little hectic, I should be able to get the fix out by Tuesday or Wednesday this week
The API hasn't been fixed yet, but here is the newly improved treeshaking
The API is now fixed as well. Treeshaking should now work properly across the website and API. I'll keep this issue open, please let me know if you notice any issues
https://bundlejs.com/?q=date-fns&treeshake=%5B%7B+isAfter+%7D%5D&bundle
@thoughtspile Does the fix work for you?
Since the fix seems to work ill close this issue
Thanks @okikio, works much better now! I'm seeing some other suspicious behavior, let me open another issue
Ok
Looks like badges ignore treeshake option. Example with
date-fns
, trying to treeshakeisAfter
:Moreover, local
echo 'export { isAfter } from "date-fns";' | npx esbuild --bundle --minify | gzip -c | wc -c
gives 541 bytes, maybe related to #43