-
Notifications
You must be signed in to change notification settings - Fork 7
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
Make the library more tree-shakable to significantly reduce bundle size #514
Comments
Hello, I believe our Managers should act similarly as described in the second point. The
As for the tree shaking, I see that there are some issues with barrel file we expose if you import code from it (we re-export You could try to adjust the imports to import files directly Before After: |
Cool to see such reduction in bundle size. As for your suggestions
|
Another big improvement could come from building and distributing an ESM version of the library. Since the library is currently compiled to CommonJS, there's no ability for tree-shaking to eliminate dead code in downstream dependencies. Namely, the I realized the entire I'm quite certain this is because const hash_wasm_1 = require("hash-wasm"); ESBuild is not able to tree-shake CJS-style |
Would you be open to me submitting a PR which adds the changes necessary to generate and publish this as a hybrid UMD & ES package? I was able to do this with a local copy of the library and, for my case, reduced the Box assets even further from 448K to 388K and hash-wasm from 215K to 13K! |
Is your feature request related to a problem? Please describe.
Because this library is implemented as one massive exported
BoxClient
class, it is impossible for bundlers like webpack and rollup to perform effective tree-shaking and remove unused portions of library code. In our app we are using this SDK in a client-side browser context, so bundle size is important to us, and the Box SDK comprises nearly half of our client-side JS bundle. (Of note, thehash-wasm
package, which the Box SDK depends on, is also a very large package that could be eliminate for folks who don't need uploads.)Describe the solution you'd like
There's some incremental steps that could be taken to improve tree shaking (there is a huge leap from 2 to 3):
sideEffects: false
is set inpackage.json
. I don't expect this to actually have a significant impact, but is always a first step.Manager
classes as separate uniquely instantiable client classes. This would provide the immediate benefit of tree shaking tools being able to eliminate unused code from any API which is not being called. This could probably be implemented without any breaking changes for current consumers ofBoxClient
. Documentation should also be updated to prefer this syntax.Describe alternatives you've considered
None?
Additional context
Additional references:
The text was updated successfully, but these errors were encountered: