编译选项
监听文件变化 自动编译
tsc xxx.ts -w
crtl + c 关闭
创建 ts 配置文件
tsc - init;
然后继续 编译 就会把当前目录下的 ts 文件全部编译
tsc - w;
选项
- include 定义希望被编译 文件所在的目录
// 默认值 ["**/*"]
// ** 任意目录
// * 任意文件
include: ["./src/**/*", "./test/**/*"]; // 所有src目录和test目录下的ts文件都会被编译
- exclude 定义不希望被编译 文件所在的目录
// 默认值 [node_modules","bower_components","jspm_packages"]
// ** 任意目录
// * 任意文件
exclude: []; // 所有src目录和test目录下的ts文件都不会被编译
- extends 定义被继承的配置文件
extends:'./configs/base'
// 当前配置文件中hui;
- files 指定被编译文件的列表,只有需要编译的文件少的时候才会用到
files:[
'sys.ts',
'index.ts',
...
]
- compilerOptions
- 编译选项
查看可选项,填一个错误值,然后编译,会提示可以填写那些值
"compilerOptions": {
// 设置ts代码编译的目标版本
// 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext'.
"target":"ES6",
// 使用的的模块化规范
// 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.
"module":"commonjs",
// 指定项目中要使用的库
// "lib":[]
// 指定编译后文件所在的目录
"outDir":'./dist',
// 将编译后的文件合并为一个文件
"outFile":'./dist/app.js',
// 是否对js文件进行编译 默认false
"allowjs": false,
// 是否检查js代码是否符合规范
"checkJS": false,
// 是否移除注释
"removeComments":false,
// 不生成编译后的文件 执行编译过程,不产生文件 用于检测语法
"noEmit": false,
// 有错误是 不生成编译后的文件
"noEmitOnError": false,
// 编译后的文件是否使用严格模式
"alwaysStrict": false,
// 不允许隐式的 any 类型
"noTmpLicitAny": true,
// 隐式 any
// function(a, b){
// return a + n
// }
// 不允许不明确类型的 this
"noTmpLicitThis": false,
// function fun(){alert(this)}
// 指定this的类型
// function fun(this:any){alert(this)}
// function fun(this:wwidow){alert(this)}
// 严格检查空值
"strictNullChecks": false,
// let box = document.getElementById('box')
// if(box !== null){
// box.onclick = function(){}
// }
// 所有严格检查总开关
"strict":false
}