-
Notifications
You must be signed in to change notification settings - Fork 309
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
ESM better treeshaking #298
Comments
This appears to be bugs (plural) in esbuild. The bwip-js ES6 modules are already properly structured for tree shaking and are verified to work with webpack. The first bug I see is that esbuild is preferring the
When you look at the generated code, you will see esbuild pulled in the So I tried to trick esbuild into using the ES6 module by updating
Because the default export is still present, the tree shaking can't happen. |
Thanks for your insight. Are we hitting into this issue? evanw/esbuild#1420 |
I don't believe that particular issue is the source of what we are seeing. We are not importing, then exporting namespaces. Similarly, we are not re-exporting the lower-level imports directly - our exports are new functions that reference the imports. Don't know if that is enough to trigger the behavior described. What confuses me is why the default export is bundled. It is not referenced by the top-level code and should be eliminated. Since esbuild seems to be an interesting bundler, I will play around with it some more to see if I can understand why it is including the default export. But we are still facing the bug in esbuild where it is not prioritizing the |
The default exports bug is now understood. If any of the exported values are unknown/untraceable, then esbuild gives up on the tree-shaking. Why an untraceable value in one module stops tree-shaking in another is beyond me - it should have no effect. This is the default export in
If the So that bug is understood and can be worked around. But we need esbuild to properly resolve modules using the |
While looking over the esbuild source code, specifically Release v3.4.5 also contains a wrapper around
|
Hi @metafloor, thanks for looking into this. I'm quite surprised to see ESBuild working this way. Is this behaviour documented anywhere? Happy to mark this issue as solved, although I would appreciate an answer regarding my PS to JS code question above. :) |
Regarding the PS to JS, there is a
The |
Here is the Vite work around.
|
I'd like to include this library in a front-end application, ideally without bundling the whole library. I don't think this is possible at the moment due to how it's structured. Have a look at the following example:
When bundling with ESBuild:
esbuild --bundle ./in.js --minify --outfile=out.js
The size of
out.js
is823.6kb
, which is the entire library, even though I only chose one symbology. It would also be nice if the symbol-specific exports didn't assume I require an output to a canvas.@metafloor Is it possible for others to contribute to this library? As far as I can tell, the code that does the postscript to js conversion hasn't been provided, it's only possible to see the output.
The text was updated successfully, but these errors were encountered: