From 94aaa644e2f27a784421cd9fc7dbef42c9fcaa7d Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Mon, 15 Oct 2018 12:12:31 +0200 Subject: [PATCH 1/3] use watchify to reduce re-build times --- package.json | 5 +++++ scripts/build-browser.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index af84e995..9e9b7683 100644 --- a/package.json +++ b/package.json @@ -68,10 +68,15 @@ "build-js": "npm run build-launcher-js && npm run build-browser-js", "build-browser-js": "node scripts/build-browser.js > app/browser/scripts.js", "build-launcher-js": "node scripts/build-launcher.js > app/launcher/scripts.js", + "watch-browser" : "node scripts/build-browser.js --watch", + "watch-launcher" : "node scripts/build-launcher.js --watch", "deploy-docs": "node scripts/build-widgets-reference.js > resources/docs/widgets-reference.md && cd resources && mkdocs gh-deploy --clean && rm -rf site", "test": "npm run build" }, "engines": { "node": ">=6" + }, + "devDependencies": { + "watchify": "^3.11.0" } } diff --git a/scripts/build-browser.js b/scripts/build-browser.js index c576c05e..51ce7930 100644 --- a/scripts/build-browser.js +++ b/scripts/build-browser.js @@ -5,9 +5,11 @@ var browserify = require('browserify'), licensify = require('licensify'), exorcist = require('exorcist'), path = require('path'), + fs = require('fs'), babelify = require('babelify'), prod = process.argv.indexOf('--prod') != -1, fast = process.argv.indexOf('--fast') != -1, + watch = process.argv.indexOf('--watch') != -1, b var ignoreList = ['**/*.min.js', '**/jquery.ui.js', '**/socket.io.slim.js'], @@ -28,17 +30,37 @@ var ignoreList = ['**/*.min.js', '**/jquery.ui.js', '**/socket.io.slim.js'], if (prod) console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... '); -b = browserify(path.resolve(__dirname + '/../src/browser/js/index.js'), {debug:!fast, insertGlobals:fast, noParse: ignoreList}) + +var plugins = [licensify] + +if(watch){plugins.push(require('watchify'))} + +b = browserify(path.resolve(__dirname + '/../src/browser/js/index.js'), + {debug:!fast, + insertGlobals:fast, + noParse: ignoreList, + cache: {},// needed by watchify + packageCache: {},// needed by watchify + plugin: plugins + }) b = b.transform(ignoreWrapper(babelify), {presets: ["env"]}) - if (prod) b = b.transform(ignoreWrapper(uglifyify), {global: true}) -b.plugin(licensify) +if(watch){ + b.on('update', bundle); + b.on('log', function (msg) {console.warn(msg);}) +} +bundle(); -b = b.bundle() +function bundle(){ + var bun = b.bundle() -if (!fast) b = b.pipe(exorcist(path.resolve(__dirname + '/../app/browser/scripts.js.map'))) + if (!fast) bun.pipe(exorcist(path.resolve(__dirname + '/../app/browser/scripts.js.map'))) + + if(watch){bun.pipe(fs.createWriteStream(path.resolve(__dirname + '/../app/browser/scripts.js')))} + else{ bun.pipe(process.stdout)} + +} -b.pipe(process.stdout) From 152a2666adef5820d4897a1d491da9b5c542bdc4 Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Mon, 15 Oct 2018 12:20:15 +0200 Subject: [PATCH 2/3] remove launcher not supported for now --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 9e9b7683..aad13a1b 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "build-browser-js": "node scripts/build-browser.js > app/browser/scripts.js", "build-launcher-js": "node scripts/build-launcher.js > app/launcher/scripts.js", "watch-browser" : "node scripts/build-browser.js --watch", - "watch-launcher" : "node scripts/build-launcher.js --watch", "deploy-docs": "node scripts/build-widgets-reference.js > resources/docs/widgets-reference.md && cd resources && mkdocs gh-deploy --clean && rm -rf site", "test": "npm run build" }, From aa6e19fbb7018c7cc1b9f16416c9206e4b9e3b39 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 16 Oct 2018 09:43:15 +0200 Subject: [PATCH 3/3] scripts: clean build-browser, always set output path from the script --- package.json | 4 ++-- scripts/build-browser.js | 45 ++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index aad13a1b..61800e15 100644 --- a/package.json +++ b/package.json @@ -66,9 +66,9 @@ "watch-js": "nodemon --watch src/browser/js -e js -x \"npm run build-js\"", "build-css": "node scripts/build-css.js", "build-js": "npm run build-launcher-js && npm run build-browser-js", - "build-browser-js": "node scripts/build-browser.js > app/browser/scripts.js", + "build-browser-js": "node scripts/build-browser.js", "build-launcher-js": "node scripts/build-launcher.js > app/launcher/scripts.js", - "watch-browser" : "node scripts/build-browser.js --watch", + "watch-browser": "node scripts/build-browser.js --watch", "deploy-docs": "node scripts/build-widgets-reference.js > resources/docs/widgets-reference.md && cd resources && mkdocs gh-deploy --clean && rm -rf site", "test": "npm run build" }, diff --git a/scripts/build-browser.js b/scripts/build-browser.js index 51ce7930..f0db3914 100644 --- a/scripts/build-browser.js +++ b/scripts/build-browser.js @@ -5,14 +5,18 @@ var browserify = require('browserify'), licensify = require('licensify'), exorcist = require('exorcist'), path = require('path'), - fs = require('fs'), + fs = require('fs'), babelify = require('babelify'), prod = process.argv.indexOf('--prod') != -1, fast = process.argv.indexOf('--fast') != -1, watch = process.argv.indexOf('--watch') != -1, b -var ignoreList = ['**/*.min.js', '**/jquery.ui.js', '**/socket.io.slim.js'], +var inputPath = path.resolve(__dirname + '/../src/browser/js/index.js'), + outputPath = path.resolve(__dirname + '/../app/browser/scripts.js') + + +var ignoreList = ['**/*.min.js', '**/jquery.ui.js'], ignoreWrapper = function(transform){ return function(file, opts){ if ( @@ -28,15 +32,15 @@ var ignoreList = ['**/*.min.js', '**/jquery.ui.js', '**/socket.io.slim.js'], } } -if (prod) console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... '); +if (prod) console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... ') var plugins = [licensify] -if(watch){plugins.push(require('watchify'))} +if (watch) plugins.push(require('watchify')) -b = browserify(path.resolve(__dirname + '/../src/browser/js/index.js'), - {debug:!fast, +b = browserify(inputPath, { + debug:!fast, insertGlobals:fast, noParse: ignoreList, cache: {},// needed by watchify @@ -45,22 +49,23 @@ b = browserify(path.resolve(__dirname + '/../src/browser/js/index.js'), }) b = b.transform(ignoreWrapper(babelify), {presets: ["env"]}) + if (prod) b = b.transform(ignoreWrapper(uglifyify), {global: true}) -if(watch){ - b.on('update', bundle); - b.on('log', function (msg) {console.warn(msg);}) -} -bundle(); - - -function bundle(){ - var bun = b.bundle() - - if (!fast) bun.pipe(exorcist(path.resolve(__dirname + '/../app/browser/scripts.js.map'))) - - if(watch){bun.pipe(fs.createWriteStream(path.resolve(__dirname + '/../app/browser/scripts.js')))} - else{ bun.pipe(process.stdout)} +if (watch) { + b.on('update', bundle) + b.on('log', function(msg) {console.warn(msg)}) } +bundle() + +function bundle() { + + var output = b.bundle() + + if (!fast) output.pipe(exorcist(outputPath + '.map')) + + output.pipe(fs.createWriteStream(outputPath)) + +}