Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prerender): allow disabling html sub-folders #1676

Merged
merged 7 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const NitroDefaults: NitroConfig = {
},

// Features
experimental: {},
experimental: {
prerenderIndexHTML: true,
},
future: {},
storage: {},
devStorage: {},
Expand Down
6 changes: 5 additions & 1 deletion src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,12 @@ export async function prerender(nitro: Nitro) {
const isImplicitHTML =
!route.endsWith(".html") && contentType.includes("html");
const routeWithIndex = route.endsWith("/") ? route + "index" : route;
const htmlPath =
route.endsWith("/") || nitro.options.experimental.prerenderIndexHTML
pi0 marked this conversation as resolved.
Show resolved Hide resolved
? joinURL(route, "index.html")
: route + ".html";
_route.fileName = withoutBase(
isImplicitHTML ? joinURL(route, "index.html") : routeWithIndex,
isImplicitHTML ? htmlPath : routeWithIndex,
nitro.options.baseURL
);
// Allow overriding content-type in `prerender:generate` hook
Expand Down
3 changes: 3 additions & 0 deletions src/presets/cloudflare-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const cloudflarePages = defineNitroPreset({
publicDir: "{{ output.dir }}",
serverDir: "{{ output.dir }}",
},
experimental: {
prerenderIndexHTML: false,
},
alias: {
// Hotfix: Cloudflare appends /index.html if mime is not found and things like ico are not in standard lite.js!
// https://github.com/unjs/nitro/pull/933
Expand Down
9 changes: 9 additions & 0 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const vercel = defineNitroPreset({
deploy: "",
preview: "",
},
experimental: {
prerenderIndexHTML: false,
},
hooks: {
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
Expand Down Expand Up @@ -102,6 +105,9 @@ export const vercelEdge = defineNitroPreset({
process: undefined,
},
},
experimental: {
prerenderIndexHTML: false,
},
hooks: {
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
Expand Down Expand Up @@ -137,6 +143,9 @@ export const vercelStatic = defineNitroPreset({
commands: {
preview: "npx serve ./static",
},
experimental: {
prerenderIndexHTML: false,
},
hooks: {
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
Expand Down
6 changes: 6 additions & 0 deletions src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ export interface NitroOptions extends PresetOptions {
/** @experimental Requires `experimental.wasm` to be effective */
wasm?: WasmOptions;
experimental?: {
/**
* Prerender HTML routes within subfolders (`/test` would produce `/test/index.html`)
*
* @default true
*/
prerenderIndexHTML?: boolean;
legacyExternals?: boolean;
openAPI?: boolean;
/**
Expand Down
8 changes: 4 additions & 4 deletions test/presets/cloudflare-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ describe("nitro:preset:cloudflare-pages", async () => {
"/build/*",
"/favicon.ico",
"/icon.png",
"/prerender.html",
"/prerender.html.br",
"/prerender.html.gz",
"/api/hello",
"/prerender/index.html",
"/prerender/index.html.br",
"/prerender/index.html.gz",
"/api/hey/index.html",
"/api/hey.html",
"/api/param/foo.json",
"/api/param/hidden",
"/api/param/prerender1",
Expand Down
4 changes: 2 additions & 2 deletions test/presets/vercel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe("nitro:preset:vercel", async () => {
expect(config).toMatchInlineSnapshot(`
{
"overrides": {
"api/hey/index.html": {
"api/hey.html": {
"path": "api/hey",
},
"prerender/index.html": {
"prerender.html": {
"path": "prerender",
},
},
Expand Down