From c013a95e2f38a5c2435b22c3338bf57b03c84ebf Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:16:00 -0400 Subject: [PATCH] perf(@angular-devkit/build-angular): only rebundle browser polyfills on explicit changes The newly introduced incremental bundler result caching is now used for browser polyfills (`polyfills` option). This allows the bundling steps to be skipped in watch mode when no related files for have been modified. (cherry picked from commit bb13e406c70d0d512c44650177d89bd27bef6396) --- .../src/tools/esbuild/application-code-bundle.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts index 9c040116426b..cc6bfd32cf8e 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts @@ -15,6 +15,7 @@ import type { NormalizedApplicationBuildOptions } from '../../builders/applicati import { allowMangle } from '../../utils/environment-options'; import { createCompilerPlugin } from './angular/compiler-plugin'; import { SourceFileCache } from './angular/source-file-cache'; +import { BundlerOptionsFactory } from './bundler-context'; import { createCompilerPluginOptions } from './compiler-plugin-options'; import { createAngularLocaleDataPlugin } from './i18n-locale-plugin'; import { createRxjsEsmResolutionPlugin } from './rxjs-esm-resolution-plugin'; @@ -73,7 +74,7 @@ export function createBrowserPolyfillBundleOptions( options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache?: SourceFileCache, -): BuildOptions | undefined { +): BuildOptions | BundlerOptionsFactory | undefined { const namespace = 'angular:polyfills'; const polyfillBundleOptions = getEsBuildCommonPolyfillsOptions( options, @@ -86,6 +87,7 @@ export function createBrowserPolyfillBundleOptions( } const { outputNames, polyfills } = options; + const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry)); const buildOptions: BuildOptions = { ...polyfillBundleOptions, @@ -103,7 +105,6 @@ export function createBrowserPolyfillBundleOptions( }; // Only add the Angular TypeScript compiler if TypeScript files are provided in the polyfills - const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry)); if (hasTypeScriptEntries) { buildOptions.plugins ??= []; const { pluginOptions, styleOptions } = createCompilerPluginOptions( @@ -121,7 +122,10 @@ export function createBrowserPolyfillBundleOptions( ); } - return buildOptions; + // Use an options factory to allow fully incremental bundling when no TypeScript files are present. + // The TypeScript compilation is not currently integrated into the bundler invalidation so + // cannot be used with fully incremental bundling yet. + return hasTypeScriptEntries ? buildOptions : () => buildOptions; } /**