mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
fix(nuxt3): directly emit document.template.mjs
(#4360)
This commit is contained in:
parent
20e09d6203
commit
14d9e8e4ae
@ -1,5 +1,4 @@
|
||||
import { existsSync, promises as fsp } from 'fs'
|
||||
import { dirname } from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import { resolve, join } from 'pathe'
|
||||
import { createNitro, createDevServer, build, prepare, copyPublicAssets, writeTypes, scanHandlers, prerender } from 'nitropack'
|
||||
import type { NitroEventHandler, NitroDevEventHandler, NitroConfig } from 'nitropack'
|
||||
@ -138,7 +137,6 @@ export async function initNitro (nuxt: Nuxt) {
|
||||
|
||||
// nuxt build/dev
|
||||
nuxt.hook('build:done', async () => {
|
||||
await writeDocumentTemplate(nuxt)
|
||||
if (nuxt.options.dev) {
|
||||
await build(nitro)
|
||||
} else {
|
||||
@ -192,17 +190,3 @@ async function resolveHandlers (nuxt: Nuxt) {
|
||||
devHandlers
|
||||
}
|
||||
}
|
||||
|
||||
async function writeDocumentTemplate (nuxt: Nuxt) {
|
||||
// Compile html template
|
||||
const src = resolve(nuxt.options.buildDir, 'views/app.template.html')
|
||||
const dst = src.replace(/.html$/, '.mjs').replace('app.template.mjs', 'document.template.mjs')
|
||||
const contents = nuxt.vfs[src] || await fsp.readFile(src, 'utf-8').catch(() => '')
|
||||
if (contents) {
|
||||
const compiled = 'export default ' +
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
`(params) => \`${contents.replace(/{{ (\w+) }}/g, '${params.$1}')}\``
|
||||
await fsp.mkdir(dirname(dst), { recursive: true })
|
||||
await fsp.writeFile(dst, compiled, 'utf8')
|
||||
}
|
||||
}
|
||||
|
@ -71,20 +71,21 @@ export const serverPluginTemplate = {
|
||||
}
|
||||
|
||||
export const appViewTemplate = {
|
||||
filename: 'views/app.template.html',
|
||||
filename: 'views/document.template.mjs',
|
||||
write: true,
|
||||
getContents () {
|
||||
return `<!DOCTYPE html>
|
||||
<html {{ HTML_ATTRS }}>
|
||||
return `export default (params) => \`<!DOCTYPE html>
|
||||
<html \${params.HTML_ATTRS}>
|
||||
|
||||
<head {{ HEAD_ATTRS }}>
|
||||
{{ HEAD }}
|
||||
<head \${params.HEAD_ATTRS}>
|
||||
\${params.HEAD}
|
||||
</head>
|
||||
|
||||
<body {{ BODY_ATTRS }}>{{ BODY_PREPEND }}
|
||||
{{ APP }}
|
||||
<body \${params.BODY_ATTRS}>\${params.BODY_PREPEND}
|
||||
\${params.APP}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>\`
|
||||
`
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user