Skip to content

Commit babe467

Browse files
committed
perf(@angular-devkit/build-angular): conditionally add Angular compiler plugin to polyfills bundling
When using the esbuild-based builders (`application`/`browser-esbuild`), the Angular compiler plugin is now only added to the polyfills bundler configuration if TypeScript files are found in the `polyfills` build option. This is not the case for a default project. The Angular compiler plugin is used to provide type-checking diagnostics for any TypeScript files present within the build. However, if there are no TypeScript files to process, there is no need to use it for the polyfills processing.
1 parent 7229a3d commit babe467

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ export function createBrowserPolyfillBundleOptions(
8686
return;
8787
}
8888

89-
const { outputNames } = options;
90-
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
91-
options,
92-
target,
93-
sourceFileCache,
94-
);
89+
const { outputNames, polyfills } = options;
9590

9691
const buildOptions: BuildOptions = {
9792
...polyfillBundleOptions,
@@ -108,15 +103,24 @@ export function createBrowserPolyfillBundleOptions(
108103
},
109104
};
110105

111-
buildOptions.plugins ??= [];
112-
buildOptions.plugins.push(
113-
createCompilerPlugin(
114-
// JS/TS options
115-
{ ...pluginOptions, noopTypeScriptCompilation: true },
116-
// Component stylesheet options are unused for polyfills but required by the plugin
117-
styleOptions,
118-
),
119-
);
106+
// Only add the Angular TypeScript compiler if TypeScript files are provided in the polyfills
107+
const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry));
108+
if (hasTypeScriptEntries) {
109+
buildOptions.plugins ??= [];
110+
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
111+
options,
112+
target,
113+
sourceFileCache,
114+
);
115+
buildOptions.plugins.push(
116+
createCompilerPlugin(
117+
// JS/TS options
118+
{ ...pluginOptions, noopTypeScriptCompilation: true },
119+
// Component stylesheet options are unused for polyfills but required by the plugin
120+
styleOptions,
121+
),
122+
);
123+
}
120124

121125
return buildOptions;
122126
}

0 commit comments

Comments
 (0)