Skip to content
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

Add sideEffects field to package.json #10714

Merged
merged 2 commits into from Aug 30, 2022
Merged

Add sideEffects field to package.json #10714

merged 2 commits into from Aug 30, 2022

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented Aug 22, 2022

As mentioned in #9212 (comment), the sideEffects field in package.json is necessary to enable tree shaking in conservative build tools such as Webpack. CesiumJS has generally maintained a fairly agnostic package.json file, but I think it's worth it to include such a field in this case since it's a dramatic optimization benefit for a popular build tool. While specific to bundlers like Webpack, it's common that libraries, such as three.js and BabylonJS, define it.

This can be tested with a fairly minimal Webpack config, eg. https://github.com/CesiumGS/cesium-webpack-example. Without sideEffects defined, the default app is 17.2MB bundled. With sideEffects, the default app drops to 14.2MB bundled. If you have an even smaller example, say and app that only imports Cartesian3, it can drop to ~100KB.

@cesium-concierge
Copy link

Thanks for the pull request @ggetz!

  • ✔️ Signed CLA found.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.

@sanjeetsuhag
Copy link
Contributor

Using the default application in cesium-webpack-example, I compared the build sizes:

Build Mode main side-effects
development 23.5 MB 20.8 MB
production 19.4 MB 17.6 MB

I modified index.js to only include Cartesian3 and then I compared the build sizes:

Build Mode main side-effects
development 23.4 MB 7.6 MB
production 19.3 MB 7.6 MB

Note: I had to add the following property to resolve in webpack.config.js to get things to work on the main branch of cesium-webpack-example:

fallback: {
    http: false,
    https: false,
    zlib: false,
}

Copy link
Contributor

@sanjeetsuhag sanjeetsuhag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ggetz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants