feat: Handle body scripts from vue-meta

This commit is contained in:
Atinux 2017-11-06 13:33:19 +01:00
parent 4cfc8f5c49
commit 07eab4c643
2 changed files with 7 additions and 3 deletions

View File

@ -45,7 +45,8 @@ export default class MetaRenderer {
meta = {
HTML_ATTRS: '',
BODY_ATTRS: '',
HEAD: ''
HEAD: '',
BODY_SCRIPTS: ''
}
// Get vue-meta context
const m = await this.getMeta(url)
@ -55,6 +56,8 @@ export default class MetaRenderer {
meta.BODY_ATTRS = m.bodyAttrs.text()
// HEAD tags
meta.HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text()
// BODY_SCRIPTS
meta.BODY_SCRIPTS = m.script.text({ body: true })
// Resources Hints
meta.resourceHints = ''
// Resource Hints

View File

@ -488,8 +488,8 @@ export default class Renderer {
const ENV = this.options.env
if (this.noSSR || spa) {
const { HTML_ATTRS, BODY_ATTRS, HEAD, resourceHints } = await this.metaRenderer.render(context)
const APP = `<div id="__nuxt">${this.resources.loadingHTML}</div>`
const { HTML_ATTRS, BODY_ATTRS, HEAD, BODY_SCRIPTS, resourceHints } = await this.metaRenderer.render(context)
const APP = `<div id="__nuxt">${this.resources.loadingHTML}</div>` + BODY_SCRIPTS
// Detect 404 errors
if (url.includes(this.options.build.publicPath) || url.includes('__webpack')) {
@ -528,6 +528,7 @@ export default class Renderer {
}
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })};</script>`
APP += context.renderScripts()
APP += m.script.text({ body: true })
HEAD += context.renderStyles()