Skip to content

Commit e20e739

Browse files
committed
refactor(@angular/build): add globalThis['ngServerMode'] only when externalDependencies are present
This code is unnecessary when no external dependencies are involved. (cherry picked from commit 43127dd)
1 parent 1047b86 commit e20e739

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/angular/build/src/tools/esbuild/application-code-bundle.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ export function createServerPolyfillBundleOptions(
200200
return;
201201
}
202202

203-
const jsBanner: string[] = [`globalThis['ngServerMode'] = true;`];
203+
const jsBanner: string[] = [];
204+
if (polyfillBundleOptions.external?.length) {
205+
jsBanner.push(`globalThis['ngServerMode'] = true;`);
206+
}
207+
204208
if (isNodePlatform) {
205209
// Note: Needed as esbuild does not provide require shims / proxy from ESModules.
206210
// See: https://github.com/evanw/esbuild/issues/1921.
@@ -394,7 +398,11 @@ export function createSsrEntryCodeBundleOptions(
394398
const ssrInjectManifestNamespace = 'angular:ssr-entry-inject-manifest';
395399
const isNodePlatform = options.ssrOptions?.platform !== ExperimentalPlatform.Neutral;
396400

397-
const jsBanner: string[] = [`globalThis['ngServerMode'] = true;`];
401+
const jsBanner: string[] = [];
402+
if (options.externalDependencies?.length) {
403+
jsBanner.push(`globalThis['ngServerMode'] = true;`);
404+
}
405+
398406
if (isNodePlatform) {
399407
// Note: Needed as esbuild does not provide require shims / proxy from ESModules.
400408
// See: https://github.com/evanw/esbuild/issues/1921.

0 commit comments

Comments
 (0)