mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +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(
|
config.plugins.push(
|
||||||
new HTMLPlugin({
|
new HTMLPlugin({
|
||||||
template: this.options.appTemplatePath,
|
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 () {
|
createRenderer () {
|
||||||
|
// Skip if SSR is disabled
|
||||||
|
if (this.noSSR) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// If resources are not yet provided
|
// If resources are not yet provided
|
||||||
if (!this.resources.serverBundle || !this.resources.clientManifest) {
|
if (!this.resources.serverBundle || !this.resources.clientManifest) {
|
||||||
return
|
return
|
||||||
@ -294,7 +303,7 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
async renderRoute (url, context = {}) {
|
async renderRoute (url, context = {}) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!this.bundleRenderer || !this.resources.appTemplate) {
|
if (!(this.noSSR || this.bundleRenderer) || !this.resources.appTemplate) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => resolve(this.renderRoute(url, context)), 1000)
|
setTimeout(() => resolve(this.renderRoute(url, context)), 1000)
|
||||||
})
|
})
|
||||||
@ -307,6 +316,23 @@ export default class Renderer extends Tapable {
|
|||||||
context.url = url
|
context.url = url
|
||||||
context.isServer = true
|
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)
|
// Call renderToString from the bundleRenderer and generate the HTML (will update the context as well)
|
||||||
let APP = await this.bundleRenderer.renderToString(context)
|
let APP = await this.bundleRenderer.renderToString(context)
|
||||||
|
|
||||||
@ -333,7 +359,7 @@ export default class Renderer extends Tapable {
|
|||||||
APP += `</script>`
|
APP += `</script>`
|
||||||
APP += context.renderScripts()
|
APP += context.renderScripts()
|
||||||
|
|
||||||
const html = this.resources.appTemplate({
|
let html = this.resources.appTemplate({
|
||||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||||
BODY_ATTRS: m.bodyAttrs.text(),
|
BODY_ATTRS: m.bodyAttrs.text(),
|
||||||
HEAD,
|
HEAD,
|
||||||
|
Loading…
Reference in New Issue
Block a user