palerdot / react-d3-speedometer

React Speedometer component using d3.js ⚛️
https://palerdot.in/react-d3-speedometer/
MIT License
229 stars 57 forks source link

Reducing bundle size #134

Open ZipBrandon opened 2 years ago

ZipBrandon commented 2 years ago

Adding react-d3-speedometer to an application that makes extensive use of d3 via nivo results in importing the entire d3 package. This can be circumvented with redeclaring imports so they don't import from the index of d3; or declaring sideEffects in the package.json.

image

ZipBrandon commented 2 years ago

With a bit of further investigation, this seems like this improvement would be yielded from usage of the alternate d3 libraries and not d3.

palerdot commented 2 years ago

This can be circumvented with redeclaring imports so they don't import from the index of d3; or declaring sideEffects in the package.json

Can you please elaborate more on what you mean by this? An example code snippet to explain your ideas might be helpful.

Also, this could also be solved by moving d3 to peerDependencies and offload d3 import mechanism to the build system used by the project. But, most of the consumers of this library may not use d3 in their project and they might just need this component.