Skip to content

Commit ca7d227

Browse files
lvwrencegaearon
authored andcommitted
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.
1 parent a9d1106 commit ca7d227

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"eslint-plugin-react": "5.2.2",
5353
"extract-text-webpack-plugin": "1.0.1",
5454
"file-loader": "0.9.0",
55+
"filesize": "^3.3.0",
5556
"fs-extra": "0.30.0",
57+
"gzip-size": "^3.0.0",
5658
"html-webpack-plugin": "2.22.0",
5759
"json-loader": "0.5.4",
5860
"opn": "4.0.2",

scripts/build.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
process.env.NODE_ENV = 'production';
1111

12+
var fs = require('fs');
13+
var filesize = require('filesize');
14+
var gzipSize = require('gzip-size');
1215
var rimrafSync = require('rimraf').sync;
1316
var webpack = require('webpack');
1417
var config = require('../config/webpack.config.prod');
@@ -18,6 +21,16 @@ var paths = require('../config/paths');
1821
// if you're in it, you don't end up in Trash
1922
rimrafSync(paths.appBuild + '/*');
2023

24+
function logBuildSize(assets, extension) {
25+
for (var i = 0; i < assets.length; i++) {
26+
var asset = assets[i];
27+
if (asset.name.endsWith('.' + extension)) {
28+
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
29+
console.log('Size (gzipped) of ' + asset.name + ': ' + filesize(gzipSize.sync(fileContents)));
30+
}
31+
}
32+
}
33+
2134
webpack(config).run(function(err, stats) {
2235
if (err) {
2336
console.error('Failed to create a production build. Reason:');
@@ -48,6 +61,9 @@ webpack(config).run(function(err, stats) {
4861
console.log(' pushstate-server build');
4962
console.log(' ' + openCommand + ' http://localhost:9000');
5063
console.log();
64+
var assets = stats.toJson()['assets'];
65+
logBuildSize(assets, 'js');
66+
logBuildSize(assets, 'css');
5167
}
5268
console.log('The bundle is optimized and ready to be deployed to production.');
5369
});

0 commit comments

Comments
 (0)