Skip to content

Commit 66c3f79

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): right align size column and add total bundle size
1 parent 814ea66 commit 66c3f79

File tree

1 file changed

+26
-6
lines changed
  • packages/angular_devkit/build_angular/src/webpack/utils

1 file changed

+26
-6
lines changed

packages/angular_devkit/build_angular/src/webpack/utils/stats.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function generateBundleStats(
5656
}
5757
}
5858

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

68+
let initialTotalSize = 0;
69+
6870
for (const { initial, stats } of data) {
6971
const [files, names, size] = stats;
70-
(initial ? changedEntryChunksStats : changedLazyChunksStats).push([
72+
73+
const data: BundleStatsData = [
7174
g(files),
7275
names,
73-
c(typeof size === 'string' ? size : formatSize(size)),
74-
]);
76+
c(typeof size === 'number' ? formatSize(size) : size),
77+
];
78+
79+
if (initial) {
80+
changedEntryChunksStats.push(data);
81+
82+
if (typeof size === 'number') {
83+
initialTotalSize += size;
84+
}
85+
86+
} else {
87+
changedLazyChunksStats.push(data);
88+
}
7589
}
7690

7791
const bundleInfo: (string | number)[][] = [];
@@ -82,6 +96,11 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean): string {
8296
['Initial Chunk Files', 'Names', 'Size'].map(bold),
8397
...changedEntryChunksStats,
8498
);
99+
100+
if (showTotalSize) {
101+
bundleInfo.push([]);
102+
bundleInfo.push([' ', 'Initial Total', formatSize(initialTotalSize)].map(bold));
103+
}
85104
}
86105

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

@@ -132,15 +152,15 @@ function statsToString(json: any, statsConfig: any, bundleState?: BundleStats[])
132152
if (a.stats[2] > b.stats[2]) {
133153
return -1;
134154
}
135-
155+
136156
if (a.stats[2] < b.stats[2]) {
137157
return 1;
138158
}
139159

140160
return 0;
141161
});
142162

143-
const statsTable = generateBuildStatsTable(changedChunksStats, colors);
163+
const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0);
144164

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

0 commit comments

Comments
 (0)