Skip to main content
100%

D3 Custom Bundle with Webpack

✓ Published0🌍 Public
CCurran Kelleher
Last edited Mar 16, 2017
Created on Mar 16, 2017

A custom D3 bundle built with Webpack demonstrates importing `d3-transition` alongside `d3-selection` to animate a text element. The code appends an "Hello, world!" heading, rotates and scales it down, then uses `.transition().duration(1500)` to restore the transform over 1.5 seconds. The example shows how Webpack’s module resolution includes only the imported transition features, while the minified `d3.min.js` output is generated via UglifyJS. This illustrates a minimal setup for tree-shaking D3 modules in a browser environment.

AI-generated description

Another demonstration of a custom D3 bundle using Rollup. This demonstrates importing d3-transition, which modifies selection.prototype to define selection.transition:

import "d3-transition";

(There are other features in d3-transition, but they are not imported here because they are not used.) Note that you must also import selection from d3-selection; otherwise, Rollup doesn’t know that it needs to include the imported code from d3-transition. Rollup isn’t perfect at detecting which code needs to be included (and which code shouldn’t be included), so sometimes you need to give it a hand.

forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/97557a39b4bfc8229786c8bccb54074d'>D3 Custom Bundle II</a>

gpl-3.0 Licensed

Similar vizzes