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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"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",
"html-webpack-plugin": "2.22.0",
"json-loader": "0.5.4",
Expand Down
13 changes: 13 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

process.env.NODE_ENV = 'production';

var filesize = require('filesize');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want gzip-size, actually.

Copy link
Contributor Author

@lvwrence lvwrence Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that the assets have already been gzipped, so I just needed to print out their filesizes? If that's not the case, does this mean we have to read every file to get their estimated gzipped size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I get it now. Gonna get some food and come back to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using gzip-size now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we probably still want filesize for human readable file sizes.

var rimrafSync = require('rimraf').sync;
var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
Expand All @@ -18,6 +19,15 @@ 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)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sup @lvwrence
nit: access the props using dot notation asset.name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol hey! what a coincidence seeing you here. done!

console.log('Size of ' + asset['name'] + ': ' + filesize(asset['size']));
}
}
}

webpack(config).run(function(err, stats) {
if (err) {
console.error('Failed to create a production build. Reason:');
Expand Down Expand Up @@ -48,6 +58,9 @@ webpack(config).run(function(err, stats) {
console.log(' hs');
console.log(' ' + openCommand + ' http://localhost:8080');
console.log();
var assets = stats.toJson()['assets'];
logBuildSize(assets, '.js');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass dot free extensions and prepend the dot in logBuildSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

logBuildSize(assets, '.css');
}
console.log('The bundle is optimized and ready to be deployed to production.');
});