- tsconfig.json https://www.tslang.cn/docs/handbook/tsconfig-json.html
- tsc —init,自动产生tsconfig.json
- 初始化的tsconfig.json无需修改,增加”allowJs”: true选项
- file 属性
- include & exclude属性
- 指定一个文件glob匹配模式列表
- extends 继承
- 一个目录下存在一个tsconfig.json文件,那这个目录是TypeScript项目的根目录
- —project(或-p)指定一个包含tsconfig.json文件的目录
tsconfig.json
{ "compilerOptions": { "noImplicitAny": false, // 不需要显式地声明变量的类型any // 编译后的目标javascript版本,ES5, ES6/ES2015,16,17,18,19,ES2020, ESNext "target": "es5", // 编译后代码的ES版本,还有es3,es2105 "lib": [ "dom", // document.getElementById("root") "dom.iterable", "esnext" ], "removeComments": true, "noImplicitAny": true, "preserveConstEnums": true, "allowJs": true, // 允许混合编译JavaScript文件 "skipLibCheck": true, // 允许我们使用commonjs的方式import默认文件, import React from 'react' "esModuleInterop": true, // "esModuleInterop": false, import * as React from 'react' "allowSyntheticDefaultImports": true, // 严格校验,不能有没意义的any,null校验等选项 "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, // 配置的是我们代码的模块系统, Node.js的CommonJS、ES6标准的esnext、requirejs的AMD "module": "esnext", "moduleResolution": "node", // 决定了我们编译器的工作方式,"node" and "classic" "resolveJsonModule": true, "isolatedModules": true, // 编译器会将每个文件作为单独的模块来使用 "noEmit": true, // 表示当发生错误的时候,编译器不要生成 JavaScript 代码 "jsx": "react" // 允许编译器支持编译react代码 }, "include": [ "src" ], "exclude": [ "node_modules", "**/*.spec.ts" ], "files": [ "core.ts", "sys.ts", "types.ts", "scanner.ts", "parser.ts", "utilities.ts", "binder.ts", "checker.ts", "emitter.ts", "program.ts", "commandLineParser.ts", "tsc.ts", "diagnosticInformationMap.generated.ts" ], "extends": "./configs/base",}
jsx
- preserve
- react
- react-jsx
- react-jsxdev
- react-native
tsconfig.json编译器配置文档