Skip to content

Commit

Permalink
fix(nitro): modify contents rather than compiled , remove template `c…
Browse files Browse the repository at this point in the history
…ompiled` (#1154)
  • Loading branch information
danielroe authored Oct 18, 2021
1 parent 5036c02 commit 5d7740c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export async function generate (nitroContext: NitroContext) {
export async function build (nitroContext: NitroContext) {
// Compile html template
const htmlSrc = resolve(nitroContext._nuxt.buildDir, `views/${{ 2: 'app', 3: 'document' }[2]}.template.html`)
const htmlTemplate = { src: htmlSrc, contents: '', dst: '', compiled: '' }
const htmlTemplate = { src: htmlSrc, contents: '', dst: '' }
htmlTemplate.dst = htmlTemplate.src.replace(/.html$/, '.mjs').replace('app.', 'document.')
htmlTemplate.contents = nitroContext.vfs[htmlTemplate.src] || await fse.readFile(htmlTemplate.src, 'utf-8')
await nitroContext._internal.hooks.callHook('nitro:document', htmlTemplate)
htmlTemplate.compiled = 'export default ' + serializeTemplate(htmlTemplate.contents)
await writeFile(htmlTemplate.dst, htmlTemplate.compiled)
const compiled = 'export default ' + serializeTemplate(htmlTemplate.contents)
await writeFile(htmlTemplate.dst, compiled)

nitroContext.rollupConfig = getRollupConfig(nitroContext)
await nitroContext._internal.hooks.callHook('nitro:rollup:before', nitroContext)
Expand Down
4 changes: 2 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { Options as EsbuildOptions } from './rollup/plugins/esbuild'
import { runtimeDir } from './dirs'

export interface NitroHooks {
'nitro:document': (htmlTemplate: { src: string, contents: string, dst: string, compiled: string }) => void
'nitro:document': (htmlTemplate: { src: string, contents: string, dst: string }) => void
'nitro:rollup:before': (context: NitroContext) => void | Promise<void>
'nitro:compiled': (context: NitroContext) => void
'close': () => void
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface NitroContext {
}
}

type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> }
type DeepPartial<T> = T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> | T[P] } : T

export interface NitroInput extends DeepPartial<NitroContext> {}

Expand Down
2 changes: 1 addition & 1 deletion src/presets/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if ('serviceWorker' in navigator) {
},
hooks: {
'nitro:document' (tmpl) {
tmpl.compiled = tmpl.compiled.replace('</body>', script + '</body>')
tmpl.contents = tmpl.contents.replace('</body>', script + '</body>')
},
async 'nitro:compiled' ({ output }: NitroContext) {
await fsp.writeFile(resolve(output.publicDir, 'sw.js'), `self.importScripts('${input._nuxt.routerBase}_server/index.mjs');`, 'utf8')
Expand Down

0 comments on commit 5d7740c

Please sign in to comment.