Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): only rebundle browser polyfills …
Browse files Browse the repository at this point in the history
…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 bb13e40)
  • Loading branch information
clydin authored and alan-agius4 committed Oct 30, 2023
1 parent 323289b commit c013a95
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -86,6 +87,7 @@ export function createBrowserPolyfillBundleOptions(
}

const { outputNames, polyfills } = options;
const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry));

const buildOptions: BuildOptions = {
...polyfillBundleOptions,
Expand All @@ -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(
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit c013a95

Please sign in to comment.