Skip to content

Commit

Permalink
Print gzipped filesize, address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
lvwrence authored and Lawrence Wu committed Jul 27, 2016
1 parent e2f4aa9 commit 52a8605
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"eslint-plugin-react": "5.2.2",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.9.0",
"filesize": "^3.3.0",
"fs-extra": "0.30.0",
"gzip-size": "^3.0.0",
"html-webpack-plugin": "2.22.0",
"json-loader": "0.5.4",
"opn": "4.0.2",
Expand Down
12 changes: 7 additions & 5 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

process.env.NODE_ENV = 'production';

var filesize = require('filesize');
var fs = require('fs');
var gzipSize = require('gzip-size');
var rimrafSync = require('rimraf').sync;
var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
Expand All @@ -22,8 +23,9 @@ rimrafSync(paths.appBuild + '/*');
function logBuildSize(assets, extension) {
for (var i = 0; i < assets.length; i++) {
var asset = assets[i];
if (asset['name'].endsWith(extension)) {
console.log('Size of ' + asset['name'] + ': ' + filesize(asset['size']));
if (asset.name.endsWith('.' + extension)) {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
console.log('Size (gzipped) of ' + asset.name + ': ' + gzipSize.sync(fileContents));
}
}
}
Expand Down Expand Up @@ -59,8 +61,8 @@ webpack(config).run(function(err, stats) {
console.log(' ' + openCommand + ' http://localhost:8080');
console.log();
var assets = stats.toJson()['assets'];
logBuildSize(assets, '.js');
logBuildSize(assets, '.css');
logBuildSize(assets, 'js');
logBuildSize(assets, 'css');
}
console.log('The bundle is optimized and ready to be deployed to production.');
});

0 comments on commit 52a8605

Please sign in to comment.