Skip to content

tsconfig

  • 类型:string

    ¥Type: string

  • 可选:是 ✅

    ¥Optional: Yes ✅

指定 TypeScript 配置文件的路径。你可以提供相对路径(相对于 cwd 解析)或绝对路径。

¥Specifies the path to a TypeScript configuration file. You may provide a relative path (resolved relative to cwd) or an absolute path.

示例

¥Examples

使用默认 tsconfig.json

¥Use default tsconfig.json

js
export default {
  tsconfig: './tsconfig.json',
};

使用自定义配置

¥Use custom config

js
export default {
  tsconfig: './tsconfig.build.json',
};

使用绝对路径

¥Use absolute path

js
export default {
  tsconfig: '/absolute/path/to/tsconfig.json',
};

深入探讨

¥In-depth

指定 tsconfig 路径后,Rolldown 将:

¥When a tsconfig path is specified, Rolldown will:

1. 使用编译器选项进行转译:

¥ Use compiler options for transpilation:

  • target:要编译为的 ECMAScript 版本

    ¥target: ECMAScript version to compile to

  • jsx:JSX 转换模式

    ¥jsx: JSX transformation mode

  • experimentalDecorators:启用装饰器支持

    ¥experimentalDecorators: Enable decorator support

  • emitDecoratorMetadata:触发装饰器元数据

    ¥emitDecoratorMetadata: Emit decorator metadata

2. 使用路径进行模块解析:

¥ Use paths for module resolution:

  • compilerOptions.paths:模块解析的路径映射

    ¥compilerOptions.paths: Path mapping for module resolution

  • compilerOptions.baseUrl:用于路径解析的基准目录

    ¥compilerOptions.baseUrl: Base directory for path resolution

3. 与转换选项合并:

¥ Merge with transform options:

tsconfig 选项将与顶层 transform 选项合并,transform 选项优先。

¥The tsconfig options will be merged with the top-level transform options, with transform options taking precedence.

示例 tsconfig.json:

¥Example tsconfig.json:

json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "jsx": "react-jsx",
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@components/*": ["src/components/*"]
    }
  }
}

使用此配置:

¥With this configuration:

  • TypeScript 将被转译为 ES2020

    ¥TypeScript will be transpiled to ES2020

  • JSX 将使用 React 的自动运行时

    ¥JSX will use React's automatic runtime

  • @/utils 这样的路径别名将解析为 src/utils

    ¥Path aliases like @/utils will resolve to src/utils

优先级

¥Priority

Rolldown 配置中直接指定的选项优先于 tsconfig.json 设置:

¥Options specified directly in Rolldown configuration take precedence over tsconfig.json settings:

js
export default {
  tsconfig: './tsconfig.json', // Has jsx: 'react-jsx'
  transform: {
    jsx: {
      mode: 'classic', // This takes precedence
    },
  },
};

自动发现

¥Automatic Discovery

如果未指定此选项,Rolldown 将不会自动查找 tsconfig.json。你必须明确提供路径。

¥Rolldown will NOT automatically look for tsconfig.json if this option is not specified. You must explicitly provide the path.

提示

对于 TypeScript 项目,建议指定 tsconfig 以确保一致的编译行为并启用路径映射。

¥For TypeScript projects, it's recommended to specify tsconfig to ensure consistent compilation behavior and enable path mapping.