mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-28 22:32:42 +00:00
feat: basic support for ssr:false
This commit is contained in:
parent
e4e9149b54
commit
c348d83120
@ -66,7 +66,8 @@ export default function webpackClientConfig () {
|
||||
config.plugins.push(
|
||||
new HTMLPlugin({
|
||||
template: this.options.appTemplatePath,
|
||||
inject: false
|
||||
inject: this.options.render.ssr === false,
|
||||
chunksSortMode: 'dependency'
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -120,7 +120,16 @@ export default class Renderer extends Tapable {
|
||||
}
|
||||
}
|
||||
|
||||
get noSSR () {
|
||||
return this.options.render.ssr === false
|
||||
}
|
||||
|
||||
createRenderer () {
|
||||
// Skip if SSR is disabled
|
||||
if (this.noSSR) {
|
||||
return
|
||||
}
|
||||
|
||||
// If resources are not yet provided
|
||||
if (!this.resources.serverBundle || !this.resources.clientManifest) {
|
||||
return
|
||||
@ -294,7 +303,7 @@ export default class Renderer extends Tapable {
|
||||
|
||||
async renderRoute (url, context = {}) {
|
||||
/* istanbul ignore if */
|
||||
if (!this.bundleRenderer || !this.resources.appTemplate) {
|
||||
if (!(this.noSSR || this.bundleRenderer) || !this.resources.appTemplate) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(this.renderRoute(url, context)), 1000)
|
||||
})
|
||||
@ -307,6 +316,23 @@ export default class Renderer extends Tapable {
|
||||
context.url = url
|
||||
context.isServer = true
|
||||
|
||||
// Basic response if SSR is disabled
|
||||
if (this.noSSR) {
|
||||
let APP = '<div id="__nuxt"></div>'
|
||||
let HEAD = ''
|
||||
|
||||
let html = this.resources.appTemplate({
|
||||
HTML_ATTRS: '',
|
||||
BODY_ATTRS: '',
|
||||
HEAD,
|
||||
APP
|
||||
})
|
||||
|
||||
return {
|
||||
html
|
||||
}
|
||||
}
|
||||
|
||||
// Call renderToString from the bundleRenderer and generate the HTML (will update the context as well)
|
||||
let APP = await this.bundleRenderer.renderToString(context)
|
||||
|
||||
@ -333,7 +359,7 @@ export default class Renderer extends Tapable {
|
||||
APP += `</script>`
|
||||
APP += context.renderScripts()
|
||||
|
||||
const html = this.resources.appTemplate({
|
||||
let html = this.resources.appTemplate({
|
||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||
BODY_ATTRS: m.bodyAttrs.text(),
|
||||
HEAD,
|
||||
|
Loading…
Reference in New Issue
Block a user