client/build: always compress vendor JS

This commit is contained in:
rr- 2016-05-14 14:47:36 +02:00
parent 914bee4c64
commit e6be94d139
1 changed files with 9 additions and 7 deletions

View File

@ -103,12 +103,12 @@ function bundleCss() {
}); });
} }
function writeJsBundle(b, path, message) { function writeJsBundle(b, path, message, compress) {
const uglifyjs = require('uglify-js'); const uglifyjs = require('uglify-js');
let outputFile = fs.createWriteStream(path); let outputFile = fs.createWriteStream(path);
b.bundle().pipe(outputFile); b.bundle().pipe(outputFile);
outputFile.on('finish', function() { outputFile.on('finish', function() {
if (!config.debug) { if (compress) {
const result = uglifyjs.minify(path); const result = uglifyjs.minify(path);
fs.writeFileSync(path, result.code); fs.writeFileSync(path, result.code);
} }
@ -134,7 +134,8 @@ function bundleJs(config) {
for (let lib of external) { for (let lib of external) {
b.require(lib); b.require(lib);
} }
writeJsBundle(b, './public/vendor.min.js', 'Bundled vendor JS'); writeJsBundle(
b, './public/vendor.min.js', 'Bundled vendor JS', true);
} }
{ {
@ -143,10 +144,11 @@ function bundleJs(config) {
if (config.transpile) { if (config.transpile) {
b = b.transform(babelify); b = b.transform(babelify);
} }
b.external(external); writeJsBundle(
b.on('dep', dep => { console.log(dep.file); }); b.external(external).add(files),
b.add(files); './public/app.min.js',
writeJsBundle(b, './public/app.min.js', 'Bundled app JS'); 'Bundled app JS',
!config.debug);
} }
}); });
} }