Skip to content

Commit 5abb25b

Browse files
authored
perf: reduce stats.hasErrors() calls (#6305)
1 parent 6cff60c commit 5abb25b

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

packages/compat/webpack/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const build = async (
5252
compiler.run((err, stats) => {
5353
if (err) {
5454
reject(err);
55-
} else if (stats?.hasErrors()) {
55+
} else if (context.buildState.hasErrors) {
5656
reject(new Error('webpack build failed.'));
5757
}
5858
// If there is a compilation error, the close method should not be called.

packages/core/src/createRsbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function applyDefaultPlugins(
8282
pluginTarget(),
8383
pluginOutput(),
8484
pluginResolve(),
85-
pluginFileSize(),
85+
pluginFileSize(context),
8686
// cleanOutput plugin should before the html plugin
8787
pluginCleanOutput(),
8888
pluginAsset(),

packages/core/src/plugins/fileSize.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { JS_REGEX } from '../constants';
1010
import { color, getAssetsFromStats } from '../helpers';
1111
import { logger } from '../logger';
1212
import type {
13+
InternalContext,
1314
PrintFileSizeAsset,
1415
PrintFileSizeOptions,
1516
RsbuildPlugin,
@@ -284,13 +285,13 @@ async function printFileSizes(
284285
return logs;
285286
}
286287

287-
export const pluginFileSize = (): RsbuildPlugin => ({
288+
export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
288289
name: 'rsbuild:file-size',
289290

290291
setup(api) {
291292
api.onAfterBuild(async ({ stats, environments, isFirstCompile }) => {
292293
// No need to print file sizes if there is any compilation error
293-
if (!stats || stats.hasErrors() || !isFirstCompile) {
294+
if (!stats || context.buildState.hasErrors || !isFirstCompile) {
294295
return;
295296
}
296297

packages/core/src/provider/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const build = async (
7070

7171
if (err) {
7272
reject(err);
73-
} else if (stats?.hasErrors()) {
73+
} else if (context.buildState.hasErrors) {
7474
reject(new Error(RSPACK_BUILD_ERROR));
7575
} else {
7676
resolve({ stats });

0 commit comments

Comments
 (0)