From 023d0937c44f94e297aa0980cb05e9c52d3d0045 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 1 Jun 2021 17:55:40 +0200 Subject: [PATCH] perf(@angular-devkit/build-webpack): include only required stats in webpackStats Until we depend on `webpackStats` in the browser builder we should only included the required stats. The below are the needed stats; ``` all: false, colors: true, hash: true, timings: true, chunks: true, builtAt: true, warnings: true, errors: true, assets: true, ids: true, entrypoints: true, ``` --- .../src/webpack/configs/stats.ts | 14 +++++-------- .../build_webpack/src/webpack/index.ts | 21 +++++++------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/stats.ts b/packages/angular_devkit/build_angular/src/webpack/configs/stats.ts index b0cd9297ff43..a031a906d9b1 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/stats.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/stats.ts @@ -15,16 +15,13 @@ const webpackOutputOptions = { timings: true, // required by custom stat output chunks: true, // required by custom stat output builtAt: true, // required by custom stat output - chunkModules: false, - children: false, // listing all children is very noisy in AOT and hides warnings/errors - modules: false, - reasons: false, warnings: true, errors: true, assets: true, // required by custom stat output - version: false, - errorDetails: false, - moduleTrace: false, + + // Needed for markAsyncChunksNonInitial. + ids: true, + entrypoints: true, }; const verboseWebpackOutputOptions: Record = { @@ -40,10 +37,9 @@ const verboseWebpackOutputOptions: Record = { errorDetails: true, moduleTrace: true, logging: 'verbose', + modulesSpace: Infinity, }; -verboseWebpackOutputOptions['modulesSpace'] = Infinity; - export function getWebpackStatsConfig(verbose = false) { return verbose ? { ...webpackOutputOptions, ...verboseWebpackOutputOptions } diff --git a/packages/angular_devkit/build_webpack/src/webpack/index.ts b/packages/angular_devkit/build_webpack/src/webpack/index.ts index 80e1e14daabc..f8bcb7281fc1 100644 --- a/packages/angular_devkit/build_webpack/src/webpack/index.ts +++ b/packages/angular_devkit/build_webpack/src/webpack/index.ts @@ -59,11 +59,6 @@ export function runWebpack( switchMap( (webpackCompiler) => new Observable((obs) => { - // Webpack 5 has a compiler level close function - const compilerClose = (webpackCompiler as { - close?(callback: () => void): void; - }).close?.bind(webpackCompiler); - const callback = (err?: Error, stats?: webpack.Stats) => { if (err) { return obs.error(err); @@ -76,19 +71,17 @@ export function runWebpack( // Log stats. log(stats, config); - obs.next(({ + const statsOptions = typeof config.stats === 'boolean' ? undefined : config.stats; + + obs.next({ success: !stats.hasErrors(), - webpackStats: shouldProvideStats ? stats.toJson() : undefined, + webpackStats: shouldProvideStats ? stats.toJson(statsOptions) : undefined, emittedFiles: getEmittedFiles(stats.compilation), outputPath: stats.compilation.outputOptions.path, - } as unknown) as BuildResult); + } as unknown as BuildResult); if (!config.watch) { - if (compilerClose) { - compilerClose(() => obs.complete()); - } else { - obs.complete(); - } + webpackCompiler.close(() => obs.complete()); } }; @@ -100,7 +93,7 @@ export function runWebpack( // Teardown logic. Close the watcher when unsubscribed from. return () => { watching.close(() => {}); - compilerClose?.(() => {}); + webpackCompiler.close(() => {}); }; } else { webpackCompiler.run(callback);