From 914bee4c640100572a664254837467237d1d0ab6 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 14 May 2016 13:50:39 +0200 Subject: [PATCH] client/build: compile vendor packages separately --- client/build.js | 57 +++++++++++++++++++++++++++++++------------ client/html/index.htm | 5 ++-- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/client/build.js b/client/build.js index a1eac06..d49a502 100644 --- a/client/build.js +++ b/client/build.js @@ -98,29 +98,56 @@ function bundleCss() { css += stylus.render( fs.readFileSync(file, 'utf-8'), {filename: file}); } - fs.writeFileSync('./public/bundle.min.css', minify(css)); + fs.writeFileSync('./public/app.min.css', minify(css)); console.info('Bundled CSS'); }); } +function writeJsBundle(b, path, message) { + const uglifyjs = require('uglify-js'); + let outputFile = fs.createWriteStream(path); + b.bundle().pipe(outputFile); + outputFile.on('finish', function() { + if (!config.debug) { + const result = uglifyjs.minify(path); + fs.writeFileSync(path, result.code); + } + console.info(message); + }); +} + function bundleJs(config) { const babelify = require('babelify'); const browserify = require('browserify'); - const uglifyjs = require('uglify-js'); - glob('./js/**/*.js', {}, function(er, files) { - const outputFile = fs.createWriteStream('./public/bundle.min.js'); - let b = browserify({debug: config.debug}); - if (config.transpile) { - b = b.transform(babelify); - } - b.add(files).bundle().pipe(outputFile); - outputFile.on('finish', function() { - if (!config.debug) { - const result = uglifyjs.minify('./public/bundle.min.js'); - fs.writeFileSync('./public/bundle.min.js', result.code); + const external = [ + 'lodash', + 'superagent', + 'mousetrap', + 'js-cookie', + 'page', + 'nprogress', + 'babel-polyfill', + ]; + glob('./js/**/*.js', {}, (er, files) => { + { + let b = browserify(); + for (let lib of external) { + b.require(lib); } - console.info('Bundled JS'); - }); + writeJsBundle(b, './public/vendor.min.js', 'Bundled vendor JS'); + } + + { + let outputFile = fs.createWriteStream('./public/app.min.js'); + let b = browserify({debug: config.debug}); + if (config.transpile) { + b = b.transform(babelify); + } + b.external(external); + b.on('dep', dep => { console.log(dep.file); }); + b.add(files); + writeJsBundle(b, './public/app.min.js', 'Bundled app JS'); + } }); } diff --git a/client/html/index.htm b/client/html/index.htm index dbbd34a..b2aeea9 100644 --- a/client/html/index.htm +++ b/client/html/index.htm @@ -4,7 +4,7 @@ <!-- confiured in config file --> - + @@ -12,6 +12,7 @@
- + +