Skip to content

Commit

Permalink
fix: fix pre-bundling executes multiple times (#3640)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 23, 2021
1 parent fc6d8f1 commit 41a00df
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -548,15 +548,19 @@ export async function createServer(
}

if (!middlewareMode && httpServer) {
let isOptimized = false
// overwrite listen to run optimizer before server start
const listen = httpServer.listen.bind(httpServer)
httpServer.listen = (async (port: number, ...args: any[]) => {
try {
await container.buildStart({})
await runOptimize()
} catch (e) {
httpServer.emit('error', e)
return
if (!isOptimized) {
try {
await container.buildStart({})
await runOptimize()
isOptimized = true
} catch (e) {
httpServer.emit('error', e)
return
}
}
return listen(port, ...args)
}) as any
Expand Down

0 comments on commit 41a00df

Please sign in to comment.