We are using the latest version of react-vis in our UI library to create a Plot component based on XYPlot and we use rollup to bundle it.
When building, rollup adds a hefty 700KB (!) to our library with all kinds of d3 dependencies, such as d3-voronoi. But this seems strange. Why would XYPlot require d3-voronoi (amongst others). Is this due to an superfluous require() somewhere? Or is it actually used?
In general, what is the advice to keep your react-vis bundle as small as possible when used with rollup (or webpack)?
I think the issue is that react-vis is not tree-shakable. Not sure about rollup, but I solved it in webpack with the config below.
module: {
rules: [
// your other rules
{
include: path.resolve('node_modules', 'react-vis'),
sideEffects: false
}
]
}
I imagine that d3-voronoi is used to create a voronoi hit area for interaction with the XYPlot.
I imagine that d3-voronoi is used to create a voronoi hit area for interaction with the XYPlot.
Yup, this is correct. We use the voronoi to find the closest point in x-y space. Reference here https://github.com/uber/react-vis/blob/70e4f6f61040cbcdb53dba85b8fa0dc5a1731ebd/src/plot/series/abstract-series.js#L199
I imagine that d3-voronoi is used to create a voronoi hit area for interaction with the XYPlot.
Yup, this is correct. We use the voronoi to find the closest point in x-y space. Reference here
Thanks for clearing this up.
I think the issue is that react-vis is not tree-shakable. Not sure about rollup, but I solved it in webpack with the config below.
module: { rules: [ // your other rules { include: path.resolve('node_modules', 'react-vis'), sideEffects: false } ] }
Rollup applies tree shaking by default.