Skip to content

Commit 53a5d30

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

3 files changed

Lines changed: 15 additions & 39 deletions

File tree

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,17 @@ export async function normalizeOptions(
267267
options.ssr = false;
268268
}
269269

270-
// Of the "prerender" option, only "format" is considered when pages are prerendered.
271-
if (options.prerender !== undefined) {
272-
if (!options.server || typeof options.prerender !== 'object') {
273-
context.logger.warn(
274-
'The "prerender" option is not considered when "outputMode" is specified.',
275-
);
276-
} else if (
270+
// "prerender.format" is considered when pages are prerendered.
271+
if (
272+
options.prerender !== undefined &&
273+
(!options.server ||
274+
typeof options.prerender !== 'object' ||
277275
options.prerender.routesFile !== undefined ||
278-
options.prerender.discoverRoutes === false
279-
) {
280-
context.logger.warn(
281-
'The "prerender.routesFile" and "prerender.discoverRoutes" options are not considered ' +
282-
'when "outputMode" is specified.',
283-
);
284-
}
276+
options.prerender.discoverRoutes === false)
277+
) {
278+
context.logger.warn(
279+
'The "prerender" option is not considered when "outputMode" is specified.',
280+
);
285281
}
286282

287283
options.prerender = !!options.server;
@@ -361,8 +357,7 @@ export async function normalizeOptions(
361357
if (prerenderFormat === PrerenderFormat.File && !outputOptions.ignoreServer) {
362358
// The server runtime of '@angular/ssr' looks up prerendered pages as '<route>/index.html'.
363359
context.logger.warn(
364-
'The "prerender.format" option set to "file" is not considered when the build produces a ' +
365-
'server ("outputMode" set to "server", or "ssr" without "outputMode").',
360+
'The "prerender.format" option is not considered when the build produces a server.',
366361
);
367362

368363
prerenderFormat = PrerenderFormat.Directory;

‎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
@@ -128,7 +128,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
128128

129129
expectLog(
130130
logs,
131-
'The "prerender.format" option set to "file" is not considered when the build produces a server',
131+
'The "prerender.format" option is not considered when the build produces a server.',
132132
);
133133

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

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ import {
1717
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-files';
1818
import { assertIsError } from '../error';
1919
import { toPosixPath } from '../path';
20-
import {
21-
addLeadingSlash,
22-
addTrailingSlash,
23-
joinUrlParts,
24-
stripLeadingSlash,
25-
stripTrailingSlash,
26-
} from '../url';
20+
import { addLeadingSlash, addTrailingSlash, joinUrlParts, stripLeadingSlash } from '../url';
2721
import { WorkerPool } from '../worker-pool';
2822
import {
2923
IMPORT_EXEC_ARGV,
@@ -57,8 +51,6 @@ type AppShellOptions = NormalizedApplicationBuildOptions['appShellOptions'];
5751
* '/index.html': { content: '<html>...</html>', appShell: false },
5852
* '/shell/index.html': { content: '<html>...</html>', appShellRoute: true }
5953
* }
60-
*
61-
* With the 'file' format, non-root routes are keyed as `<route>.html` (e.g. 'shell.html').
6254
*/
6355
type PrerenderOutput = Record<string, { content: string; appShellRoute: boolean }>;
6456

@@ -467,22 +459,11 @@ function getRouteWithoutBaseHref(route: string, baseHrefPathname: string): strin
467459
: route;
468460
}
469461

470-
/**
471-
* Returns the output file path of a prerendered route, relative to the browser output directory.
472-
*
473-
* - `directory`: `/foo/bar` is written to `foo/bar/index.html`.
474-
* - `file`: `/foo/bar` is written to `foo/bar.html`.
475-
*
476-
* The root route (after removing the `baseHref`) is written to `index.html` in both formats.
477-
*/
478462
function getRouteOutPath(route: string, baseHrefPathname: string, format: PrerenderFormat): string {
479463
const routeWithoutBaseHref = getRouteWithoutBaseHref(route, baseHrefPathname);
480464

481-
if (format === PrerenderFormat.File) {
482-
const routePath = stripTrailingSlash(posix.normalize(addLeadingSlash(routeWithoutBaseHref)));
483-
if (routePath !== '/') {
484-
return `${stripLeadingSlash(routePath)}.html`;
485-
}
465+
if (format === PrerenderFormat.File && routeWithoutBaseHref !== '/') {
466+
return stripLeadingSlash(`${routeWithoutBaseHref}.html`);
486467
}
487468

488469
return stripLeadingSlash(posix.join(routeWithoutBaseHref, 'index.html'));

0 commit comments

Comments
 (0)