mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +00:00
fix(nitro): modify contents rather than compiled , remove template compiled
(#1154)
This commit is contained in:
parent
d6ad4f3b16
commit
f974425cc4
@ -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> { }
|
||||
|
@ -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)
|
||||
|
@ -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> {}
|
||||
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user