mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
rollup-plugin-node-resolve seems unable to resolve d3 under npm2 which is installed by default with node 4. So this plugin adds an extra include path to help it find the d3 dependencies. npm3 flat dependencies: /node_modules/d3-selection npm2 hierarchical dependencies: /node_modules/d3/node_modules/d3-selection
85 lines
1.8 KiB
JavaScript
85 lines
1.8 KiB
JavaScript
/* eslint-disable no-console */
|
|
|
|
var fs = require('fs');
|
|
var rollup = require('rollup');
|
|
var includePaths = require('rollup-plugin-includepaths');
|
|
var nodeResolve = require('rollup-plugin-node-resolve');
|
|
var commonjs = require('rollup-plugin-commonjs');
|
|
var json = require('rollup-plugin-json');
|
|
var http = require('http');
|
|
var gaze = require('gaze');
|
|
var ecstatic = require('ecstatic');
|
|
|
|
var building = false;
|
|
var cache;
|
|
if (process.argv[2] === 'develop') {
|
|
build();
|
|
|
|
gaze(['modules/**/*.js', 'data/**/*.{js,json}'], function(err, watcher) {
|
|
watcher.on('all', function() {
|
|
build();
|
|
});
|
|
});
|
|
|
|
http.createServer(
|
|
ecstatic({ root: __dirname, cache: 0 })
|
|
).listen(8080);
|
|
|
|
console.log('Listening on :8080');
|
|
|
|
} else {
|
|
build();
|
|
}
|
|
|
|
|
|
|
|
function unlink(f) {
|
|
try { fs.unlinkSync(f); } catch (e) { /* noop */ }
|
|
}
|
|
|
|
function build() {
|
|
if (building) return;
|
|
|
|
// Start clean
|
|
unlink('dist/iD.js');
|
|
unlink('dist/iD.js.map');
|
|
|
|
building = true;
|
|
console.log('Rebuilding');
|
|
console.time('Rebuilt');
|
|
|
|
rollup.rollup({
|
|
entry: './modules/id.js',
|
|
plugins: [
|
|
includePaths({
|
|
paths: [
|
|
'node_modules/d3/node_modules' // for npm 2
|
|
]
|
|
}),
|
|
nodeResolve({
|
|
module: true,
|
|
main: true,
|
|
browser: false
|
|
}),
|
|
commonjs(),
|
|
json()
|
|
],
|
|
cache: cache
|
|
}).then(function (bundle) {
|
|
bundle.write({
|
|
format: 'iife',
|
|
dest: 'dist/iD.js',
|
|
sourceMap: true,
|
|
useStrict: false
|
|
});
|
|
building = false;
|
|
cache = bundle;
|
|
console.timeEnd('Rebuilt');
|
|
}, function(err) {
|
|
building = false;
|
|
cache = undefined;
|
|
console.error(err);
|
|
});
|
|
}
|
|
|