Skip to content

Commit 8e57db6

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): show lazy files in stat table correctly with esbuild
When using the esbuild-based browser application builder, the output build file stat table was incorrectly displaying non-injected global styles and scripts as initial files. These output files will now be correctly shown as lazy files. Initial files will also now display their respective name if available. The table entries are now sorted in descending order by raw file size as was done in the Webpack-based builder.
1 parent 2b937db commit 8e57db6

File tree

2 files changed

+20
-19
lines changed
  • packages/angular_devkit/build_angular/src

2 files changed

+20
-19
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ async function execute(
278278
}
279279
}
280280

281-
logBuildStats(context, metafile);
281+
logBuildStats(context, metafile, initialFiles);
282282

283283
const buildTime = Number(process.hrtime.bigint() - startTime) / 10 ** 9;
284284
context.logger.info(`Complete. [${buildTime.toFixed(3)} seconds]`);
@@ -723,11 +723,12 @@ export async function* buildEsbuildBrowser(
723723

724724
export default createBuilder(buildEsbuildBrowser);
725725

726-
function logBuildStats(context: BuilderContext, metafile: Metafile) {
726+
function logBuildStats(context: BuilderContext, metafile: Metafile, initialFiles: FileInfo[]) {
727+
const initial = new Map(initialFiles.map((info) => [info.file, info.name]));
727728
const stats: BundleStats[] = [];
728729
for (const [file, output] of Object.entries(metafile.outputs)) {
729-
// Skip sourcemaps
730-
if (file.endsWith('.map')) {
730+
// Only display JavaScript and CSS files
731+
if (!file.endsWith('.js') && !file.endsWith('.css')) {
731732
continue;
732733
}
733734
// Skip internal component resources
@@ -737,8 +738,8 @@ function logBuildStats(context: BuilderContext, metafile: Metafile) {
737738
}
738739

739740
stats.push({
740-
initial: !!output.entryPoint,
741-
stats: [file, '', output.bytes, ''],
741+
initial: initial.has(file),
742+
stats: [file, initial.get(file) ?? '', output.bytes, ''],
742743
});
743744
}
744745

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ export function generateBuildStatsTable(
119119
}
120120
}
121121

122+
// Sort descending by raw size
123+
data.sort((a, b) => {
124+
if (a.stats[2] > b.stats[2]) {
125+
return -1;
126+
}
127+
128+
if (a.stats[2] < b.stats[2]) {
129+
return 1;
130+
}
131+
132+
return 0;
133+
});
134+
122135
for (const { initial, stats } of data) {
123136
const [files, names, rawSize, estimatedTransferSize] = stats;
124137
const getRawSizeColor = getSizeColor(names, files);
@@ -274,19 +287,6 @@ function statsToString(
274287

275288
runsCache.add(json.outputPath || '');
276289

277-
// Sort chunks by size in descending order
278-
changedChunksStats.sort((a, b) => {
279-
if (a.stats[2] > b.stats[2]) {
280-
return -1;
281-
}
282-
283-
if (a.stats[2] < b.stats[2]) {
284-
return 1;
285-
}
286-
287-
return 0;
288-
});
289-
290290
const statsTable = generateBuildStatsTable(
291291
changedChunksStats,
292292
colors,

0 commit comments

Comments
 (0)