Last active
August 29, 2015 14:26
-
-
Save molily/b37d7781dd27f93385f5 to your computer and use it in GitHub Desktop.
Building a custom D3 with Smash and Gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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