@@ -12,17 +12,25 @@ import {
12
12
BuildOutputFileType ,
13
13
InitialFileRecord ,
14
14
} from '../../tools/esbuild/bundler-context' ;
15
- import { BuildOutputAsset } from '../../tools/esbuild/bundler-execution-result' ;
15
+ import {
16
+ BuildOutputAsset ,
17
+ PrerenderedRoutesRecord ,
18
+ } from '../../tools/esbuild/bundler-execution-result' ;
16
19
import { generateIndexHtml } from '../../tools/esbuild/index-html-generator' ;
17
20
import { createOutputFile } from '../../tools/esbuild/utils' ;
18
21
import { maxWorkers } from '../../utils/environment-options' ;
19
22
import {
20
23
SERVER_APP_MANIFEST_FILENAME ,
21
24
generateAngularServerAppManifest ,
22
25
} from '../../utils/server-rendering/manifest' ;
26
+ import {
27
+ RouteRenderMode ,
28
+ WritableSerializableRouteTreeNode ,
29
+ } from '../../utils/server-rendering/models' ;
23
30
import { prerenderPages } from '../../utils/server-rendering/prerender' ;
24
31
import { augmentAppWithServiceWorkerEsbuild } from '../../utils/service-worker' ;
25
32
import { INDEX_HTML_SERVER , NormalizedApplicationBuildOptions } from './options' ;
33
+ import { OutputMode } from './schema' ;
26
34
27
35
/**
28
36
* Run additional builds steps including SSG, AppShell, Index HTML file and Service worker generation.
@@ -43,25 +51,26 @@ export async function executePostBundleSteps(
43
51
warnings : string [ ] ;
44
52
additionalOutputFiles : BuildOutputFile [ ] ;
45
53
additionalAssets : BuildOutputAsset [ ] ;
46
- prerenderedRoutes : string [ ] ;
54
+ prerenderedRoutes : PrerenderedRoutesRecord ;
47
55
} > {
48
56
const additionalAssets : BuildOutputAsset [ ] = [ ] ;
49
57
const additionalOutputFiles : BuildOutputFile [ ] = [ ] ;
50
58
const allErrors : string [ ] = [ ] ;
51
59
const allWarnings : string [ ] = [ ] ;
52
- const prerenderedRoutes : string [ ] = [ ] ;
60
+ const prerenderedRoutes : PrerenderedRoutesRecord = { } ;
53
61
54
62
const {
55
63
baseHref = '/' ,
56
64
serviceWorker,
57
65
indexHtmlOptions,
58
66
optimizationOptions,
59
67
sourcemapOptions,
60
- ssrOptions,
68
+ outputMode,
69
+ serverEntryPoint,
61
70
prerenderOptions,
62
71
appShellOptions,
63
72
workspaceRoot,
64
- verbose ,
73
+ disableFullServerManifestGeneration ,
65
74
} = options ;
66
75
67
76
// Index HTML content without CSS inlining to be used for server rendering (AppShell, SSG and SSR).
@@ -91,13 +100,13 @@ export async function executePostBundleSteps(
91
100
if ( ssrContent ) {
92
101
additionalHtmlOutputFiles . set (
93
102
INDEX_HTML_SERVER ,
94
- createOutputFile ( INDEX_HTML_SERVER , ssrContent , BuildOutputFileType . Server ) ,
103
+ createOutputFile ( INDEX_HTML_SERVER , ssrContent , BuildOutputFileType . ServerApplication ) ,
95
104
) ;
96
105
}
97
106
}
98
107
99
108
// Create server manifest
100
- if ( prerenderOptions || appShellOptions || ssrOptions ) {
109
+ if ( serverEntryPoint ) {
101
110
additionalOutputFiles . push (
102
111
createOutputFile (
103
112
SERVER_APP_MANIFEST_FILENAME ,
@@ -106,44 +115,41 @@ export async function executePostBundleSteps(
106
115
outputFiles ,
107
116
optimizationOptions . styles . inlineCritical ?? false ,
108
117
undefined ,
118
+ locale ,
109
119
) ,
110
- BuildOutputFileType . Server ,
120
+ BuildOutputFileType . ServerApplication ,
111
121
) ,
112
122
) ;
113
123
}
114
124
115
125
// Pre-render (SSG) and App-shell
116
126
// If localization is enabled, prerendering is handled in the inlining process.
117
- if ( ( prerenderOptions || appShellOptions ) && ! allErrors . length ) {
127
+ if (
128
+ ! disableFullServerManifestGeneration &&
129
+ ( prerenderOptions || appShellOptions || ( outputMode && serverEntryPoint ) ) &&
130
+ ! allErrors . length
131
+ ) {
118
132
assert (
119
133
indexHtmlOptions ,
120
134
'The "index" option is required when using the "ssg" or "appShell" options.' ,
121
135
) ;
122
136
123
- const {
124
- output,
125
- warnings,
126
- errors,
127
- prerenderedRoutes : generatedRoutes ,
128
- serializableRouteTreeNode,
129
- } = await prerenderPages (
137
+ const { output, warnings, errors, serializableRouteTreeNode } = await prerenderPages (
130
138
workspaceRoot ,
131
139
baseHref ,
132
140
appShellOptions ,
133
141
prerenderOptions ,
134
142
[ ...outputFiles , ...additionalOutputFiles ] ,
135
143
assetFiles ,
144
+ outputMode ,
136
145
sourcemapOptions . scripts ,
137
146
maxWorkers ,
138
- verbose ,
139
147
) ;
140
148
141
149
allErrors . push ( ...errors ) ;
142
150
allWarnings . push ( ...warnings ) ;
143
- prerenderedRoutes . push ( ...Array . from ( generatedRoutes ) ) ;
144
-
145
- const indexHasBeenPrerendered = generatedRoutes . has ( indexHtmlOptions . output ) ;
146
151
152
+ const indexHasBeenPrerendered = output [ indexHtmlOptions . output ] ;
147
153
for ( const [ path , { content, appShellRoute } ] of Object . entries ( output ) ) {
148
154
// Update the index contents with the app shell under these conditions:
149
155
// - Replace 'index.html' with the app shell only if it hasn't been prerendered yet.
@@ -155,7 +161,26 @@ export async function executePostBundleSteps(
155
161
) ;
156
162
}
157
163
158
- if ( ssrOptions ) {
164
+ const serializableRouteTreeNodeForManifest : WritableSerializableRouteTreeNode = [ ] ;
165
+
166
+ for ( const metadata of serializableRouteTreeNode ) {
167
+ switch ( metadata . renderMode ) {
168
+ case RouteRenderMode . Prerender :
169
+ case /* Legacy building mode */ undefined : {
170
+ if ( ! metadata . redirectTo || outputMode === OutputMode . Static ) {
171
+ prerenderedRoutes [ metadata . route ] = { headers : metadata . headers } ;
172
+ }
173
+ break ;
174
+ }
175
+ case RouteRenderMode . Server :
176
+ case RouteRenderMode . Client :
177
+ serializableRouteTreeNodeForManifest . push ( metadata ) ;
178
+
179
+ break ;
180
+ }
181
+ }
182
+
183
+ if ( outputMode === OutputMode . Server ) {
159
184
// Regenerate the manifest to append route tree. This is only needed if SSR is enabled.
160
185
const manifest = additionalOutputFiles . find ( ( f ) => f . path === SERVER_APP_MANIFEST_FILENAME ) ;
161
186
assert ( manifest , `${ SERVER_APP_MANIFEST_FILENAME } was not found in output files.` ) ;
@@ -165,7 +190,8 @@ export async function executePostBundleSteps(
165
190
additionalHtmlOutputFiles ,
166
191
outputFiles ,
167
192
optimizationOptions . styles . inlineCritical ?? false ,
168
- serializableRouteTreeNode ,
193
+ serializableRouteTreeNodeForManifest ,
194
+ locale ,
169
195
) ,
170
196
) ;
171
197
}
0 commit comments