feat(vue-renderer): render.injectScripts option (#5745)

This commit is contained in:
aidou 2019-05-26 02:19:10 +08:00 committed by Pooya Parsa
parent 668db6fbbb
commit 0fc8ee41d1

View File

@ -93,13 +93,16 @@ export default class SSRRenderer extends BaseRenderer {
m.script.text() +
m.noscript.text()
// Check if we need to inject scripts and state
const shouldInjectScripts = this.options.render.injectScripts !== false
// Add <base href=""> meta if router base specified
if (this.options._routerBaseSpecified) {
HEAD += `<base href="${this.options.router.base}">`
}
// Inject resource hints
if (this.options.render.resourceHints) {
if (this.options.render.resourceHints && shouldInjectScripts) {
HEAD += this.renderResourceHints(renderContext)
}
@ -108,7 +111,9 @@ export default class SSRRenderer extends BaseRenderer {
// Serialize state
const serializedSession = `window.${this.serverContext.globals.context}=${devalue(renderContext.nuxt)};`
if (shouldInjectScripts) {
APP += `<script>${serializedSession}</script>`
}
// Calculate CSP hashes
const { csp } = this.options.render
@ -132,7 +137,9 @@ export default class SSRRenderer extends BaseRenderer {
}
// Prepend scripts
if (shouldInjectScripts) {
APP += this.renderScripts(renderContext)
}
APP += m.script.text({ body: true })
APP += m.noscript.text({ body: true })