From 52a8605373dd6c23b8ce5da842d70f75ab686491 Mon Sep 17 00:00:00 2001 From: Lawrence Wu Date: Wed, 27 Jul 2016 13:31:47 -0700 Subject: [PATCH] Print gzipped filesize, address nits --- package.json | 2 +- scripts/build.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e6f5eb6921f..eeaf2232586 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/build.js b/scripts/build.js index 03eb8acd61c..f657309deb7 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -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'); @@ -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)); } } } @@ -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.'); });