/snowpack-d3

❄️ 📦 A robust development environment for building D3 visualizations.

Primary LanguageJavaScriptMIT LicenseMIT

Snowpack + D3 Development Environment

Quickly build D3 visualizations (v6) with a robust development environment that offers the following out-of-the-box features:

  • Hot-Module Replacement and Fast Refresh
  • Integrates Webpack (Via @snowpack/plugin-webpack Plugin) for a Production-Optimized Build
  • Targets IE 11 via Browserslist
  • Preview Production-Optimized Build via http-server
  • Automatic Polyfill Injection
  • ES6+ Syntax Support

Safari

IE 11

Example Visualization Source: https://observablehq.com/@d3/density-contours

The snowpack.config.js file is heavily annotated with comments. Be sure to read through the comments!

This project is bootstrapped with blank template of Create Snowpack App (CSA).

Production-Optimized Build

The size of the application's production-optimized build will depend on how you import the D3 library into the project.

Importing the Entire D3 Library

import * as d3 from d3

Bundle Size - Importing the Entire D3 Library

Importing Constituent D3 Libraries

import { scaleLinear } from "d3-scale";
import { extent } from "d3-array";
import { tsv } from "d3-fetch";
import { axisBottom, axisLeft } from "d3-axis";
import { contourDensity } from "d3-contour";
import { select } from "d3-selection";
import { geoPath } from "d3-geo";

Bundle Size - Importing Constituent D3 Libraries

Available Scripts

npm start

Runs the application in the development mode. Open http://localhost:8080 to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

npm run build

Builds a static copy of your site to the build/ folder. Your application is ready to be deployed!

npm run serve

Runs the production-optimized application. Open http://localhost:5555 to view it in the browser.