fix(nitro): modify contents rather than compiled , remove template compiled (#1154)

This commit is contained in:
Daniel Roe 2021-10-18 10:06:23 +01:00 committed by GitHub
parent d6ad4f3b16
commit f974425cc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -14,6 +14,6 @@ export interface ConfigSchema extends _ConfigSchema {
export interface NuxtOptions extends ConfigSchema { }
type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> | T[P] }
type DeepPartial<T> = T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> | T[P] } : T
export interface NuxtConfig extends DeepPartial<ConfigSchema> { }

View File

@ -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)

View File

@ -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
@ -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> {}

View File

@ -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')