fix(vite): improve logs for client vs server (#3634)

This commit is contained in:
Sébastien Chopin 2022-03-14 11:19:37 +01:00 committed by GitHub
parent e891ea0cca
commit 570016c143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View File

@ -184,7 +184,7 @@ export interface NuxtHooks {
// vite
'vite:extend': (viteBuildContext: { nuxt: Nuxt, config: any }) => HookResult
'vite:extendConfig': (viteInlineConfig: any, env: { isClient: boolean, isServer: boolean }) => HookResult
'vite:serverCreated': (viteServer: any) => HookResult
'vite:serverCreated': (viteServer: any, env: { isClient: boolean, isServer: boolean }) => HookResult
}
export type NuxtHookName = keyof NuxtHooks

View File

@ -62,7 +62,7 @@ export async function buildClient (ctx: ViteBuildContext) {
const viteServer = await vite.createServer(clientConfig)
ctx.clientServer = viteServer
await ctx.nuxt.callHook('vite:serverCreated', viteServer)
await ctx.nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false })
const viteMiddleware: Connect.NextHandleFunction = (req, res, next) => {
// Workaround: vite devmiddleware modifies req.url

View File

@ -131,7 +131,7 @@ export async function buildServer (ctx: ViteBuildContext) {
const viteServer = await vite.createServer(serverConfig)
ctx.ssrServer = viteServer
await ctx.nuxt.callHook('vite:serverCreated', viteServer)
await ctx.nuxt.callHook('vite:serverCreated', viteServer, { isClient: false, isServer: true })
// Close server on exit
ctx.nuxt.hook('close', () => viteServer.close())
@ -140,7 +140,7 @@ export async function buildServer (ctx: ViteBuildContext) {
await viteServer.pluginContainer.buildStart({})
if (ctx.nuxt.options.experimental.viteNode) {
logger.info('Using experimental vite-node server...')
logger.info('Vite server using experimental `vite-node`...')
await prepareDevServerEntry(ctx)
} else {
// Build and watch

View File

@ -86,7 +86,7 @@ export async function bundle (nuxt: Nuxt) {
await nuxt.callHook('vite:extend', ctx)
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => {
// Invalidate virtual modules when templates are re-generated
ctx.nuxt.hook('app:templatesGenerated', () => {
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
@ -98,7 +98,7 @@ export async function bundle (nuxt: Nuxt) {
const start = Date.now()
warmupViteServer(server, ['/entry.mjs'])
.then(() => logger.info(`Vite warmed up in ${Date.now() - start}ms`))
.then(() => logger.info(`Vite ${env.isClient ? 'client' : 'server'} warmed up in ${Date.now() - start}ms`))
.catch(logger.error)
})