Skip to content

Commit d385469

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

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,9 @@ export async function normalizeOptions(
267267
options.ssr = false;
268268
}
269269

270-
// Values are compared, as schema defaults are added to the "prerender" object.
271270
if (
272271
options.prerender !== undefined &&
273-
(typeof options.prerender !== 'object' ||
274-
options.prerender.routesFile !== undefined ||
275-
options.prerender.discoverRoutes === false)
272+
(typeof options.prerender === 'boolean' || !('format' in options.prerender))
276273
) {
277274
context.logger.warn(
278275
'The "prerender" option has no effect when "outputMode" is specified (only "format" is supported).',

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,21 @@
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-
},
584+
}
585+
},
586+
"additionalProperties": false
587+
},
588+
{
589+
"type": "object",
590+
"properties": {
585591
"format": {
586592
"type": "string",
587593
"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"
594+
"enum": ["directory", "file"]
590595
}
591596
},
592-
"additionalProperties": false
597+
"additionalProperties": false,
598+
"required": ["format"]
593599
}
594600
]
595601
},

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
9696
);
9797
});
9898

99+
it(`should warn when 'prerender' is an object without 'format' and 'outputMode' is specified`, async () => {
100+
harness.useTarget('build', {
101+
...BASE_OPTIONS,
102+
server: 'src/main.server.ts',
103+
polyfills: ['zone.js'],
104+
outputMode: OutputMode.Static,
105+
prerender: { routesFile: 'routes.txt' },
106+
});
107+
108+
const { result, logs } = await harness.executeOnce();
109+
expect(result?.success).toBeTrue();
110+
111+
expectLog(logs, 'The "prerender" option has no effect when "outputMode" is specified');
112+
});
113+
99114
it(`should write routes to '<route>/index.html' by default`, async () => {
100115
harness.useTarget('build', {
101116
...BASE_OPTIONS,

0 commit comments

Comments
 (0)