client/build: compile vendor packages separately
This commit is contained in:
parent
2cba1a432f
commit
914bee4c64
|
@ -98,29 +98,56 @@ function bundleCss() {
|
||||||
css += stylus.render(
|
css += stylus.render(
|
||||||
fs.readFileSync(file, 'utf-8'), {filename: file});
|
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');
|
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) {
|
function bundleJs(config) {
|
||||||
const babelify = require('babelify');
|
const babelify = require('babelify');
|
||||||
const browserify = require('browserify');
|
const browserify = require('browserify');
|
||||||
const uglifyjs = require('uglify-js');
|
const external = [
|
||||||
glob('./js/**/*.js', {}, function(er, files) {
|
'lodash',
|
||||||
const outputFile = fs.createWriteStream('./public/bundle.min.js');
|
'superagent',
|
||||||
let b = browserify({debug: config.debug});
|
'mousetrap',
|
||||||
if (config.transpile) {
|
'js-cookie',
|
||||||
b = b.transform(babelify);
|
'page',
|
||||||
}
|
'nprogress',
|
||||||
b.add(files).bundle().pipe(outputFile);
|
'babel-polyfill',
|
||||||
outputFile.on('finish', function() {
|
];
|
||||||
if (!config.debug) {
|
glob('./js/**/*.js', {}, (er, files) => {
|
||||||
const result = uglifyjs.minify('./public/bundle.min.js');
|
{
|
||||||
fs.writeFileSync('./public/bundle.min.js', result.code);
|
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');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset='utf-8'/>
|
<meta charset='utf-8'/>
|
||||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
<title><!-- confiured in config file --></title>
|
<title><!-- confiured in config file --></title>
|
||||||
<link href='/bundle.min.css' rel='stylesheet' type='text/css'/>
|
<link href='/app.min.css' rel='stylesheet' type='text/css'/>
|
||||||
<link href='//maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css' rel='stylesheet' type='text/css'/>
|
<link href='//maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css' rel='stylesheet' type='text/css'/>
|
||||||
<link href='//fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'/>
|
<link href='//fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'/>
|
||||||
<link rel='shortcut icon' type='image/png' href='/favicon.png'/>
|
<link rel='shortcut icon' type='image/png' href='/favicon.png'/>
|
||||||
|
@ -12,6 +12,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id='top-nav-holder'></div>
|
<div id='top-nav-holder'></div>
|
||||||
<div id='content-holder'></div>
|
<div id='content-holder'></div>
|
||||||
<script type='text/javascript' src='/bundle.min.js'></script>
|
<script type='text/javascript' src='/vendor.min.js'></script>
|
||||||
|
<script type='text/javascript' src='/app.min.js'></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue