Skip to content

Commit

Permalink
perf(@angular-devkit/build-webpack): include only required stats in w…
Browse files Browse the repository at this point in the history
…ebpackStats

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,
```
  • Loading branch information
alan-agius4 committed Jun 2, 2021
1 parent 2e007b7 commit 023d093
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean | string | number> = {
Expand All @@ -40,10 +37,9 @@ const verboseWebpackOutputOptions: Record<string, boolean | string | number> = {
errorDetails: true,
moduleTrace: true,
logging: 'verbose',
modulesSpace: Infinity,
};

verboseWebpackOutputOptions['modulesSpace'] = Infinity;

export function getWebpackStatsConfig(verbose = false) {
return verbose
? { ...webpackOutputOptions, ...verboseWebpackOutputOptions }
Expand Down
21 changes: 7 additions & 14 deletions packages/angular_devkit/build_webpack/src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ export function runWebpack(
switchMap(
(webpackCompiler) =>
new Observable<BuildResult>((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);
Expand All @@ -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());
}
};

Expand All @@ -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);
Expand Down

0 comments on commit 023d093

Please sign in to comment.