fix(compat): add template variables for compat module (#162)

This commit is contained in:
Daniel Roe 2021-05-24 11:53:04 +01:00 committed by GitHub
parent de22e8f71b
commit f497020f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { getNitroContext, NitroContext } from './context'
import { createDevServer } from './server/dev' import { createDevServer } from './server/dev'
import { wpfs } from './utils/wpfs' import { wpfs } from './utils/wpfs'
import { resolveMiddleware } from './server/middleware' import { resolveMiddleware } from './server/middleware'
import { serializeTemplate } from './utils'
export default function nuxt2CompatModule () { export default function nuxt2CompatModule () {
const { nuxt } = this const { nuxt } = this
@ -51,6 +52,15 @@ export default function nuxt2CompatModule () {
serverConfig.devtool = false serverConfig.devtool = false
}) })
// Add missing template variables (which normally renderer would create)
nitroContext._internal.hooks.hook('nitro:template:document', (htmlTemplate) => {
if (!htmlTemplate.contents.includes('BODY_SCRIPTS_PREPEND')) {
const fullTemplate = ['{{ BODY_SCRIPTS_PREPEND }}', '{{ APP }}', '{{ BODY_SCRIPTS }}'].join('\n ')
htmlTemplate.contents = htmlTemplate.contents.replace('{{ APP }}', fullTemplate)
htmlTemplate.compiled = 'module.exports = ' + serializeTemplate(htmlTemplate.contents)
}
})
// Nitro client plugin // Nitro client plugin
this.addPlugin({ this.addPlugin({
fileName: 'nitro.client.js', fileName: 'nitro.client.js',