react-vis icon indicating copy to clipboard operation
react-vis copied to clipboard

Bundle size is very large to due d3-* imports: Why does XYPlot depend on d3-voronoi?

Open bt-88 opened this issue 7 years ago • 5 comments

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

bt-88 avatar Nov 05 '19 10:11 bt-88

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
		}
	]
}

jsalis avatar Nov 08 '19 04:11 jsalis

I imagine that d3-voronoi is used to create a voronoi hit area for interaction with the XYPlot.

ericsoco avatar Nov 08 '19 05:11 ericsoco

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

jonsadka avatar Nov 12 '19 00:11 jonsadka

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

Thanks for clearing this up.

bt-88 avatar Nov 15 '19 07:11 bt-88

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.

bt-88 avatar Nov 15 '19 07:11 bt-88