Skip to content

Commit 6c513cf

Browse files
committed
refactor(@angular/build): add handling for ngServerMode
Configure esbuild to add `ngServerMode` as define. (cherry picked from commit 8e2829c)
1 parent d63f49a commit 6c513cf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,12 @@ export function createSsrEntryCodeBundleOptions(
507507
function getEsBuildServerCommonOptions(options: NormalizedApplicationBuildOptions): BuildOptions {
508508
const isNodePlatform = options.ssrOptions?.platform !== ExperimentalPlatform.Neutral;
509509

510+
const commonOptons = getEsBuildCommonOptions(options);
511+
commonOptons.define ??= {};
512+
commonOptons.define['ngServerMode'] = 'true';
513+
510514
return {
511-
...getEsBuildCommonOptions(options),
515+
...commonOptons,
512516
platform: isNodePlatform ? 'node' : 'neutral',
513517
outExtension: { '.js': '.mjs' },
514518
// Note: `es2015` is needed for RxJS v6. If not specified, `module` would
@@ -587,6 +591,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
587591
// which a constant true value would break.
588592
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
589593
'ngJitMode': jit ? 'true' : 'false',
594+
'ngServerMode': 'false',
590595
},
591596
loader: loaderExtensions,
592597
footer,

packages/angular_devkit/build_angular/src/tools/webpack/configs/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
299299
if (scriptsOptimization) {
300300
extraMinimizers.push(
301301
new JavaScriptOptimizerPlugin({
302-
define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
302+
define: {
303+
...(buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER),
304+
'ngServerMode': isPlatformServer,
305+
},
303306
sourcemap: scriptsSourceMap,
304307
supportedBrowsers: buildOptions.supportedBrowsers,
305308
keepIdentifierNames: !allowMangle || isPlatformServer,

0 commit comments

Comments
 (0)