Skip to content

Commit afb735f

Browse files
authored
fix(builder): failed to print file size in some cases (#3676)
1 parent 06d7dfb commit afb735f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/curvy-mails-provide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/builder-shared': patch
3+
'@modern-js/builder': patch
4+
---
5+
6+
fix(builder): failed to print file size in some cases
7+
8+
fix(builder): 修复部分情况下输出产物体积失败的问题

packages/builder/builder-shared/src/types/stats.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface StatsOptionsObj {
1212
colors?: boolean;
1313

1414
/** Rspack not support below opts */
15+
cachedAssets?: boolean;
1516
groupAssetsByInfo?: boolean;
1617
groupAssetsByPath?: boolean;
1718
groupAssetsByChunk?: boolean;

packages/builder/builder/src/plugins/fileSize.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async function printFileSizes(stats: Stats | MultiStats, distPath: string) {
6969
const origin = stats.toJson({
7070
all: false,
7171
assets: true,
72+
cachedAssets: true,
7273
groupAssetsByInfo: false,
7374
groupAssetsByPath: false,
7475
groupAssetsByChunk: false,
@@ -146,7 +147,12 @@ export const builderPluginFileSize = (): DefaultBuilderPlugin => ({
146147
const config = api.getNormalizedConfig();
147148

148149
if (config.performance.printFileSize && stats) {
149-
await printFileSizes(stats, api.context.distPath);
150+
try {
151+
await printFileSizes(stats, api.context.distPath);
152+
} catch (err) {
153+
logger.error('Failed to print file size.');
154+
logger.error(err as Error);
155+
}
150156
}
151157
});
152158
},

0 commit comments

Comments
 (0)