From 4a07ae7243a30f8cdd8b72d077bfbb54801255fa Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 7 Nov 2019 12:52:41 -0500 Subject: [PATCH] Testing out multiple build targets in build_src.. Also silence warnings - closes #4120 --- build_src.js | 144 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 113 insertions(+), 31 deletions(-) diff --git a/build_src.js b/build_src.js index fdefa486f..ab002550c 100644 --- a/build_src.js +++ b/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;