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 的更多信息。