create-react-app ts 配置文件说明

6 min read

创建基于TS的react 项目

npx create-react-app react-ts --template typescript

create-react-app ts 配置文件说明

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true, // Allow .js files to be compiled
    "skipLibCheck": true,
    "esModuleInterop": true, // 允许使用es6的模块化语法 import react from "react"
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,  // 可以引用json文件
    "isolatedModules": true, // 编译器会将每个模块作为一个独立的模块,而不是将其打包到一个文件中
    "noEmit": true, // 表示不生成js文件
    "jsx": "react-jsx" // 允许使用jsx语法
  },
  "include": [
    "src"
  ]
}