mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
feat(vue-renderer): support render.ssrLog
for controlling SSR logs (#5784)
This commit is contained in:
parent
fd3ee629fa
commit
21aaef3b48
@ -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'
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ export default () => ({
|
||||
},
|
||||
resourceHints: true,
|
||||
ssr: undefined,
|
||||
ssrLog: undefined,
|
||||
http2: {
|
||||
push: false,
|
||||
shouldPush: null,
|
||||
|
@ -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'
|
||||
|
@ -308,6 +308,7 @@ Object {
|
||||
},
|
||||
"resourceHints": true,
|
||||
"ssr": true,
|
||||
"ssrLog": false,
|
||||
"static": Object {
|
||||
"prefix": true,
|
||||
},
|
||||
|
@ -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,
|
||||
},
|
||||
|
1
packages/config/types/render.d.ts
vendored
1
packages/config/types/render.d.ts
vendored
@ -23,5 +23,6 @@ export interface NuxtConfigurationRender {
|
||||
http2?: any // TBD
|
||||
resourceHints?: boolean
|
||||
ssr?: boolean
|
||||
ssrLog?: boolean | 'collapsed'
|
||||
static?: ServeStaticOptions
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user