Skip to content

Commit

Permalink
Display difference from the previous build in filesize (resolves face…
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Aug 2, 2016
1 parent 01eeb61 commit 4b5d48f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ var paths = require('../config/paths');
rimrafSync(paths.appBuild + '/*');

console.log('Creating an optimized production build...');
webpack(config).run(function(err, stats) {

var oldAssets;
var compiler = webpack(config, function(err, stats) {
oldAssets = stats.toJson().assets
.filter(asset => /\.(js|css)$/.test(asset.name))
.map(asset => {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
var size = gzipSize(fileContents);
return {
name: path.basename(asset.name),
size: size
};
});
});

compiler.run(function(err, stats) {
if (err) {
console.error('Failed to create a production build. Reason:');
console.error(err.message || err);
Expand All @@ -41,11 +56,27 @@ webpack(config).run(function(err, stats) {
.map(asset => {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
var size = gzipSize(fileContents);
var sizeDiffLabel = '';

for (var i = oldAssets.length - 1; i >= 0; --i) {
var oldAsset = oldAssets[i];
if (oldAsset.name === asset.name) {
var sizeDiff = asset.size - oldAsset.size;
if (sizeDiff !== 0) {
sizeDiffLabel = ' (' +
(sizeDiff < 0 ? '-' : '+') +
filesize(Math.abs(sizeDiff)) +
')';
}
break;
}
}

return {
folder: path.join('build', path.dirname(asset.name)),
name: path.basename(asset.name),
size: size,
sizeLabel: filesize(size)
sizeLabel: filesize(size) + sizeDiffLabel
};
});
assets.sort((a, b) => b.size - a.size);
Expand Down

0 comments on commit 4b5d48f

Please sign in to comment.