@@ -254,9 +254,7 @@ export function createServerMainCodeBundleOptions(
254
254
255
255
return ( loadResultCache ) => {
256
256
const pluginOptions = createCompilerPluginOptions ( options , sourceFileCache , loadResultCache ) ;
257
-
258
257
const mainServerNamespace = 'angular:main-server' ;
259
- const mainServerInjectPolyfillsNamespace = 'angular:main-server-inject-polyfills' ;
260
258
const mainServerInjectManifestNamespace = 'angular:main-server-inject-manifest' ;
261
259
const zoneless = isZonelessApp ( polyfills ) ;
262
260
const entryPoints : Record < string , string > = {
@@ -275,7 +273,9 @@ export function createServerMainCodeBundleOptions(
275
273
const buildOptions : BuildOptions = {
276
274
...getEsBuildServerCommonOptions ( options ) ,
277
275
target,
278
- inject : [ mainServerInjectPolyfillsNamespace , mainServerInjectManifestNamespace ] ,
276
+ banner : {
277
+ js : `import './polyfills.server.mjs';` ,
278
+ } ,
279
279
entryPoints,
280
280
supported : getFeatureSupport ( target , zoneless ) ,
281
281
plugins : [
@@ -311,18 +311,10 @@ export function createServerMainCodeBundleOptions(
311
311
312
312
buildOptions . plugins . push (
313
313
createServerBundleMetadata ( ) ,
314
- createVirtualModulePlugin ( {
315
- namespace : mainServerInjectPolyfillsNamespace ,
316
- cache : loadResultCache ,
317
- loadContent : ( ) => ( {
318
- contents : `import './polyfills.server.mjs';` ,
319
- loader : 'js' ,
320
- resolveDir : workspaceRoot ,
321
- } ) ,
322
- } ) ,
323
314
createVirtualModulePlugin ( {
324
315
namespace : mainServerInjectManifestNamespace ,
325
316
cache : loadResultCache ,
317
+ entryPointOnly : false ,
326
318
loadContent : async ( ) => {
327
319
const contents : string [ ] = [
328
320
// Configure `@angular/ssr` manifest.
@@ -348,16 +340,19 @@ export function createServerMainCodeBundleOptions(
348
340
) ;
349
341
350
342
const contents : string [ ] = [
351
- // Re-export all symbols including default export from 'main.server.ts'
352
- `export { default } from '${ mainServerEntryPointJsImport } ';` ,
353
- `export * from '${ mainServerEntryPointJsImport } ';` ,
343
+ // Inject manifest
344
+ `import '${ mainServerInjectManifestNamespace } ';` ,
354
345
355
346
// Add @angular /ssr exports
356
347
`export {
357
- ɵdestroyAngularServerApp,
358
- ɵextractRoutesAndCreateRouteTree,
359
- ɵgetOrCreateAngularServerApp,
360
- } from '@angular/ssr';` ,
348
+ ɵdestroyAngularServerApp,
349
+ ɵextractRoutesAndCreateRouteTree,
350
+ ɵgetOrCreateAngularServerApp,
351
+ } from '@angular/ssr';` ,
352
+
353
+ // Re-export all symbols including default export from 'main.server.ts'
354
+ `export { default } from '${ mainServerEntryPointJsImport } ';` ,
355
+ `export * from '${ mainServerEntryPointJsImport } ';` ,
361
356
] ;
362
357
363
358
return {
@@ -392,22 +387,24 @@ export function createSsrEntryCodeBundleOptions(
392
387
393
388
return ( loadResultCache ) => {
394
389
const pluginOptions = createCompilerPluginOptions ( options , sourceFileCache , loadResultCache ) ;
395
-
396
390
const ssrEntryNamespace = 'angular:ssr-entry' ;
397
391
const ssrInjectManifestNamespace = 'angular:ssr-entry-inject-manifest' ;
398
- const ssrInjectRequireNamespace = 'angular:ssr-entry-inject-require' ;
399
392
const isNodePlatform = options . ssrOptions ?. platform !== ExperimentalPlatform . Neutral ;
400
393
401
- const inject : string [ ] = [ ssrInjectManifestNamespace ] ;
402
- if ( isNodePlatform ) {
403
- inject . unshift ( ssrInjectRequireNamespace ) ;
404
- }
405
-
406
394
const buildOptions : BuildOptions = {
407
395
...getEsBuildServerCommonOptions ( options ) ,
408
396
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 ,
409
407
entryPoints : {
410
- // TODO: consider renaming to index
411
408
'server' : ssrEntryNamespace ,
412
409
} ,
413
410
supported : getFeatureSupport ( target , true ) ,
@@ -420,7 +417,6 @@ export function createSsrEntryCodeBundleOptions(
420
417
stylesheetBundler ,
421
418
) ,
422
419
] ,
423
- inject,
424
420
} ;
425
421
426
422
buildOptions . plugins ??= [ ] ;
@@ -443,27 +439,10 @@ export function createSsrEntryCodeBundleOptions(
443
439
444
440
buildOptions . plugins . push (
445
441
createServerBundleMetadata ( { ssrEntryBundle : true } ) ,
446
- createVirtualModulePlugin ( {
447
- namespace : ssrInjectRequireNamespace ,
448
- cache : loadResultCache ,
449
- loadContent : ( ) => {
450
- const contents : string [ ] = [
451
- // Note: Needed as esbuild does not provide require shims / proxy from ESModules.
452
- // See: https://github.com/evanw/esbuild/issues/1921.
453
- `import { createRequire } from 'node:module';` ,
454
- `globalThis['require'] ??= createRequire(import.meta.url);` ,
455
- ] ;
456
-
457
- return {
458
- contents : contents . join ( '\n' ) ,
459
- loader : 'js' ,
460
- resolveDir : workspaceRoot ,
461
- } ;
462
- } ,
463
- } ) ,
464
442
createVirtualModulePlugin ( {
465
443
namespace : ssrInjectManifestNamespace ,
466
444
cache : loadResultCache ,
445
+ entryPointOnly : false ,
467
446
loadContent : ( ) => {
468
447
const contents : string [ ] = [
469
448
// Configure `@angular/ssr` app engine manifest.
@@ -488,6 +467,9 @@ export function createSsrEntryCodeBundleOptions(
488
467
serverEntryPoint ,
489
468
) ;
490
469
const contents : string [ ] = [
470
+ // Configure `@angular/ssr` app engine manifest.
471
+ `import '${ ssrInjectManifestNamespace } ';` ,
472
+
491
473
// Re-export all symbols including default export
492
474
`import * as server from '${ serverEntryPointJsImport } ';` ,
493
475
`export * from '${ serverEntryPointJsImport } ';` ,
0 commit comments