mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(vite): improve logs for client vs server (#3634)
This commit is contained in:
parent
e891ea0cca
commit
570016c143
@ -184,7 +184,7 @@ export interface NuxtHooks {
|
|||||||
// vite
|
// vite
|
||||||
'vite:extend': (viteBuildContext: { nuxt: Nuxt, config: any }) => HookResult
|
'vite:extend': (viteBuildContext: { nuxt: Nuxt, config: any }) => HookResult
|
||||||
'vite:extendConfig': (viteInlineConfig: any, env: { isClient: boolean, isServer: boolean }) => 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
|
export type NuxtHookName = keyof NuxtHooks
|
||||||
|
@ -62,7 +62,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
|
|
||||||
const viteServer = await vite.createServer(clientConfig)
|
const viteServer = await vite.createServer(clientConfig)
|
||||||
ctx.clientServer = viteServer
|
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) => {
|
const viteMiddleware: Connect.NextHandleFunction = (req, res, next) => {
|
||||||
// Workaround: vite devmiddleware modifies req.url
|
// Workaround: vite devmiddleware modifies req.url
|
||||||
|
@ -131,7 +131,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
const viteServer = await vite.createServer(serverConfig)
|
const viteServer = await vite.createServer(serverConfig)
|
||||||
ctx.ssrServer = viteServer
|
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
|
// Close server on exit
|
||||||
ctx.nuxt.hook('close', () => viteServer.close())
|
ctx.nuxt.hook('close', () => viteServer.close())
|
||||||
@ -140,7 +140,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
await viteServer.pluginContainer.buildStart({})
|
await viteServer.pluginContainer.buildStart({})
|
||||||
|
|
||||||
if (ctx.nuxt.options.experimental.viteNode) {
|
if (ctx.nuxt.options.experimental.viteNode) {
|
||||||
logger.info('Using experimental vite-node server...')
|
logger.info('Vite server using experimental `vite-node`...')
|
||||||
await prepareDevServerEntry(ctx)
|
await prepareDevServerEntry(ctx)
|
||||||
} else {
|
} else {
|
||||||
// Build and watch
|
// Build and watch
|
||||||
|
@ -86,7 +86,7 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
|
|
||||||
await nuxt.callHook('vite:extend', ctx)
|
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
|
// Invalidate virtual modules when templates are re-generated
|
||||||
ctx.nuxt.hook('app:templatesGenerated', () => {
|
ctx.nuxt.hook('app:templatesGenerated', () => {
|
||||||
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
||||||
@ -98,7 +98,7 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
warmupViteServer(server, ['/entry.mjs'])
|
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)
|
.catch(logger.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user