diff --git a/build.js b/build.js index 373b77f05..2e18d46fb 100644 --- a/build.js +++ b/build.js @@ -12,10 +12,11 @@ function buildAll() { if (_currBuild) return _currBuild; return _currBuild = - Promise.all([buildCSS(), buildBundle()]) - .then(() => { - _currBuild = null; - }) + Promise.resolve() + .then(() => buildCSS()) + .then(() => buildData()) + .then(() => buildSrc()) + .then(() => _currBuild = null) .catch((err) => { console.error(err); _currBuild = null; @@ -23,10 +24,4 @@ function buildAll() { }); }; - -function buildBundle() { - return buildData() - .then(() => buildSrc()); -} - module.exports = buildAll; diff --git a/build_css.js b/build_css.js index b1fcd27a8..ab6e80bc0 100644 --- a/build_css.js +++ b/build_css.js @@ -5,9 +5,6 @@ const glob = require('glob'); let _currBuild = null; -// if called directly, do the thing. -buildCSS(); - function buildCSS() { if (_currBuild) return _currBuild; @@ -20,7 +17,8 @@ function buildCSS() { console.time(END); return _currBuild = - doGlob('css/**/*.css') + Promise.resolve() + .then(() => doGlob('css/**/*.css')) .then((files) => doConcat(files, 'dist/iD.css')) .then(() => { console.timeEnd(END); diff --git a/build_data.js b/build_data.js index 8a53f71cb..edd47ee4a 100644 --- a/build_data.js +++ b/build_data.js @@ -22,12 +22,8 @@ fontawesome.library.add(fas, far, fab); const request = require('request').defaults({ maxSockets: 1 }); - let _currBuild = null; -// if called directly, do the thing. -buildData(); - function buildData() { if (_currBuild) return _currBuild; diff --git a/build_src.js b/build_src.js index ab002550c..c806365f2 100644 --- a/build_src.js +++ b/build_src.js @@ -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; diff --git a/package.json b/package.json index b109b3ecb..f420d0fc5 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "ISC", "scripts": { "all": "npm-run-all -s clean build dist", - "build": "node build.js", + "build": "node --max-old-space-size=4096 build.js", "clean": "shx rm -f dist/*.js dist/*.map dist/*.css dist/img/*.svg", "dist": "npm-run-all -p dist:**", "dist:mapillary": "shx mkdir -p dist/mapillary-js && shx cp -R node_modules/mapillary-js/dist/* dist/mapillary-js/", @@ -27,7 +27,7 @@ "dist:svg:temaki": "svg-sprite --symbol --symbol-dest . --shape-id-generator \"temaki-%s\" --symbol-sprite dist/img/temaki-sprite.svg node_modules/temaki/icons/*.svg", "imagery": "node data/update_imagery", "lint": "eslint *.js test/spec modules", - "start": "node server.js", + "start": "node --max-old-space-size=4096 server.js", "phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/phantom.html spec", "test": "npm-run-all -s lint build test:**", "test:phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec",