@@ -200,6 +200,16 @@ export function createServerPolyfillBundleOptions(
200
200
return ;
201
201
}
202
202
203
+ const jsBanner : string [ ] = [ `globalThis['ngServerMode'] = true;` ] ;
204
+ if ( isNodePlatform ) {
205
+ // Note: Needed as esbuild does not provide require shims / proxy from ESModules.
206
+ // See: https://github.com/evanw/esbuild/issues/1921.
207
+ jsBanner . push (
208
+ `import { createRequire } from 'node:module';` ,
209
+ `globalThis['require'] ??= createRequire(import.meta.url);` ,
210
+ ) ;
211
+ }
212
+
203
213
const buildOptions : BuildOptions = {
204
214
...polyfillBundleOptions ,
205
215
platform : isNodePlatform ? 'node' : 'neutral' ,
@@ -210,16 +220,9 @@ export function createServerPolyfillBundleOptions(
210
220
// More details: https://github.com/angular/angular-cli/issues/25405.
211
221
mainFields : [ 'es2020' , 'es2015' , 'module' , 'main' ] ,
212
222
entryNames : '[name]' ,
213
- banner : isNodePlatform
214
- ? {
215
- js : [
216
- // Note: Needed as esbuild does not provide require shims / proxy from ESModules.
217
- // See: https://github.com/evanw/esbuild/issues/1921.
218
- `import { createRequire } from 'node:module';` ,
219
- `globalThis['require'] ??= createRequire(import.meta.url);` ,
220
- ] . join ( '\n' ) ,
221
- }
222
- : undefined ,
223
+ banner : {
224
+ js : jsBanner . join ( '\n' ) ,
225
+ } ,
223
226
target,
224
227
entryPoints : {
225
228
'polyfills.server' : namespace ,
@@ -391,19 +394,22 @@ export function createSsrEntryCodeBundleOptions(
391
394
const ssrInjectManifestNamespace = 'angular:ssr-entry-inject-manifest' ;
392
395
const isNodePlatform = options . ssrOptions ?. platform !== ExperimentalPlatform . Neutral ;
393
396
397
+ const jsBanner : string [ ] = [ `globalThis['ngServerMode'] = true;` ] ;
398
+ if ( isNodePlatform ) {
399
+ // Note: Needed as esbuild does not provide require shims / proxy from ESModules.
400
+ // See: https://github.com/evanw/esbuild/issues/1921.
401
+ jsBanner . push (
402
+ `import { createRequire } from 'node:module';` ,
403
+ `globalThis['require'] ??= createRequire(import.meta.url);` ,
404
+ ) ;
405
+ }
406
+
394
407
const buildOptions : BuildOptions = {
395
408
...getEsBuildServerCommonOptions ( options ) ,
396
409
target,
397
- banner : isNodePlatform
398
- ? {
399
- js : [
400
- // Note: Needed as esbuild does not provide require shims / proxy from ESModules.
401
- // See: https://github.com/evanw/esbuild/issues/1921.
402
- `import { createRequire } from 'node:module';` ,
403
- `globalThis['require'] ??= createRequire(import.meta.url);` ,
404
- ] . join ( '\n' ) ,
405
- }
406
- : undefined ,
410
+ banner : {
411
+ js : jsBanner . join ( '\n' ) ,
412
+ } ,
407
413
entryPoints : {
408
414
'server' : ssrEntryNamespace ,
409
415
} ,
0 commit comments