mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(vite): avoid creating server for production build (#5941)
This commit is contained in:
parent
02598fba56
commit
4abcfb6bf9
@ -60,25 +60,27 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
|
|
||||||
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })
|
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })
|
||||||
|
|
||||||
const viteServer = await vite.createServer(clientConfig)
|
if (ctx.nuxt.options.dev) {
|
||||||
ctx.clientServer = viteServer
|
// Dev
|
||||||
await ctx.nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false })
|
const viteServer = await vite.createServer(clientConfig)
|
||||||
|
ctx.clientServer = 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
|
||||||
const originalURL = req.url
|
const originalURL = req.url
|
||||||
viteServer.middlewares.handle(req, res, (err) => {
|
viteServer.middlewares.handle(req, res, (err) => {
|
||||||
req.url = originalURL
|
req.url = originalURL
|
||||||
next(err)
|
next(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await ctx.nuxt.callHook('server:devMiddleware', viteMiddleware)
|
||||||
|
|
||||||
|
ctx.nuxt.hook('close', async () => {
|
||||||
|
await viteServer.close()
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
await ctx.nuxt.callHook('server:devMiddleware', viteMiddleware)
|
// Build
|
||||||
|
|
||||||
ctx.nuxt.hook('close', async () => {
|
|
||||||
await viteServer.close()
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!ctx.nuxt.options.dev) {
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
await vite.build(clientConfig)
|
await vite.build(clientConfig)
|
||||||
await ctx.nuxt.callHook('build:resources', wpfs)
|
await ctx.nuxt.callHook('build:resources', wpfs)
|
||||||
|
@ -101,15 +101,6 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
if (!nuxt.options.dev) {
|
if (!nuxt.options.dev) {
|
||||||
ctx.config.server.hmr = false
|
ctx.config.server.hmr = false
|
||||||
ctx.config.server.watch = undefined
|
ctx.config.server.watch = undefined
|
||||||
|
|
||||||
// TODO: Workaround for vite watching tsconfig changes
|
|
||||||
// https://github.com/nuxt/framework/pull/5875
|
|
||||||
ctx.config.plugins.push({
|
|
||||||
name: 'nuxt:close-vite-watcher',
|
|
||||||
configureServer (server) {
|
|
||||||
return server?.watcher?.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await nuxt.callHook('vite:extend', ctx)
|
await nuxt.callHook('vite:extend', ctx)
|
||||||
@ -129,6 +120,7 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
.then(() => logger.info(`Vite ${env.isClient ? 'client' : 'server'} 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)
|
||||||
})
|
})
|
||||||
|
|
||||||
await buildClient(ctx)
|
await buildClient(ctx)
|
||||||
await buildServer(ctx)
|
await buildServer(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user