diff --git a/examples/meta-info/nuxt.config.js b/examples/meta-info/nuxt.config.js index eb1d1a0265..941b70d4c6 100644 --- a/examples/meta-info/nuxt.config.js +++ b/examples/meta-info/nuxt.config.js @@ -6,5 +6,8 @@ export default { { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: 'Meta description' } ] + }, + render: { + ssrLog: 'collapsed' } } diff --git a/packages/config/src/config/render.js b/packages/config/src/config/render.js index 1f9087996d..957d71a83c 100644 --- a/packages/config/src/config/render.js +++ b/packages/config/src/config/render.js @@ -8,6 +8,7 @@ export default () => ({ }, resourceHints: true, ssr: undefined, + ssrLog: undefined, http2: { push: false, shouldPush: null, diff --git a/packages/config/src/options.js b/packages/config/src/options.js index 67df5c6664..638c9855b2 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -299,6 +299,10 @@ export function getNuxtConfig(_options) { options.pageTransition.appear = true } + options.render.ssrLog = options.dev + ? options.render.ssrLog === undefined || options.render.ssrLog + : false + // We assume the SPA fallback path is 404.html (for GitHub Pages, Surge, etc.) if (options.generate.fallback === true) { options.generate.fallback = '404.html' diff --git a/packages/config/test/__snapshots__/options.test.js.snap b/packages/config/test/__snapshots__/options.test.js.snap index b8d3dd436a..e1418d9465 100644 --- a/packages/config/test/__snapshots__/options.test.js.snap +++ b/packages/config/test/__snapshots__/options.test.js.snap @@ -308,6 +308,7 @@ Object { }, "resourceHints": true, "ssr": true, + "ssrLog": false, "static": Object { "prefix": true, }, diff --git a/packages/config/test/config/__snapshots__/index.test.js.snap b/packages/config/test/config/__snapshots__/index.test.js.snap index 87026a0d0e..12f0738e41 100644 --- a/packages/config/test/config/__snapshots__/index.test.js.snap +++ b/packages/config/test/config/__snapshots__/index.test.js.snap @@ -275,6 +275,7 @@ Object { }, "resourceHints": true, "ssr": undefined, + "ssrLog": undefined, "static": Object { "prefix": true, }, @@ -609,6 +610,7 @@ Object { }, "resourceHints": true, "ssr": undefined, + "ssrLog": undefined, "static": Object { "prefix": true, }, diff --git a/packages/config/types/render.d.ts b/packages/config/types/render.d.ts index 345028f5ae..08ee6cea68 100644 --- a/packages/config/types/render.d.ts +++ b/packages/config/types/render.d.ts @@ -23,5 +23,6 @@ export interface NuxtConfigurationRender { http2?: any // TBD resourceHints?: boolean ssr?: boolean + ssrLog?: boolean | 'collapsed' static?: ServeStaticOptions } diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index 07a1cae970..2048eab8a9 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -37,10 +37,10 @@ const NUXT = window.<%= globals.context %> || {} Object.assign(Vue.config, <%= serialize(vue.config) %>)<%= isTest ? '// eslint-disable-line' : '' %> -<% if (isDev) { %> +<% if (nuxtOptions.render.ssrLog) { %> const logs = NUXT.logs || [] if (logs.length > 0) { - console.group("%c🚀 Nuxt.js SSR Logs", 'font-size: 110%') + console.group<%= nuxtOptions.render.ssrLog === 'collapsed' ? 'Collapsed' : '' %>("%c🚀 Nuxt.js SSR Logs", 'font-size: 110%') const logger = consola.withScope('nuxt:ssr') logs.forEach(logObj => logger[logObj.type](logObj)) delete NUXT.logs diff --git a/packages/vue-renderer/src/renderers/ssr.js b/packages/vue-renderer/src/renderers/ssr.js index 0e727be744..0cfcc50954 100644 --- a/packages/vue-renderer/src/renderers/ssr.js +++ b/packages/vue-renderer/src/renderers/ssr.js @@ -39,7 +39,10 @@ export default class SSRRenderer extends BaseRenderer { ) } - async devRenderToString(renderContext) { + useSSRLog() { + if (!this.options.render.ssrLog) { + return + } const logs = [] const devReporter = { log(logObj) { @@ -50,19 +53,25 @@ export default class SSRRenderer extends BaseRenderer { } } consola.addReporter(devReporter) - const APP = await this.vueRenderer.renderToString(renderContext) - consola.removeReporter(devReporter) - renderContext.nuxt.logs = logs - return APP + return () => { + consola.removeReporter(devReporter) + return logs + } } async render(renderContext) { // Call ssr:context hook to extend context from modules await this.serverContext.nuxt.callHook('vue-renderer:ssr:prepareContext', renderContext) + const getSSRLog = this.useSSRLog() + // Call Vue renderer renderToString - let APP = await (this.options.dev ? this.devRenderToString(renderContext) : this.vueRenderer.renderToString(renderContext)) + let APP = await this.vueRenderer.renderToString(renderContext) + + if (typeof getSSRLog === 'function') { + renderContext.nuxt.logs = getSSRLog() + } // Call ssr:context hook await this.serverContext.nuxt.callHook('vue-renderer:ssr:context', renderContext)