Commit ca7d227a authored by Lawrence Wu's avatar Lawrence Wu Committed by Dan Abramov
Browse files

Display JS and CSS bundle sizes after build (#229)

* Display JS and CSS bundle sizes after build

* Print gzipped filesize, address nits

* Use filesize for human readable output.
parent a9d1106e
No related merge requests found
Showing with 18 additions and 0 deletions
+18 -0
......@@ -9,6 +9,9 @@
process.env.NODE_ENV = 'production';
var fs = require('fs');
var filesize = require('filesize');
var gzipSize = require('gzip-size');
var rimrafSync = require('rimraf').sync;
var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
......@@ -18,6 +21,16 @@ var paths = require('../config/paths');
// if you're in it, you don't end up in Trash
rimrafSync(paths.appBuild + '/*');
function logBuildSize(assets, extension) {
for (var i = 0; i < assets.length; i++) {
var asset = assets[i];
if (asset.name.endsWith('.' + extension)) {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
console.log('Size (gzipped) of ' + asset.name + ': ' + filesize(gzipSize.sync(fileContents)));
}
}
}
webpack(config).run(function(err, stats) {
if (err) {
console.error('Failed to create a production build. Reason:');
......@@ -48,6 +61,9 @@ webpack(config).run(function(err, stats) {
console.log(' pushstate-server build');
console.log(' ' + openCommand + ' http://localhost:9000');
console.log();
var assets = stats.toJson()['assets'];
logBuildSize(assets, 'js');
logBuildSize(assets, 'css');
}
console.log('The bundle is optimized and ready to be deployed to production.');
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment