Skip to content

Commit 2c43bbb

Browse files
committed
fix: ensure we have index.html after static generation
resolves #237
1 parent b100399 commit 2c43bbb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/module.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,29 @@ export default defineNuxtModule<ModuleOptions>({
155155
})
156156
)
157157

158+
if (nuxt.options._generate) {
159+
nuxt.hook('nitro:config', config => {
160+
config.prerender ||= {}
161+
config.prerender.routes ||= []
162+
config.prerender.routes.push('/200.html')
163+
})
164+
165+
// Ensure there is an index.html file present when doing static file generation
166+
let publicFolder: string
167+
nuxt.hook('nitro:init', nitro => {
168+
publicFolder = nitro.options.output.publicDir
169+
})
170+
171+
nuxt.hook('close', async () => {
172+
const indexFile = join(publicFolder, 'index.html')
173+
const fallbackFile = join(publicFolder, '200.html')
174+
175+
if (!existsSync(indexFile) && existsSync(fallbackFile)) {
176+
await fsp.copyFile(fallbackFile, indexFile)
177+
}
178+
})
179+
}
180+
158181
const { setupBasic, setupCore, setupUtilities } = useCSSSetup()
159182

160183
// Add Ionic Core CSS

0 commit comments

Comments
 (0)