Merge pull request #385 from MartinHN/pr/hot_rebuild

use watchify to reduce re-build times
This commit is contained in:
jean-emmanuel 2018-10-16 09:51:42 +02:00 • committed by GitHub
commit cf71dd43e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 8 deletions

View file

@ -66,12 +66,16 @@
"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",
"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"
}
}

View file

@ -5,12 +5,18 @@ 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'],
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 (
@ -26,19 +32,40 @@ 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... ')
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(inputPath, {
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)})
}
b = b.bundle()
bundle()
if (!fast) b = b.pipe(exorcist(path.resolve(__dirname + '/../app/browser/scripts.js.map')))
function bundle() {
b.pipe(process.stdout)
var output = b.bundle()
if (!fast) output.pipe(exorcist(outputPath + '.map'))
output.pipe(fs.createWriteStream(outputPath))
}