Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display JS and CSS bundle sizes after build #229

Merged
merged 3 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Print gzipped filesize, address nits
  • Loading branch information
lvwrence authored and Lawrence Wu committed Jul 27, 2016
commit 52a8605373dd6c23b8ce5da842d70f75ab686491
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.');
});