@@ -97,7 +97,7 @@ export function createServerCodeBundleOptions(
97
97
target : string [ ] ,
98
98
sourceFileCache : SourceFileCache ,
99
99
) : BuildOptions {
100
- const { jit, serverEntryPoint, workspaceRoot } = options ;
100
+ const { jit, serverEntryPoint, workspaceRoot, ssrOptions } = options ;
101
101
102
102
assert (
103
103
serverEntryPoint ,
@@ -110,7 +110,15 @@ export function createServerCodeBundleOptions(
110
110
sourceFileCache ,
111
111
) ;
112
112
113
- const namespace = 'angular:server-entry' ;
113
+ const namespace = 'angular:main-server' ;
114
+ const entryPoints : Record < string , string > = {
115
+ 'main.server' : namespace ,
116
+ } ;
117
+
118
+ const ssrEntryPoint = ssrOptions ?. entry ;
119
+ if ( ssrEntryPoint ) {
120
+ entryPoints [ 'server' ] = ssrEntryPoint ;
121
+ }
114
122
115
123
const buildOptions : BuildOptions = {
116
124
...getEsBuildCommonOptions ( options ) ,
@@ -131,9 +139,7 @@ export function createServerCodeBundleOptions(
131
139
`globalThis['require'] ??= createRequire(import.meta.url);` ,
132
140
] . join ( '\n' ) ,
133
141
} ,
134
- entryPoints : {
135
- 'server' : namespace ,
136
- } ,
142
+ entryPoints,
137
143
supported : getFeatureSupport ( target ) ,
138
144
plugins : [
139
145
createSourcemapIngorelistPlugin ( ) ,
@@ -143,30 +149,6 @@ export function createServerCodeBundleOptions(
143
149
// Component stylesheet options
144
150
styleOptions ,
145
151
) ,
146
- createVirtualModulePlugin ( {
147
- namespace,
148
- loadContent : ( ) => {
149
- const mainServerEntryPoint = path
150
- . relative ( workspaceRoot , serverEntryPoint )
151
- . replace ( / \\ / g, '/' ) ;
152
- const importAndExportDec : string [ ] = [
153
- `import '@angular/platform-server/init';` ,
154
- `import moduleOrBootstrapFn from './${ mainServerEntryPoint } ';` ,
155
- `export default moduleOrBootstrapFn;` ,
156
- `export { renderApplication, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';` ,
157
- ] ;
158
-
159
- if ( jit ) {
160
- importAndExportDec . unshift ( `import '@angular/compiler';` ) ;
161
- }
162
-
163
- return {
164
- contents : importAndExportDec . join ( '\n' ) ,
165
- loader : 'js' ,
166
- resolveDir : workspaceRoot ,
167
- } ;
168
- } ,
169
- } ) ,
170
152
] ,
171
153
} ;
172
154
@@ -177,6 +159,33 @@ export function createServerCodeBundleOptions(
177
159
buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
178
160
}
179
161
162
+ buildOptions . plugins . push (
163
+ createVirtualModulePlugin ( {
164
+ namespace,
165
+ loadContent : ( ) => {
166
+ const mainServerEntryPoint = path
167
+ . relative ( workspaceRoot , serverEntryPoint )
168
+ . replace ( / \\ / g, '/' ) ;
169
+ const importAndExportDec : string [ ] = [
170
+ `import '@angular/platform-server/init';` ,
171
+ `import moduleOrBootstrapFn from './${ mainServerEntryPoint } ';` ,
172
+ `export default moduleOrBootstrapFn;` ,
173
+ `export { renderApplication, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';` ,
174
+ ] ;
175
+
176
+ if ( jit ) {
177
+ importAndExportDec . unshift ( `import '@angular/compiler';` ) ;
178
+ }
179
+
180
+ return {
181
+ contents : importAndExportDec . join ( '\n' ) ,
182
+ loader : 'js' ,
183
+ resolveDir : workspaceRoot ,
184
+ } ;
185
+ } ,
186
+ } ) ,
187
+ ) ;
188
+
180
189
return buildOptions ;
181
190
}
182
191
0 commit comments