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