Webpack will include everything from d3.js in the package when import { select } from 'd3' executed, as shown in the following package visualization. The problem can be solved with import { select } from 'd3-selection' , but this somewhat worsens the goal of automatic tree shake.
Shaking trees seems to work in simple cases with our non-library code.
We use "modules": false in our .babelrc to save the module syntax and use 'module' in our webpack.config.js resolve: { mainFields: ['module', 'browser', 'main'] } to select code based on d3 module. As you can see, the imported node_modules / d3 / index.js is split into ES6 modules instead of a monolithic browser package or CommonJS export.
Should this be posted as a problem on the gigub webpack page or am I doing something wrong? This uses all the latest library versions ( d3@4.5.0 , webpack@2.2.1 , etc.)
edit: This appears to be related to the following issues:
Nathan liebrecht
source share