Just make the build steps sequential, build single target with buble

This commit is contained in:
Bryan Housel
2019-11-07 17:03:15 -05:00
parent 4a07ae7243
commit 5da962a694
5 changed files with 37 additions and 108 deletions
+28 -88
View File
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
const buble = require('@rollup/plugin-buble');
const colors = require('colors/safe');
const commonjs = require('rollup-plugin-commonjs');
const includePaths = require('rollup-plugin-includepaths');
@@ -6,45 +7,24 @@ 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();
function buildSrc() {
if (_currBuild) return _currBuild;
const START = '🏗 ' + colors.yellow('Building bundles...');
const END = '👍 ' + colors.green('bundles built');
const START = '🏗 ' + colors.yellow('Building source...');
const END = '👍 ' + colors.green('source built');
console.log('');
console.log(START);
console.time(END);
return _currBuild =
buildModern()
// .then(() => buildES5())
Promise.resolve()
.then(() => buildBundle())
.then(() => {
console.timeEnd(END);
console.log('');
@@ -59,13 +39,14 @@ function buildSrc() {
};
function buildModern() {
console.log('📦 ' + colors.yellow('Bundling modern JavaScript...'));
function buildBundle() {
console.log('📦 ' + colors.yellow('Bundling JavaScript...'));
// Start clean
shell.rm('-f', [
'dist/iD.js',
'dist/iD.js.map'
'dist/iD.js.map',
// 'docs/statistics.html'
]);
let prom =
@@ -73,10 +54,25 @@ function buildModern() {
input: './modules/id.js',
onwarn: onWarn,
plugins: [
includePaths(INCLUDEPATHSOPTS),
nodeResolve(NODERESOLVEOPTS),
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']
}),
commonjs(),
json(JSONOPTS)
json({ indent: '' }),
buble(),
// viz causes src build to take about 3x longer; skip
// visualizer({
// filename: 'docs/statistics.html',
// sourcemap: true
// })
]
})
.then((bundle) => {
@@ -92,62 +88,6 @@ function buildModern() {
};
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;