@@ -12,17 +12,25 @@ import {
1212 BuildOutputFileType ,
1313 InitialFileRecord ,
1414} 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' ;
1619import { generateIndexHtml } from '../../tools/esbuild/index-html-generator' ;
1720import { createOutputFile } from '../../tools/esbuild/utils' ;
1821import { maxWorkers } from '../../utils/environment-options' ;
1922import {
2023 SERVER_APP_MANIFEST_FILENAME ,
2124 generateAngularServerAppManifest ,
2225} from '../../utils/server-rendering/manifest' ;
26+ import {
27+ RouteRenderMode ,
28+ WritableSerializableRouteTreeNode ,
29+ } from '../../utils/server-rendering/models' ;
2330import { prerenderPages } from '../../utils/server-rendering/prerender' ;
2431import { augmentAppWithServiceWorkerEsbuild } from '../../utils/service-worker' ;
2532import { INDEX_HTML_SERVER , NormalizedApplicationBuildOptions } from './options' ;
33+ import { OutputMode } from './schema' ;
2634
2735/**
2836 * Run additional builds steps including SSG, AppShell, Index HTML file and Service worker generation.
@@ -43,25 +51,26 @@ export async function executePostBundleSteps(
4351 warnings : string [ ] ;
4452 additionalOutputFiles : BuildOutputFile [ ] ;
4553 additionalAssets : BuildOutputAsset [ ] ;
46- prerenderedRoutes : string [ ] ;
54+ prerenderedRoutes : PrerenderedRoutesRecord ;
4755} > {
4856 const additionalAssets : BuildOutputAsset [ ] = [ ] ;
4957 const additionalOutputFiles : BuildOutputFile [ ] = [ ] ;
5058 const allErrors : string [ ] = [ ] ;
5159 const allWarnings : string [ ] = [ ] ;
52- const prerenderedRoutes : string [ ] = [ ] ;
60+ const prerenderedRoutes : PrerenderedRoutesRecord = { } ;
5361
5462 const {
5563 baseHref = '/' ,
5664 serviceWorker,
5765 indexHtmlOptions,
5866 optimizationOptions,
5967 sourcemapOptions,
60- ssrOptions,
68+ outputMode,
69+ serverEntryPoint,
6170 prerenderOptions,
6271 appShellOptions,
6372 workspaceRoot,
64- verbose ,
73+ disableFullServerManifestGeneration ,
6574 } = options ;
6675
6776 // Index HTML content without CSS inlining to be used for server rendering (AppShell, SSG and SSR).
@@ -91,13 +100,13 @@ export async function executePostBundleSteps(
91100 if ( ssrContent ) {
92101 additionalHtmlOutputFiles . set (
93102 INDEX_HTML_SERVER ,
94- createOutputFile ( INDEX_HTML_SERVER , ssrContent , BuildOutputFileType . Server ) ,
103+ createOutputFile ( INDEX_HTML_SERVER , ssrContent , BuildOutputFileType . ServerApplication ) ,
95104 ) ;
96105 }
97106 }
98107
99108 // Create server manifest
100- if ( prerenderOptions || appShellOptions || ssrOptions ) {
109+ if ( serverEntryPoint ) {
101110 additionalOutputFiles . push (
102111 createOutputFile (
103112 SERVER_APP_MANIFEST_FILENAME ,
@@ -106,44 +115,41 @@ export async function executePostBundleSteps(
106115 outputFiles ,
107116 optimizationOptions . styles . inlineCritical ?? false ,
108117 undefined ,
118+ locale ,
109119 ) ,
110- BuildOutputFileType . Server ,
120+ BuildOutputFileType . ServerApplication ,
111121 ) ,
112122 ) ;
113123 }
114124
115125 // Pre-render (SSG) and App-shell
116126 // 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+ ) {
118132 assert (
119133 indexHtmlOptions ,
120134 'The "index" option is required when using the "ssg" or "appShell" options.' ,
121135 ) ;
122136
123- const {
124- output,
125- warnings,
126- errors,
127- prerenderedRoutes : generatedRoutes ,
128- serializableRouteTreeNode,
129- } = await prerenderPages (
137+ const { output, warnings, errors, serializableRouteTreeNode } = await prerenderPages (
130138 workspaceRoot ,
131139 baseHref ,
132140 appShellOptions ,
133141 prerenderOptions ,
134142 [ ...outputFiles , ...additionalOutputFiles ] ,
135143 assetFiles ,
144+ outputMode ,
136145 sourcemapOptions . scripts ,
137146 maxWorkers ,
138- verbose ,
139147 ) ;
140148
141149 allErrors . push ( ...errors ) ;
142150 allWarnings . push ( ...warnings ) ;
143- prerenderedRoutes . push ( ...Array . from ( generatedRoutes ) ) ;
144-
145- const indexHasBeenPrerendered = generatedRoutes . has ( indexHtmlOptions . output ) ;
146151
152+ const indexHasBeenPrerendered = output [ indexHtmlOptions . output ] ;
147153 for ( const [ path , { content, appShellRoute } ] of Object . entries ( output ) ) {
148154 // Update the index contents with the app shell under these conditions:
149155 // - Replace 'index.html' with the app shell only if it hasn't been prerendered yet.
@@ -155,7 +161,26 @@ export async function executePostBundleSteps(
155161 ) ;
156162 }
157163
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 ) {
159184 // Regenerate the manifest to append route tree. This is only needed if SSR is enabled.
160185 const manifest = additionalOutputFiles . find ( ( f ) => f . path === SERVER_APP_MANIFEST_FILENAME ) ;
161186 assert ( manifest , `${ SERVER_APP_MANIFEST_FILENAME } was not found in output files.` ) ;
@@ -165,7 +190,8 @@ export async function executePostBundleSteps(
165190 additionalHtmlOutputFiles ,
166191 outputFiles ,
167192 optimizationOptions . styles . inlineCritical ?? false ,
168- serializableRouteTreeNode ,
193+ serializableRouteTreeNodeForManifest ,
194+ locale ,
169195 ) ,
170196 ) ;
171197 }
0 commit comments