diff --git a/packages/vite/bin/vite.js b/packages/vite/bin/vite.js index e4d128ac7fa4db..9286da7aced26f 100755 --- a/packages/vite/bin/vite.js +++ b/packages/vite/bin/vite.js @@ -49,6 +49,15 @@ function start() { try { // eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is supported in Node 22.8.0+ and only called if it exists module.enableCompileCache?.() + // flush the cache after 10s because the cache is not flushed until process end + // for dev server, the cache is never flushed unless manually flushed because the process.exit is called + // also flushing the cache in SIGINT handler seems to cause the process to hang + setTimeout(() => { + try { + // eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is supported in Node 22.12.0+ and only called if it exists + module.flushCompileCache?.() + } catch {} + }, 10 * 1000).unref() } catch {} return import('../dist/node/cli.js') }