Skip to content

Commit

Permalink
chore(bundlereport): small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVinke committed Mar 4, 2018
1 parent 5e19eec commit 3bfd735
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,12 @@ exports.Bundle = class {

console.log(`Writing ${bundleFileName}...`);

if (buildOptions.bundleReport) {
if (buildOptions.isApplicable('bundleReport')) {
let sbuffer = [];
let jsonRep = {};

sbuffer.push('>> ' + bundleFileName + ' total size : ' + (contents.length / 1024).toFixed(2) + 'kb, containing ' + files.length + ' files');
let sortedFiles = files.sort(function (a, b) {
let sortedFiles = files.sort((a, b) => {
if (a.contents.length > b.contents.length) {
return -1;
}
Expand All @@ -276,9 +277,17 @@ exports.Bundle = class {
});
for (let i = 0; i < sortedFiles.length; ++i) {
let currentFile = sortedFiles[i];
sbuffer.push(' > ' + (currentFile.contents.length / 1024).toFixed(2) + 'kb ('+ ((currentFile.contents.length / contents.length) * 100).toFixed(2)+'%) - ' + currentFile.path );
sbuffer.push('> ' + (currentFile.contents.length / 1024).toFixed(2) + 'kb (' + ((currentFile.contents.length / contents.length) * 100).toFixed(2) + '%) - ' + (currentFile.path || currentFile.contents.substring(0, 200)));
if (currentFile.path) {
jsonRep[currentFile.path] = jsonRep[currentFile.path] || {};
jsonRep[currentFile.path].file = currentFile.path;
jsonRep[currentFile.path].filesize = (currentFile.contents.length / 1024).toFixed(2);
}
}
fs.writeFile('bundle-report-' + bundleFileName + '.txt', sbuffer.join('\n'));

logger.info(`Writing bundle reports for ${bundleFileName}...`);
fs.writeFile(`bundle-report-${bundleFileName}.txt`, sbuffer.join('\n'));
fs.writeFile(`bundle-report-${bundleFileName}.json`, JSON.stringify(jsonRep, null, 2));
}

if (buildOptions.isApplicable('minify')) {
Expand Down

0 comments on commit 3bfd735

Please sign in to comment.