-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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, the hash-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):
- Ensure
sideEffects: false
is set inpackage.json
. I don't expect this to actually have a significant impact, but is always a first step. - Export the different API
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. - Ultimately maximum tree-shaking capability would require exporting individual API methods as functions, perhaps accepting common configuration options as a first or last function parameter or using an object parameter pattern. This would be a significant re-write and new pattern for the library.
Describe alternatives you've considered
None?
Additional context
Additional references:
teddyzeenny, michaelhays and stanoje-cimphony
Metadata
Metadata
Labels
enhancementNew feature or requestNew feature or request