Skip to content

Instantly share code, notes, and snippets.

@molily
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molily/b37d7781dd27f93385f5 to your computer and use it in GitHub Desktop.
Save molily/b37d7781dd27f93385f5 to your computer and use it in GitHub Desktop.
Building a custom D3 with Smash and Gulp
import path from 'path';
import fs from 'fs';
import { Readable } from 'stream';
import es from 'event-stream';
import gulp from 'gulp';
import smash from 'smash';
const SRC_DIR = path.resolve('./src');
const JAVASCRIPTS_SRC_DIR = path.join(SRC_DIR, JAVASCRIPTS_DIR);
// Build custom D3 version
// -----------------------
// We only need some modules of D3 and the modularization isn’t finished yet.
// See https://github.com/mbostock/d3/issues/2461
// Meanwhile we’re using smash for this purpose.
// See https://github.com/mbostock/smash/wiki
const D3_MODULES = [
'start',
'geo/path', 'geo/orthographic',
'scale/quantile', 'scale/linear',
'xhr/json', 'dsv/tsv',
'end',
];
const D3_BUILD_FILE = path.join(JAVASCRIPTS_SRC_DIR, 'vendor', 'd3.js');
const D3_PRIMER = '/* Custom D3.js (http://d3js.org/) build created with `gulp d3` */\n/* eslint-disable */\n';
gulp.task('d3', () => {
const primerStream = new Readable();
primerStream.push(D3_PRIMER);
primerStream.push(null);
const d3Path = path.dirname(require.resolve('d3'));
const modules = D3_MODULES.map((module) =>
path.join(d3Path, 'src', module + '.js')
);
const smashStream = smash(modules);
return es.merge(primerStream, smashStream)
.pipe(fs.createWriteStream(D3_BUILD_FILE));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment