Skip to content

Commit 13f8dea

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

7 files changed

Lines changed: 64 additions & 384 deletions

File tree

‎goldens/public-api/angular/build/index.api.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export type ApplicationBuilderOptions = {
5555
poll?: number;
5656
polyfills?: string[];
5757
prerender?: PrerenderUnion;
58-
prerenderFormat?: PrerenderFormat;
5958
preserveSymlinks?: boolean;
6059
progress?: boolean;
6160
scripts?: ScriptElement[];
@@ -168,7 +167,7 @@ export function executeUnitTestBuilder(options: UnitTestBuilderOptions, context:
168167
// @public
169168
export type ExtractI18nBuilderOptions = {
170169
buildTarget?: string;
171-
format?: Format;
170+
format?: Format_2;
172171
i18nDuplicateTranslation?: I18NDuplicateTranslation;
173172
outFile?: string;
174173
outputPath?: string;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export async function executePostBundleSteps(
170170
assetFiles,
171171
outputMode,
172172
prerenderFormat,
173-
indexHtmlOptions.output,
174173
sourcemapOptions.scripts,
175174
maxWorkers,
176175
);

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
OutputMode,
3333
OutputPathClass,
3434
Platform,
35-
PrerenderFormat,
35+
Format as PrerenderFormat,
3636
} from './schema';
3737

3838
/**
@@ -258,15 +258,30 @@ export async function normalizeOptions(
258258
}
259259
}
260260

261+
let prerenderFormat =
262+
(typeof options.prerender === 'object' && options.prerender.format) ||
263+
PrerenderFormat.Directory;
264+
261265
if (options.outputMode) {
262266
if (!options.server) {
263267
options.ssr = false;
264268
}
265269

270+
// Of the "prerender" option, only "format" is considered when pages are prerendered.
266271
if (options.prerender !== undefined) {
267-
context.logger.warn(
268-
'The "prerender" option is not considered when "outputMode" is specified.',
269-
);
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 (
277+
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+
}
270285
}
271286

272287
options.prerender = !!options.server;
@@ -343,16 +358,12 @@ export async function normalizeOptions(
343358
options.outputMode === OutputMode.Static,
344359
};
345360

346-
let prerenderFormat = options.prerenderFormat ?? PrerenderFormat.Directory;
347361
if (prerenderFormat === PrerenderFormat.File && !outputOptions.ignoreServer) {
348362
// The server runtime of '@angular/ssr' looks up prerendered pages as '<route>/index.html'.
349-
// The warning is only relevant when pages are actually prerendered, which the dev-server skips.
350-
if ((prerenderOptions || appShellOptions) && !(options.partialSSRBuild || usePartialSsrBuild)) {
351-
context.logger.warn(
352-
'The "prerenderFormat" option set to "file" is not considered when the build produces a ' +
353-
'server ("outputMode" set to "server", or "ssr" without "outputMode").',
354-
);
355-
}
363+
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").',
366+
);
356367

357368
prerenderFormat = PrerenderFormat.Directory;
358369
}

‎packages/angular/build/src/builders/application/schema.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,18 +581,18 @@
581581
"type": "boolean",
582582
"description": "Whether the builder should process the Angular Router configuration to find all unparameterized routes and prerender them.",
583583
"default": true
584+
},
585+
"format": {
586+
"type": "string",
587+
"description": "Defines the file layout of prerendered pages. 'directory': '/foo' is written to 'foo/index.html'. 'file': '/foo' is written to 'foo.html', which some hosting services serve for '/foo' without a redirect to '/foo/'. The root route of the application and of each locale is always written to 'index.html'. Only considered when the build does not produce a server.",
588+
"enum": ["directory", "file"],
589+
"default": "directory"
584590
}
585591
},
586592
"additionalProperties": false
587593
}
588594
]
589595
},
590-
"prerenderFormat": {
591-
"type": "string",
592-
"description": "Defines the file layout of prerendered (SSG) pages. 'directory': '/foo' is written to 'foo/index.html'. 'file': '/foo' is written to 'foo.html', which some hosting services serve for '/foo' without a redirect to '/foo/'. The root route of the application and of each locale is always written to 'index.html'. Routes that cannot be written safely to '<route>.html' keep '<route>/index.html' with a warning. Only considered when the build does not produce a server.",
593-
"enum": ["directory", "file"],
594-
"default": "directory"
595-
},
596596
"ssr": {
597597
"description": "Server side render (SSR) pages of your application during runtime.",
598598
"default": false,

0 commit comments

Comments
 (0)