Skip to content

Commit

Permalink
fix: compatibility with nitro binary rendering (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 30, 2022
1 parent 6c63cc1 commit f63f38a
Show file tree
Hide file tree
Showing 3 changed files with 613 additions and 650 deletions.
11 changes: 8 additions & 3 deletions src/module.ts
Expand Up @@ -17,7 +17,7 @@ export default defineNuxtModule<ModuleOptions>({
preload: 'media',
},
},
setup(options, nuxt) {
setup (options, nuxt) {
// Only enable for production
if (nuxt.options.dev) return

Expand All @@ -33,8 +33,13 @@ export default defineNuxtModule<ModuleOptions>({
...options.config,
})
nitro.hooks.hook('prerender:generate', async route => {
if (!route.contents || !route.fileName?.endsWith('.html')) return
route.contents = await critters.process(route.contents)
if (!route.fileName?.endsWith('.html')) return
if ('data' in route) {
const contents = new TextDecoder('utf-8').decode(new Uint8Array(route.data!))
route.data = new TextEncoder().encode(await critters.process(contents))
} else if (route.contents) {
route.contents = await critters.process(route.contents!)
}
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/generate.spec.ts
Expand Up @@ -10,7 +10,7 @@ await setup({
})

describe('module in generated pages', () => {
it('enables extractCSS', async () => {
it('processes generated index.html', async () => {
const ctx = useTestContext()
const body = await fsp.readFile(
resolve(ctx.nuxt!.options.nitro.output?.dir || '', 'public/index.html'),
Expand Down

0 comments on commit f63f38a

Please sign in to comment.