use watchify to reduce re-build times

This commit is contained in:
Martin Hermant 2018-10-15 12:12:31 +02:00
parent 6a1193d573
commit 94aaa644e2
No known key found for this signature in database
GPG key ID: FA123D713AB2A87C
2 changed files with 33 additions and 6 deletions

View file

@ -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)