Skip to content

Make the library more tree-shakable to significantly reduce bundle size #514

@adamstoffel

Description

@adamstoffel

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.)

Image

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):

  1. Ensure sideEffects: false is set in package.json. I don't expect this to actually have a significant impact, but is always a first step.
  2. 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 of BoxClient. Documentation should also be updated to prefer this syntax.
  3. 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:

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions