Bun 會讀取您 tsconfig.json
檔案中的 paths
欄位,以重新編寫匯入路徑。這對於別名化套件名稱或避免過長的相對路徑非常有用。
{
"compilerOptions": {
"paths": {
"my-custom-name": ["zod"],
"@components/*": ["./src/components/*"]
}
}
}
使用上述 tsconfig.json
,以下匯入將被重新編寫
import { z } from "my-custom-name"; // imports from "zod"
import { Button } from "@components/Button"; // imports from "./src/components/Button"
請參閱文件 > 執行階段 > TypeScript 以取得更多關於搭配 Bun 使用 TypeScript 的資訊。