Skip to content

Commit c013a95

Browse files
clydinalan-agius4
authored andcommitted
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 bb13e40)
1 parent 323289b commit c013a95

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { NormalizedApplicationBuildOptions } from '../../builders/applicati
1515
import { allowMangle } from '../../utils/environment-options';
1616
import { createCompilerPlugin } from './angular/compiler-plugin';
1717
import { SourceFileCache } from './angular/source-file-cache';
18+
import { BundlerOptionsFactory } from './bundler-context';
1819
import { createCompilerPluginOptions } from './compiler-plugin-options';
1920
import { createAngularLocaleDataPlugin } from './i18n-locale-plugin';
2021
import { createRxjsEsmResolutionPlugin } from './rxjs-esm-resolution-plugin';
@@ -73,7 +74,7 @@ export function createBrowserPolyfillBundleOptions(
7374
options: NormalizedApplicationBuildOptions,
7475
target: string[],
7576
sourceFileCache?: SourceFileCache,
76-
): BuildOptions | undefined {
77+
): BuildOptions | BundlerOptionsFactory | undefined {
7778
const namespace = 'angular:polyfills';
7879
const polyfillBundleOptions = getEsBuildCommonPolyfillsOptions(
7980
options,
@@ -86,6 +87,7 @@ export function createBrowserPolyfillBundleOptions(
8687
}
8788

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

9092
const buildOptions: BuildOptions = {
9193
...polyfillBundleOptions,
@@ -103,7 +105,6 @@ export function createBrowserPolyfillBundleOptions(
103105
};
104106

105107
// Only add the Angular TypeScript compiler if TypeScript files are provided in the polyfills
106-
const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry));
107108
if (hasTypeScriptEntries) {
108109
buildOptions.plugins ??= [];
109110
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
@@ -121,7 +122,10 @@ export function createBrowserPolyfillBundleOptions(
121122
);
122123
}
123124

124-
return buildOptions;
125+
// Use an options factory to allow fully incremental bundling when no TypeScript files are present.
126+
// The TypeScript compilation is not currently integrated into the bundler invalidation so
127+
// cannot be used with fully incremental bundling yet.
128+
return hasTypeScriptEntries ? buildOptions : () => buildOptions;
125129
}
126130

127131
/**

0 commit comments

Comments
 (0)