scripts: clean build-browser, always set output path from the script
This commit is contained in:
parent
4d44b45b79
commit
f2a3e12c90
2 changed files with 27 additions and 22 deletions
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue