Skip to content

Bun 讀取 tsconfig.json 中的 paths 字段來重寫導入路徑。這對於別名化包名稱或避免較長的相對路徑很有用。

json
{
  "compilerOptions": {
    "paths": {
      "my-custom-name": ["zod"],
      "@components/*": ["./src/components/*"]
    }
  }
}

使用上面的 tsconfig.json,以下導入將被重寫:

ts
import { z } from "my-custom-name"; // 從 "zod" 導入
import { Button } from "@components/Button"; // 從 "./src/components/Button" 導入

請參閱 文檔 > 運行時 > TypeScript 獲取在 Bun 中使用 TypeScript 的更多信息。

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