tsconfig.json配置

54 阅读1分钟
{
  "compilerOptions": {
    "target": "es5", // 编译目标为ES5
    "module": "esnext", // 模块类型为ES6风格的模块
    "allowJs": true, // 允许编译JavaScript文件
    "sourceMap": true, // 生成sourceMap文件
    "strict": true, // 开启严格模式
    "noImplicitAny": true, // 禁止隐式的any类型
    "moduleResolution": "node", // 模块解析策略
    "esModuleInterop": true, // 允许使用CommonJS模块风格导入默认导出的模块
    "resolveJsonModule": true, // 允许导入JSON模块
    "declaration": true, // 生成声明文件
    "outDir": "./dist", // 输出目录
    "baseUrl": ".", // 解析非相对模块的基准目录
    "paths": { // 路径映射
      "@/*": ["src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts", "tests/**/*.tsx"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

其中,部分比较常用的配置选项:

  • compilerOptions.target:编译目标,一般为ES5或ES6。
  • compilerOptions.module:模块类型,一般为ES6风格的模块。
  • compilerOptions.sourceMap:是否生成sourceMap文件。
  • compilerOptions.strict:开启严格模式。
  • compilerOptions.noImplicitAny:禁止隐式的any类型。
  • compilerOptions.outDir:输出目录。
  • compilerOptions.baseUrl:解析非相对模块的基准目录。
  • compilerOptions.paths:路径映射。
  • include:需要编译的文件路径。
  • exclude:排除的文件路径。