/** * 开发模式:一条命令同时起后端和前端。 * * 后端带 --hot,改了服务端代码自己重载;前端是 Vite,改了界面代码浏览器立刻更新, * 两边都不用手动重启。访问 Vite 那个地址(5173),它会把接口请求转发给后端。 * * 打包后的 `bun run start` 不具备这个能力:它把前端打成静态文件再由后端提供, * 代码一改就得重新打包重启。那种方式适合最终验证和部署。 */ export {} const procs = [ Bun.spawn(['bun', 'run', '--hot', 'server/index.ts'], { stdio: ['inherit', 'inherit', 'inherit'] }), Bun.spawn(['bunx', 'vite'], { stdio: ['inherit', 'inherit', 'inherit'] }), ] const stopAll = () => { for (const p of procs) p.kill() process.exit(0) } process.on('SIGINT', stopAll) process.on('SIGTERM', stopAll) await Promise.race(procs.map((p) => p.exited)) stopAll()