Skip to content

Commit

Permalink
fix(vite-plugin-nitro): enable prerendering of root index.html (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Sep 21, 2023
1 parent 875f4e8 commit c231f56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit c231f56

Please sign in to comment.