mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +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 })
|
||||
|
||||
const viteServer = await vite.createServer(clientConfig)
|
||||
ctx.clientServer = viteServer
|
||||
await ctx.nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false })
|
||||
if (ctx.nuxt.options.dev) {
|
||||
// Dev
|
||||
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) => {
|
||||
// Workaround: vite devmiddleware modifies req.url
|
||||
const originalURL = req.url
|
||||
viteServer.middlewares.handle(req, res, (err) => {
|
||||
req.url = originalURL
|
||||
next(err)
|
||||
const viteMiddleware: Connect.NextHandleFunction = (req, res, next) => {
|
||||
// Workaround: vite devmiddleware modifies req.url
|
||||
const originalURL = req.url
|
||||
viteServer.middlewares.handle(req, res, (err) => {
|
||||
req.url = originalURL
|
||||
next(err)
|
||||
})
|
||||
}
|
||||
await ctx.nuxt.callHook('server:devMiddleware', viteMiddleware)
|
||||
|
||||
ctx.nuxt.hook('close', async () => {
|
||||
await viteServer.close()
|
||||
})
|
||||
}
|
||||
await ctx.nuxt.callHook('server:devMiddleware', viteMiddleware)
|
||||
|
||||
ctx.nuxt.hook('close', async () => {
|
||||
await viteServer.close()
|
||||
})
|
||||
|
||||
if (!ctx.nuxt.options.dev) {
|
||||
} else {
|
||||
// Build
|
||||
const start = Date.now()
|
||||
await vite.build(clientConfig)
|
||||
await ctx.nuxt.callHook('build:resources', wpfs)
|
||||
|
@ -101,15 +101,6 @@ export async function bundle (nuxt: Nuxt) {
|
||||
if (!nuxt.options.dev) {
|
||||
ctx.config.server.hmr = false
|
||||
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)
|
||||
@ -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`))
|
||||
.catch(logger.error)
|
||||
})
|
||||
|
||||
await buildClient(ctx)
|
||||
await buildServer(ctx)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user