Skip to content

Commit e2f4aa9

Browse files
lvwrenceLawrence Wu
authored and
Lawrence Wu
committed
Display JS and CSS bundle sizes after build
1 parent 6267992 commit e2f4aa9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"eslint-plugin-react": "5.2.2",
4949
"extract-text-webpack-plugin": "1.0.1",
5050
"file-loader": "0.9.0",
51+
"filesize": "^3.3.0",
5152
"fs-extra": "0.30.0",
5253
"html-webpack-plugin": "2.22.0",
5354
"json-loader": "0.5.4",

scripts/build.js

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

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

12+
var filesize = require('filesize');
1213
var rimrafSync = require('rimraf').sync;
1314
var webpack = require('webpack');
1415
var config = require('../config/webpack.config.prod');
@@ -18,6 +19,15 @@ var paths = require('../config/paths');
1819
// if you're in it, you don't end up in Trash
1920
rimrafSync(paths.appBuild + '/*');
2021

22+
function logBuildSize(assets, extension) {
23+
for (var i = 0; i < assets.length; i++) {
24+
var asset = assets[i];
25+
if (asset['name'].endsWith(extension)) {
26+
console.log('Size of ' + asset['name'] + ': ' + filesize(asset['size']));
27+
}
28+
}
29+
}
30+
2131
webpack(config).run(function(err, stats) {
2232
if (err) {
2333
console.error('Failed to create a production build. Reason:');
@@ -48,6 +58,9 @@ webpack(config).run(function(err, stats) {
4858
console.log(' hs');
4959
console.log(' ' + openCommand + ' http://localhost:8080');
5060
console.log();
61+
var assets = stats.toJson()['assets'];
62+
logBuildSize(assets, '.js');
63+
logBuildSize(assets, '.css');
5164
}
5265
console.log('The bundle is optimized and ready to be deployed to production.');
5366
});

0 commit comments

Comments
 (0)