Skip to content

Commit 0d439a0

Browse files
committed
feat(@angular-devkit/build-webpack): add option for webpack stats output presence
The Webpack `Stats.toJson` function can be expensive. A new programmatic option is now available (`shouldProvideStats`) which can be used to control whether the `webpackStats` property on the builder output object is present. For backwards compatibility, the option is currently enabled by default.
1 parent 5746ae5 commit 0d439a0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • packages/angular_devkit/build_webpack/src/webpack

packages/angular_devkit/build_webpack/src/webpack/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ export function runWebpack(
3434
options: {
3535
logging?: WebpackLoggingCallback,
3636
webpackFactory?: WebpackFactory,
37+
shouldProvideStats?: boolean,
3738
} = {},
3839
): Observable<BuildResult> {
40+
const {
41+
logging: log = (stats, config) => context.logger.info(stats.toString(config.stats)),
42+
shouldProvideStats = true,
43+
} = options;
3944
const createWebpack = (c: webpack.Configuration) => {
4045
if (options.webpackFactory) {
4146
const result = options.webpackFactory(c);
@@ -48,8 +53,6 @@ export function runWebpack(
4853
return of(webpack(c));
4954
}
5055
};
51-
const log: WebpackLoggingCallback = options.logging
52-
|| ((stats, config) => context.logger.info(stats.toString(config.stats)));
5356

5457
return createWebpack({ ...config, watch: false }).pipe(
5558
switchMap(webpackCompiler => new Observable<BuildResult>(obs => {
@@ -72,7 +75,7 @@ export function runWebpack(
7275

7376
obs.next({
7477
success: !stats.hasErrors(),
75-
webpackStats: stats.toJson(),
78+
webpackStats: shouldProvideStats ? stats.toJson() : undefined,
7679
emittedFiles: getEmittedFiles(stats.compilation),
7780
} as unknown as BuildResult);
7881

0 commit comments

Comments
 (0)