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(vite-plugin-nitro): enable prerendering of root index.html #663

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/vite-plugin-nitro/src/lib/build-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NitroConfig } from 'nitropack';
import * as fs from 'fs';

import { Options } from './options';
import { addPostRenderingHooks } from './hooks/post-rendering-hook';
Expand All @@ -24,6 +25,16 @@ export async function buildServer(
await prepare(nitro);
await copyPublicAssets(nitro);

if (
nitroConfig?.prerender?.routes &&
nitroConfig?.prerender?.routes.find((route) => route === '/')
) {
// Remove the root index.html so it can be replaced with the prerendered version
if (fs.existsSync(`${nitroConfig?.output?.publicDir}/index.html`)) {
fs.unlinkSync(`${nitroConfig?.output?.publicDir}/index.html`);
}
}

console.log(`Prerendering static pages...`);
await prerender(nitro);

Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
...nitroConfig,
});
const server = createDevServer(nitro);
await prepare(nitro);
await build(nitro);
viteServer.middlewares.use(apiPrefix, toNodeListener(server.app));

Expand Down