執行環境套件管理器打包器測試執行器程式碼檢查格式化指南參考部落格意見回饋

重新對映匯入路徑

Bun 會讀取你 tsconfig.json 檔案中的 paths 欄位以重新寫入匯入路徑。這對於別名包名或避免冗長的相對路徑非常有用。

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

使用此 tsconfig.json,Bun 會重寫以下匯入:

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

請參閱 TypeScript。