diff --git a/package.json b/package.json index d75c3fc67f6d1c4ff9c9c955baf05dd860b60e29..81a9c733cc89566f99eabc6f493ebc9f7fbfae4d 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,9 @@ "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", diff --git a/scripts/build.js b/scripts/build.js index d92008154db559d90656b8dff13609fef75f3e70..7642ce3f41854b32692ff84a68ab849ab4b61f21 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -9,6 +9,9 @@ process.env.NODE_ENV = 'production'; +var fs = require('fs'); +var filesize = require('filesize'); +var gzipSize = require('gzip-size'); var rimrafSync = require('rimraf').sync; var webpack = require('webpack'); var config = require('../config/webpack.config.prod'); @@ -18,6 +21,16 @@ 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)) { + var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name); + console.log('Size (gzipped) of ' + asset.name + ': ' + filesize(gzipSize.sync(fileContents))); + } + } +} + webpack(config).run(function(err, stats) { if (err) { console.error('Failed to create a production build. Reason:'); @@ -48,6 +61,9 @@ webpack(config).run(function(err, stats) { console.log(' pushstate-server build'); console.log(' ' + openCommand + ' http://localhost:9000'); console.log(); + var assets = stats.toJson()['assets']; + logBuildSize(assets, 'js'); + logBuildSize(assets, 'css'); } console.log('The bundle is optimized and ready to be deployed to production.'); });