Skip to content

Commit

Permalink
fix(compat): add template variables for compat module (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 24, 2021
1 parent 05cdd8c commit 126920a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getNitroContext, NitroContext } from './context'
import { createDevServer } from './server/dev'
import { wpfs } from './utils/wpfs'
import { resolveMiddleware } from './server/middleware'
import { serializeTemplate } from './utils'

export default function nuxt2CompatModule () {
const { nuxt } = this
Expand Down Expand Up @@ -51,6 +52,15 @@ export default function nuxt2CompatModule () {
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
this.addPlugin({
fileName: 'nitro.client.js',
Expand Down

0 comments on commit 126920a

Please sign in to comment.