From 570016c143d321a78deb1d2fb3abc2238b1b731a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 14 Mar 2022 11:19:37 +0100 Subject: [PATCH] fix(vite): improve logs for client vs server (#3634) --- packages/schema/src/types/hooks.ts | 2 +- packages/vite/src/client.ts | 2 +- packages/vite/src/server.ts | 4 ++-- packages/vite/src/vite.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index f0d8dd70ad..c5dff3e41e 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -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 diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index d3bb726489..99d803b54d 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -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 diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index 0e73fe3fbf..149e96e7db 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -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 diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 456abcf9a2..e237b89982 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -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) })