运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

重新映射导入路径

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。