Skip to content

Commit 1f8d120

Browse files
committed
fix: close bundle at cli exit
1 parent 05e5c22 commit 1f8d120

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/vite/src/node/build.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
mergeWithDefaults,
6060
normalizePath,
6161
partialEncodeURIPath,
62+
setupSIGTERMListener,
6263
unique,
6364
} from './utils'
6465
import { perEnvironmentPlugin, resolveEnvironmentPlugins } from './plugin'
@@ -973,8 +974,20 @@ async function buildEnvironment(
973974
}
974975
throw e
975976
} finally {
976-
// close the bundle will make the rolldown hmr invalid, so dev build need to disable it.
977-
if (bundle && !server) await bundle.close()
977+
// Note: close the bundle will make the rolldown hmr invalid, so dev build need to disable it.
978+
if (server) {
979+
const closeBundleAndExit = async (_: unknown, exitCode?: number) => {
980+
try {
981+
if (bundle) await bundle.close()
982+
} finally {
983+
process.exitCode ??= exitCode ? 128 + exitCode : undefined
984+
process.exit()
985+
}
986+
}
987+
setupSIGTERMListener(closeBundleAndExit)
988+
} else {
989+
if (bundle) await bundle.close()
990+
}
978991
}
979992
}
980993

0 commit comments

Comments
 (0)