Running Vite Preview and Using Bun for Background Processes
Question: How to start and background vite preview and exit 0
Use nohup
or a process manager:
nohup bunx vite preview &
To ensure it exits cleanly:
bunx vite preview & sleep 1 && exit 0
Tips:
- Redirect logs to a file if needed.
Question: How to do this with bun spawn
Using Bun’s spawn
:
const { spawn } = require("bun");
spawn(["vite", "preview"], {
stdout: "inherit",
stderr: "inherit",
detached: true,
});
Tips:
- Use
detached: true
andstdio: "ignore"
to fully background.