Skip to content

Commit ec739d7

Browse files
committed
refactor(@angular/build): allow Bazel to inject a custom esbuild plugin
Introduces a mechanism to dynamically load a custom esbuild plugin when the application builder is executed within a Bazel environment. This is enabled by a new `bazelEsbuildPluginPath` option, which is derived from the `NG_INTERNAL_ESBUILD_PLUGINS_DO_NOT_USE` environment variable. The path is only resolved if the `BAZEL_BINDIR` and `JS_BINARY__EXECROOT` environment variables are also present, ensuring the logic is only active during a Bazel build. The builder dynamically imports the plugin from the specified path and adds it to the esbuild pipeline, allowing for build-system-specific customizations.
1 parent 6639085 commit ec739d7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/angular/build/src/builders/application/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { BuildOutputFileType } from '../../tools/esbuild/bundler-context';
1414
import { createJsonBuildManifest, emitFilesToDisk } from '../../tools/esbuild/utils';
1515
import { colors as ansiColors } from '../../utils/color';
1616
import { deleteOutputDir } from '../../utils/delete-output-dir';
17-
import { useJSONBuildLogs } from '../../utils/environment-options';
17+
import { bazelEsbuildPluginPath, useJSONBuildLogs } from '../../utils/environment-options';
1818
import { purgeStaleBuildCache } from '../../utils/purge-cache';
1919
import { assertCompatibleAngularVersion } from '../../utils/version';
2020
import { runEsBuildBuildAction } from './build-action';
@@ -56,6 +56,14 @@ export async function* buildApplicationInternal(
5656
return;
5757
}
5858

59+
if (bazelEsbuildPluginPath) {
60+
extensions ??= {};
61+
extensions.codePlugins ??= [];
62+
63+
const { default: bazelEsbuildPlugin } = await import(bazelEsbuildPluginPath);
64+
extensions.codePlugins.push(bazelEsbuildPlugin);
65+
}
66+
5967
const normalizedOptions = await normalizeOptions(context, projectName, options, extensions);
6068

6169
if (!normalizedOptions.outputOptions.ignoreServer) {

packages/angular/build/src/utils/environment-options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,11 @@ export const useComponentTemplateHmr = parseTristate(process.env['NG_HMR_TEMPLAT
165165
* When `NG_BUILD_PARTIAL_SSR` is enabled, a partial server-side rendering build will be performed.
166166
*/
167167
export const usePartialSsrBuild = parseTristate(process.env['NG_BUILD_PARTIAL_SSR']) === true;
168+
169+
const bazelBinDirectory = process.env['BAZEL_BINDIR'];
170+
const bazelExecRoot = process.env['JS_BINARY__EXECROOT'];
171+
172+
export const bazelEsbuildPluginPath =
173+
bazelBinDirectory && bazelExecRoot
174+
? process.env['NG_INTERNAL_ESBUILD_PLUGINS_DO_NOT_USE']
175+
: undefined;

0 commit comments

Comments
 (0)