diff --git a/lib/builder/webpack/client.config.js b/lib/builder/webpack/client.config.js index c32348747c..c2b92005a4 100644 --- a/lib/builder/webpack/client.config.js +++ b/lib/builder/webpack/client.config.js @@ -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' }) ) diff --git a/lib/core/renderer.js b/lib/core/renderer.js index b2c0b0ba51..c3bbe7205f 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -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 = '
' + 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 += `` 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,