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"
有关在 Bun 中使用 TypeScript 的更多信息,请参阅 文档 > 运行时 > TypeScript。