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

Created on 5 Nov 2019  路  5Comments  路  Source: uber/react-vis

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

All 5 comments

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

https://github.com/uber/react-vis/blob/70e4f6f61040cbcdb53dba85b8fa0dc5a1731ebd/src/plot/series/abstract-series.js#L199

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martoncsikos picture martoncsikos  路  4Comments

basilaiman picture basilaiman  路  3Comments

jckr picture jckr  路  5Comments

jonnydodad picture jonnydodad  路  4Comments

mcnuttandrew picture mcnuttandrew  路  3Comments