Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): conditionally add Angular compil…
Browse files Browse the repository at this point in the history
…er 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.
  • Loading branch information
clydin committed Oct 23, 2023
1 parent 7229a3d commit babe467
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ export function createBrowserPolyfillBundleOptions(
return;
}

const { outputNames } = options;
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
options,
target,
sourceFileCache,
);
const { outputNames, polyfills } = options;

const buildOptions: BuildOptions = {
...polyfillBundleOptions,
Expand All @@ -108,15 +103,24 @@ export function createBrowserPolyfillBundleOptions(
},
};

buildOptions.plugins ??= [];
buildOptions.plugins.push(
createCompilerPlugin(
// JS/TS options
{ ...pluginOptions, noopTypeScriptCompilation: true },
// Component stylesheet options are unused for polyfills but required by the plugin
styleOptions,
),
);
// 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(
options,
target,
sourceFileCache,
);
buildOptions.plugins.push(
createCompilerPlugin(
// JS/TS options
{ ...pluginOptions, noopTypeScriptCompilation: true },
// Component stylesheet options are unused for polyfills but required by the plugin
styleOptions,
),
);
}

return buildOptions;
}
Expand Down

0 comments on commit babe467

Please sign in to comment.