【TypeScript】配置
2021/09/09 09:36:40
tsconfig.json
tsconfig.jsoncompilerOptions 完整编译选项
{
"compileOnSave": true, // 设置IDE保存文件时根据tsconfig.json重新生成文件,要想支持这个特性需要Visual Studio 2015, TypeScript1.8.4以上并且安装atom-typescript插件。
"extends": './configs/base', // 引入其他配置
"compilerOptions": { // 配置项
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [ // 编译包含文件列表,指定要编译的文件
"core.ts",
],
"include": [ // 编译包含文件glob规则列表,指定要编译文件的匹配规则
"src/**/*"
],
"exclude": [ // 编译排除文件glob规则列表,指定要排除文件的匹配规则
"node_modules",
"**/*.spec.ts"
]
}
配置细节
compilerOptions 可以被忽略,这时编译器会使用默认值。
如果 files 和 include 都没有被指定,编译器默认包含当前目录和子目录下所有的 TypeScript 文件(.ts, .d.ts 和 .tsx),排除在 exclude 里指定的文件。
使用 outDir 指定的目录下的文件永远会被编译器排除,除非你明确地使用 files 将其包含进来(这时就算用 exclude 指定也没用)。
使用 include 引入的文件可以使用 exclude 属性过滤。 然而,通过 files 属性明确指定的文件却总是会被包含在内,不管 exclude 如何设置。
exclude 默认情况下会排除 node_modules,bower_components,jspm_packages 和 <outDir> 目录。
任何被 files 或 include 指定的文件所引用的文件也会被包含进来。
在命令行上指定的编译选项会覆盖在 tsconfig.json 文件里的相应选项。
glob 通配符
- 匹配 0 或多个字符(不包括目录分隔符)
- ? 匹配一个任意字符(不包括目录分隔符)
- **/ 递归匹配任意子目录