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