Skip to content

Bun 支持 --hot 標志來運行文件並啟用熱重載。當任何模塊或文件更改時,Bun 會重新運行該文件。

sh
bun --hot run index.ts

Bun 會檢測你何時使用 Bun.serve() 運行 HTTP 服務器。當源文件更改時,它會重新加載你的 fetch 處理程序,而無需重啟 bun 進程。這使得熱重載幾乎是瞬時的。

NOTE

請注意,這不會重新加載瀏覽器中的頁面。
ts
Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello world");
  },
});

Bun學習網由www.bunjs.com.cn整理維護