【笔记】TS的配置文件

前言

TS的配置文件学习笔记

配置文件

compilerOptions.target:指定编译后的目标JS兼容版本
compilerOptions.module:指定编译后的目标JS模块化规范
compilerOptions.strict:指定是否开启TS严格模式的所有选项
compilerOptions.allowJs:指定是否允许TS文件中编写JS代码
compilerOptions.jsx:指定是否转换JSX语法

preserve:保留标签
react:将标签转换为React.createElement()

compilerOptions.esModuleInterop:指定是否允许混用ESModule和CommonJS
compilerOptions.baseUrl:指定项目根目录
compilerOptions.paths:指定项目路径别名
compilerOptions.lib:指定项目种可以使用的内部库
include:指定哪些文件会被编译,可以使用通配符,缺省值为["./*"]
exclude:指定哪些文件会被排除,可以使用通配符,缺省值为["node_modules/**/*"]
files:指定哪些文件会被编译,不能使用通配符

tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"allowJs": true,
"jsx": "preserve",
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"lib": ["dom", "esnext"]
},
"include": ["./*"],
"exclude": ["./node_modules/**/*"]
}

完成