Skip to content

Commit

Permalink
feat(@angular-devkit/build-webpack): add option for webpack stats out…
Browse files Browse the repository at this point in the history
…put 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.
  • Loading branch information
clydin committed Dec 3, 2020
1 parent 5746ae5 commit 0d439a0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/angular_devkit/build_webpack/src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ export function runWebpack(
options: {
logging?: WebpackLoggingCallback,
webpackFactory?: WebpackFactory,
shouldProvideStats?: boolean,
} = {},
): Observable<BuildResult> {
const {
logging: log = (stats, config) => context.logger.info(stats.toString(config.stats)),
shouldProvideStats = true,
} = options;
const createWebpack = (c: webpack.Configuration) => {
if (options.webpackFactory) {
const result = options.webpackFactory(c);
Expand All @@ -48,8 +53,6 @@ export function runWebpack(
return of(webpack(c));
}
};
const log: WebpackLoggingCallback = options.logging
|| ((stats, config) => context.logger.info(stats.toString(config.stats)));

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

obs.next({
success: !stats.hasErrors(),
webpackStats: stats.toJson(),
webpackStats: shouldProvideStats ? stats.toJson() : undefined,
emittedFiles: getEmittedFiles(stats.compilation),
} as unknown as BuildResult);

Expand Down

0 comments on commit 0d439a0

Please sign in to comment.