Skip to content

Commit

Permalink
Sort list of output files by size within a group
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 5, 2021
1 parent 24dc655 commit b072d94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-roses-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

Sort list of outputted files by size within a group
15 changes: 13 additions & 2 deletions packages/wmr/src/lib/output-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ export function bundleStats(bundle, outDir) {
let total = 0;
const assets = bundle.output
.filter(asset => !/\.map$/.test(asset.fileName))
.sort((a, b) => scoreAsset(b) - scoreAsset(a));
.sort((a, b) => {
const scoreB = scoreAsset(b);
const scoreA = scoreAsset(a);

if (scoreA === scoreB) {
const contentA = a.type === 'asset' ? a.source : a.code;
const contentB = b.type === 'asset' ? b.source : b.code;
return contentB.length - contentA.length;
}

return scoreB - scoreA;
});

let nonCssAsset = false;
const assetsText = assets.reduce((str, output) => {
Expand Down Expand Up @@ -55,7 +66,7 @@ function scoreAsset(asset) {
}
// ...then CSS files
else if (/\.css$/.test(asset.fileName)) {
return 10;
return 9;
}

// ...and everything else after that
Expand Down

0 comments on commit b072d94

Please sign in to comment.