tools.tsChecker

  • 类型: Object | Function
  • 默认值:
const defaultOptions = {
  typescript: {
    // avoid OOM issue
    memoryLimit: 8192,
    // use tsconfig of user project
    configFile: tsconfigPath,
    // use TypeScript checker by default
    tsgo: false,
    // use typescript of user project
    typescriptPath: require.resolve('typescript'),
  },
  issue: {
    exclude: [
      { file: '**/*.(spec|test).ts' },
      { file: '**/node_modules/**/*' },
    ],
  },
  logger: {
    log() {
      // do nothing
      // we only want to display error messages
    },
    error(message: string) {
      console.error(message.replace(/ERROR/g, 'Type Error'));
    },
  },
},

默认情况下,Modern.js 会开启 @rsbuild/plugin-type-check 进行类型检查。你可以通过 output.disableTsChecker 配置项来关闭类型检查。

示例

tsChecker 的值为 Object 类型时,会与默认配置进行深层合并。

export default {
  tools: {
    tsChecker: {
      issue: {
        exclude: [({ file = '' }) => /[\\/]some-folder[\\/]/.test(file)],
      },
    },
  },
};

请参考 @rsbuild/plugin-type-check 了解更多用法。

TypeScript Go 支持

tools.tsChecker 支持开启 TypeScript Go 进行类型检查。该能力由 @rsbuild/plugin-type-check 底层集成的 ts-checker-rspack-plugin 提供,目前仍处于实验阶段,可以将类型检查耗时减少约 5-10 倍。

在使用前,需要安装 @typescript/native-preview

npm
yarn
pnpm
bun
deno
npm install @typescript/native-preview -D

然后将 typescript.tsgo 设置为 true

export default {
  tools: {
    tsChecker: {
      typescript: {
        tsgo: true,
      },
    },
  },
};

开启 tsgo 后,默认的 typescript.typescriptPath 会解析到 @typescript/native-preview/package.json。如果你手动设置了 typescript.typescriptPath,它必须是指向 @typescript/native-preview/package.json 的绝对路径。

关于 tsgo 模式下生效的配置项和相关限制,请参考 ts-checker-rspack-plugin - TypeScript Go support