@@ -110,14 +110,16 @@ export function createServerCodeBundleOptions(
110
110
sourceFileCache ,
111
111
) ;
112
112
113
- const namespace = 'angular:main-server' ;
113
+ const mainServerNamespace = 'angular:main-server' ;
114
+ const ssrEntryNamespace = 'angular:ssr-entry' ;
115
+
114
116
const entryPoints : Record < string , string > = {
115
- 'main.server' : namespace ,
117
+ 'main.server' : mainServerNamespace ,
116
118
} ;
117
119
118
120
const ssrEntryPoint = ssrOptions ?. entry ;
119
121
if ( ssrEntryPoint ) {
120
- entryPoints [ 'server' ] = ssrEntryPoint ;
122
+ entryPoints [ 'server' ] = ssrEntryNamespace ;
121
123
}
122
124
123
125
const buildOptions : BuildOptions = {
@@ -159,37 +161,62 @@ export function createServerCodeBundleOptions(
159
161
buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
160
162
}
161
163
164
+ const polyfills = [ `import '@angular/platform-server/init';` ] ;
165
+
166
+ if ( options . polyfills ?. includes ( 'zone.js' ) ) {
167
+ polyfills . push ( `import 'zone.js/node';` ) ;
168
+ }
169
+
170
+ if ( jit ) {
171
+ polyfills . push ( `import '@angular/compiler';` ) ;
172
+ }
173
+
162
174
buildOptions . plugins . push (
163
175
createVirtualModulePlugin ( {
164
- namespace,
176
+ namespace : mainServerNamespace ,
165
177
loadContent : ( ) => {
166
178
const mainServerEntryPoint = path
167
179
. relative ( workspaceRoot , serverEntryPoint )
168
180
. 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
- if ( options . polyfills ?. includes ( 'zone.js' ) ) {
181
- importAndExportDec . unshift ( `import 'zone.js/node';` ) ;
182
- }
183
181
184
182
return {
185
- contents : importAndExportDec . join ( '\n' ) ,
183
+ contents : [
184
+ ...polyfills ,
185
+ `import moduleOrBootstrapFn from './${ mainServerEntryPoint } ';` ,
186
+ `export default moduleOrBootstrapFn;` ,
187
+ `export * from './${ mainServerEntryPoint } ';` ,
188
+ `export { renderApplication, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';` ,
189
+ ] . join ( '\n' ) ,
186
190
loader : 'js' ,
187
191
resolveDir : workspaceRoot ,
188
192
} ;
189
193
} ,
190
194
} ) ,
191
195
) ;
192
196
197
+ if ( ssrEntryPoint ) {
198
+ buildOptions . plugins . push (
199
+ createVirtualModulePlugin ( {
200
+ namespace : ssrEntryNamespace ,
201
+ loadContent : ( ) => {
202
+ const mainServerEntryPoint = path
203
+ . relative ( workspaceRoot , ssrEntryPoint )
204
+ . replace ( / \\ / g, '/' ) ;
205
+
206
+ return {
207
+ contents : [
208
+ ...polyfills ,
209
+ `import './${ mainServerEntryPoint } ';` ,
210
+ `export * from './${ mainServerEntryPoint } ';` ,
211
+ ] . join ( '\n' ) ,
212
+ loader : 'js' ,
213
+ resolveDir : workspaceRoot ,
214
+ } ;
215
+ } ,
216
+ } ) ,
217
+ ) ;
218
+ }
219
+
193
220
return buildOptions ;
194
221
}
195
222
0 commit comments