Skip to content

Commit 7ccd292

Browse files
committed
fixup! feat(@angular/build): add prerender.format option to prerender routes as <route>.html
1 parent 53a5d30 commit 7ccd292

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎packages/angular/build/src/builders/application/execute-post-bundle.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export async function executePostBundleSteps(
7171
outputMode,
7272
serverEntryPoint,
7373
prerenderOptions,
74-
prerenderFormat,
7574
appShellOptions,
7675
publicPath,
7776
workspaceRoot,
@@ -169,7 +168,6 @@ export async function executePostBundleSteps(
169168
[...outputFiles, ...additionalOutputFiles],
170169
assetFiles,
171170
outputMode,
172-
prerenderFormat,
173171
sourcemapOptions.scripts,
174172
maxWorkers,
175173
);

‎packages/angular/build/src/builders/application/options.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export async function normalizeOptions(
258258
}
259259
}
260260

261-
let prerenderFormat =
261+
const prerenderFormat =
262262
(typeof options.prerender === 'object' && options.prerender.format) ||
263263
PrerenderFormat.Directory;
264264

@@ -267,16 +267,15 @@ export async function normalizeOptions(
267267
options.ssr = false;
268268
}
269269

270-
// "prerender.format" is considered when pages are prerendered.
270+
// Values are compared, as schema defaults are added to the "prerender" object.
271271
if (
272272
options.prerender !== undefined &&
273-
(!options.server ||
274-
typeof options.prerender !== 'object' ||
273+
(typeof options.prerender !== 'object' ||
275274
options.prerender.routesFile !== undefined ||
276275
options.prerender.discoverRoutes === false)
277276
) {
278277
context.logger.warn(
279-
'The "prerender" option is not considered when "outputMode" is specified.',
278+
'The "prerender" option has no effect when "outputMode" is specified (only "format" is supported).',
280279
);
281280
}
282281

@@ -314,6 +313,7 @@ export async function normalizeOptions(
314313
prerenderOptions = {
315314
discoverRoutes,
316315
routesFile: routesFile && path.join(workspaceRoot, routesFile),
316+
format: prerenderFormat,
317317
};
318318
}
319319

@@ -354,13 +354,13 @@ export async function normalizeOptions(
354354
options.outputMode === OutputMode.Static,
355355
};
356356

357-
if (prerenderFormat === PrerenderFormat.File && !outputOptions.ignoreServer) {
357+
if (prerenderOptions?.format === PrerenderFormat.File && !outputOptions.ignoreServer) {
358358
// The server runtime of '@angular/ssr' looks up prerendered pages as '<route>/index.html'.
359359
context.logger.warn(
360360
'The "prerender.format" option is not considered when the build produces a server.',
361361
);
362362

363-
prerenderFormat = PrerenderFormat.Directory;
363+
prerenderOptions.format = PrerenderFormat.Directory;
364364
}
365365

366366
const outputNames = {
@@ -513,7 +513,6 @@ export async function normalizeOptions(
513513
subresourceIntegrity,
514514
serverEntryPoint,
515515
prerenderOptions,
516-
prerenderFormat,
517516
appShellOptions,
518517
outputMode,
519518
ssrOptions,

‎packages/angular/build/src/builders/application/tests/options/prerender-format_spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
8080

8181
const { result, logs } = await harness.executeOnce();
8282
expect(result?.success).toBeTrue();
83-
expectNoLog(logs, 'The "prerender" option is not considered');
83+
expectNoLog(logs, 'The "prerender" option has no effect');
8484

8585
harness.expectFile('dist/browser/index.html').content.toContain('home works!');
8686
harness.expectFile('dist/browser/foo.html').content.toContain('foo works!');

‎packages/angular/build/src/utils/server-rendering/prerender.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export async function prerenderPages(
6262
outputFiles: Readonly<BuildOutputFile[]>,
6363
assets: Readonly<BuildOutputAsset[]>,
6464
outputMode: OutputMode | undefined,
65-
format: PrerenderFormat,
6665
sourcemap = false,
6766
maxThreads = 1,
6867
): Promise<{
@@ -201,7 +200,7 @@ export async function prerenderPages(
201200
outputFilesForWorker,
202201
assetsReversed,
203202
outputMode,
204-
format,
203+
prerenderOptions?.format,
205204
appShellRoute ?? appShellOptions?.route,
206205
);
207206

@@ -211,7 +210,11 @@ export async function prerenderPages(
211210
const baseHrefPathnameWithLeadingSlash = new URL(baseHref, 'http://localhost').pathname;
212211

213212
for (const metadata of serializableRouteTreeNodeForPrerender) {
214-
const outPath = getRouteOutPath(metadata.route, baseHrefPathnameWithLeadingSlash, format);
213+
const outPath = getRouteOutPath(
214+
metadata.route,
215+
baseHrefPathnameWithLeadingSlash,
216+
prerenderOptions?.format,
217+
);
215218

216219
if (output[outPath]) {
217220
prerenderedRoutes[metadata.route] = { headers: metadata.headers };
@@ -236,7 +239,7 @@ async function renderPages(
236239
outputFilesForWorker: Record<string, Uint8Array>,
237240
assetFilesForWorker: Record<string, string>,
238241
outputMode: OutputMode | undefined,
239-
format: PrerenderFormat,
242+
format: PrerenderFormat | undefined,
240243
appShellRoute: string | undefined,
241244
): Promise<{
242245
output: PrerenderOutput;
@@ -459,7 +462,11 @@ function getRouteWithoutBaseHref(route: string, baseHrefPathname: string): strin
459462
: route;
460463
}
461464

462-
function getRouteOutPath(route: string, baseHrefPathname: string, format: PrerenderFormat): string {
465+
function getRouteOutPath(
466+
route: string,
467+
baseHrefPathname: string,
468+
format: PrerenderFormat | undefined,
469+
): string {
463470
const routeWithoutBaseHref = getRouteWithoutBaseHref(route, baseHrefPathname);
464471

465472
if (format === PrerenderFormat.File && routeWithoutBaseHref !== '/') {

0 commit comments

Comments
 (0)