From 34947fc64953f845d33ffb1c52f236869a040c9d Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:52:37 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): use incremental component style bundling only in watch mode Component style bundling when using the application builder will now only generate incremental contexts when in watch mode. During non-watch build, this incremental context information is not needed and unnecessarily increases memory usage during a build. (cherry picked from commit 8d1d3531d0990ea4cc9c919d36cb6ff6c855be40) --- .../src/tools/esbuild/angular/compiler-plugin.ts | 2 ++ .../src/tools/esbuild/angular/component-stylesheets.ts | 5 +++-- .../src/tools/esbuild/compiler-plugin-options.ts | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts index 07f78a38667d..982abe484ad0 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts @@ -47,6 +47,7 @@ export interface CompilerPluginOptions { fileReplacements?: Record; sourceFileCache?: SourceFileCache; loadResultCache?: LoadResultCache; + incremental: boolean; } // eslint-disable-next-line max-lines-per-function @@ -100,6 +101,7 @@ export function createCompilerPlugin( // Track incremental component stylesheet builds const stylesheetBundler = new ComponentStylesheetBundler( styleOptions, + pluginOptions.incremental, pluginOptions.loadResultCache, ); let sharedTSCompilationState: SharedTSCompilationState | undefined; diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/component-stylesheets.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/component-stylesheets.ts index 14b56994580d..849f1a5b0cde 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/component-stylesheets.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/component-stylesheets.ts @@ -45,6 +45,7 @@ export class ComponentStylesheetBundler { */ constructor( private readonly options: BundleStylesheetOptions, + private readonly incremental: boolean, private readonly cache?: LoadResultCache, ) {} @@ -53,7 +54,7 @@ export class ComponentStylesheetBundler { const buildOptions = createStylesheetBundleOptions(this.options, this.cache); buildOptions.entryPoints = [entry]; - return new BundlerContext(this.options.workspaceRoot, true, buildOptions); + return new BundlerContext(this.options.workspaceRoot, this.incremental, buildOptions); }); return extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles); @@ -95,7 +96,7 @@ export class ComponentStylesheetBundler { }, }); - return new BundlerContext(this.options.workspaceRoot, true, buildOptions); + return new BundlerContext(this.options.workspaceRoot, this.incremental, buildOptions); }); // Extract the result of the bundling from the output files diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/compiler-plugin-options.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/compiler-plugin-options.ts index 03c5210a4002..d1de9017d3b2 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/compiler-plugin-options.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/compiler-plugin-options.ts @@ -47,6 +47,7 @@ export function createCompilerPluginOptions( fileReplacements, sourceFileCache, loadResultCache: sourceFileCache?.loadResultCache, + incremental: !!options.watch, }, // Component stylesheet options styleOptions: {