Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): right align size column and add t…
Browse files Browse the repository at this point in the history
…otal bundle size
  • Loading branch information
alan-agius4 authored and filipesilva committed Nov 3, 2020
1 parent 197d73d commit 50e830d
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions packages/angular_devkit/build_angular/src/webpack/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function generateBundleStats(
}
}

function generateBuildStatsTable(data: BundleStats[], colors: boolean): string {
function generateBuildStatsTable(data: BundleStats[], colors: boolean, showTotalSize: boolean): string {
const g = (x: string) => colors ? ansiColors.greenBright(x) : x;
const c = (x: string) => colors ? ansiColors.cyanBright(x) : x;
const bold = (x: string) => colors ? ansiColors.bold(x) : x;
Expand All @@ -65,13 +65,27 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean): string {
const changedEntryChunksStats: BundleStatsData[] = [];
const changedLazyChunksStats: BundleStatsData[] = [];

let initialTotalSize = 0;

for (const { initial, stats } of data) {
const [files, names, size] = stats;
(initial ? changedEntryChunksStats : changedLazyChunksStats).push([

const data: BundleStatsData = [
g(files),
names,
c(typeof size === 'string' ? size : formatSize(size)),
]);
c(typeof size === 'number' ? formatSize(size) : size),
];

if (initial) {
changedEntryChunksStats.push(data);

if (typeof size === 'number') {
initialTotalSize += size;
}

} else {
changedLazyChunksStats.push(data);
}
}

const bundleInfo: (string | number)[][] = [];
Expand All @@ -82,6 +96,11 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean): string {
['Initial Chunk Files', 'Names', 'Size'].map(bold),
...changedEntryChunksStats,
);

if (showTotalSize) {
bundleInfo.push([]);
bundleInfo.push([' ', 'Initial Total', formatSize(initialTotalSize)].map(bold));
}
}

// Seperator
Expand All @@ -100,6 +119,7 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean): string {
return textTable(bundleInfo, {
hsep: dim(' | '),
stringLength: s => removeColor(s).length,
align: ['l', 'l', 'r'],
});
}

Expand Down Expand Up @@ -132,15 +152,15 @@ function statsToString(json: any, statsConfig: any, bundleState?: BundleStats[])
if (a.stats[2] > b.stats[2]) {
return -1;
}

if (a.stats[2] < b.stats[2]) {
return 1;
}

return 0;
});

const statsTable = generateBuildStatsTable(changedChunksStats, colors);
const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0);

// In some cases we do things outside of webpack context
// Such us index generation, service worker augmentation etc...
Expand Down

0 comments on commit 50e830d

Please sign in to comment.