Skip to main content
Bun 支持 --hot 标志来启用热重载运行文件。当任何模块或文件发生变化时,Bun 会重新运行该文件。
terminal
bun --hot run index.ts

Bun 会检测你是否正在使用 Bun.serve() 运行 HTTP 服务器。当源文件更改时,它会重新加载你的 fetch 处理函数,而不会 重启 bun 进程。这让热重载几乎是瞬时完成的。
请注意,这并不会刷新你浏览器中的页面。
https://mintcdn.com/ikxin/RzFFGbzo0-4huILA/icons/typescript.svg?fit=max&auto=format&n=RzFFGbzo0-4huILA&q=85&s=a3dffd2241f05776d3bd25171d0c5a79index.ts
Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello world");
  },
});