mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Testing out multiple build targets in build_src..
Also silence warnings - closes #4120
This commit is contained in:
144
build_src.js
144
build_src.js
@@ -6,10 +6,28 @@ const json = require('rollup-plugin-json');
|
||||
const nodeResolve = require('rollup-plugin-node-resolve');
|
||||
const rollup = require('rollup');
|
||||
const shell = require('shelljs');
|
||||
//const visualizer = require('rollup-plugin-visualizer');
|
||||
const visualizer = require('rollup-plugin-visualizer');
|
||||
|
||||
let _currBuild = null;
|
||||
|
||||
// rollup plugin options
|
||||
const INCLUDEPATHSOPTS = {
|
||||
paths: ['node_modules/d3/node_modules'], // npm2 or windows
|
||||
include: {
|
||||
'martinez-polygon-clipping': 'node_modules/martinez-polygon-clipping/dist/martinez.umd.js'
|
||||
}
|
||||
};
|
||||
const NODERESOLVEOPTS = {
|
||||
mainFields: ['module', 'main'],
|
||||
browser: false,
|
||||
dedupe: ['object-inspect']
|
||||
};
|
||||
const JSONOPTS = {
|
||||
indent: ''
|
||||
};
|
||||
|
||||
|
||||
|
||||
// if called directly, do the thing.
|
||||
buildSrc();
|
||||
|
||||
@@ -24,35 +42,41 @@ function buildSrc() {
|
||||
console.log(START);
|
||||
console.time(END);
|
||||
|
||||
return _currBuild =
|
||||
buildModern()
|
||||
// .then(() => buildES5())
|
||||
.then(() => {
|
||||
console.timeEnd(END);
|
||||
console.log('');
|
||||
_currBuild = null;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
console.log('');
|
||||
_currBuild = null;
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function buildModern() {
|
||||
console.log('📦 ' + colors.yellow('Bundling modern JavaScript...'));
|
||||
|
||||
// Start clean
|
||||
shell.rm('-f', [
|
||||
//'docs/statistics.html',
|
||||
'dist/iD.js',
|
||||
'dist/iD.js.map'
|
||||
]);
|
||||
|
||||
return _currBuild =
|
||||
let prom =
|
||||
rollup.rollup({
|
||||
input: './modules/id.js',
|
||||
onwarn: onWarn,
|
||||
plugins: [
|
||||
includePaths({
|
||||
paths: ['node_modules/d3/node_modules'], // npm2 or windows
|
||||
include: {
|
||||
'martinez-polygon-clipping': 'node_modules/martinez-polygon-clipping/dist/martinez.umd.js'
|
||||
}
|
||||
}),
|
||||
nodeResolve({
|
||||
mainFields: ['module', 'main'],
|
||||
browser: false,
|
||||
dedupe: ['object-inspect']
|
||||
}),
|
||||
includePaths(INCLUDEPATHSOPTS),
|
||||
nodeResolve(NODERESOLVEOPTS),
|
||||
commonjs(),
|
||||
json({ indent: '' }),
|
||||
// viz causes src build to take about 3x longer; skip
|
||||
// visualizer({
|
||||
// filename: 'docs/statistics.html',
|
||||
// sourcemap: true
|
||||
// })
|
||||
json(JSONOPTS)
|
||||
]
|
||||
})
|
||||
.then((bundle) => {
|
||||
@@ -62,19 +86,77 @@ function buildSrc() {
|
||||
sourcemap: true,
|
||||
strict: false
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
console.timeEnd(END);
|
||||
console.log('');
|
||||
_currBuild = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
_currBuild = false;
|
||||
console.log('');
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
return prom;
|
||||
};
|
||||
|
||||
|
||||
function buildES5() {
|
||||
console.log('📦 ' + colors.yellow('Bundling ES5 JavaScript...'));
|
||||
|
||||
// Start clean
|
||||
shell.rm('-f', [
|
||||
'dist/iD.es5.js',
|
||||
'dist/iD.es5.js.map'
|
||||
]);
|
||||
|
||||
let prom =
|
||||
rollup.rollup({
|
||||
input: './modules/id.js',
|
||||
plugins: [
|
||||
includePaths(INCLUDEPATHSOPTS),
|
||||
nodeResolve(NODERESOLVEOPTS),
|
||||
commonjs(),
|
||||
json(JSONOPTS)
|
||||
]
|
||||
})
|
||||
.then((bundle) => {
|
||||
return bundle.write({
|
||||
format: 'iife',
|
||||
file: 'dist/iD.es5.js',
|
||||
sourcemap: true,
|
||||
strict: false
|
||||
});
|
||||
});
|
||||
|
||||
return prom;
|
||||
};
|
||||
|
||||
|
||||
function buildStats() {
|
||||
console.log('📦 ' + colors.yellow('Building statistics...'));
|
||||
|
||||
// Start clean
|
||||
shell.rm('-f', [
|
||||
'docs/statistics.html'
|
||||
]);
|
||||
|
||||
return
|
||||
rollup.rollup({
|
||||
input: './modules/id.js',
|
||||
plugins: [
|
||||
includePaths(INCLUDEPATHSOPTS),
|
||||
nodeResolve(NODERESOLVEOPTS),
|
||||
commonjs(),
|
||||
json(JSONOPTS),
|
||||
visualizer({
|
||||
filename: 'docs/statistics.html',
|
||||
sourcemap: true
|
||||
})
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
function onWarn(warning, warn) {
|
||||
// skip certain warnings
|
||||
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
|
||||
if (warning.code === 'EVAL') return;
|
||||
|
||||
// Use default for everything else
|
||||
console.log(colors.yellow(warning.code));
|
||||
warn(warning);
|
||||
}
|
||||
|
||||
|
||||
module.exports = buildSrc;
|
||||
|
||||
Reference in New Issue
Block a user