编译选项

tsc xx.ts **-w **

  • 添加监视器   自动编译

**tsconfig.json**

  • ts 的配置文件,ts 编译器可以根据它的信息来对代码进行编译
  • 在当前文件目录下添加 ts 配置文件   可以使用 tsc  对当前目录下所有 ts 文件进行编译。tsc -w 可对当前所有 ts 进行自动编译
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
/* ts的配置文件,ts编译器可以根据它的信息来对代码进行编译 */

/* "include"用来指定哪些 ts文件需要被编译 */
/* 一个*表示任意文件、两个*表示任意目录 */
"include": [
"./src/*"
],
/* "exclude" 不需要被编译的文件 */
/* 默认值 ["node_modules","bower_components","jspm_packages"] */
"exclude":[],

"extends":" ./configs/base" --就是套娃,引用其他配置文件

"files": [
//一个一个的列出要编译的文件名
"index.ts"
],

//complierOption 编译器的选项
"compilerOptions": {

// target 用来指定ts被编译的es版本
// 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017',
'es2018', 'es2019', 'es2020', 'esnext'
"target":"es2015",

//module 用来指定要使用的模块化的范式
"module": "system",

//lib用来指定项目中使用到的 js库,默认不写这个选项,该有得都有
/* "lib":[] */

//outDir 用来指定编译后文件所在的文件目录
"outDir":"./dist",

//将代码合并为一个文化
//设置outFile后,所有的全局作用域中的代码会合并到同一个文件中
//使用时 module必须使用 system 或 amd
//实际一般用的打包工具
"outFile":"./dist/app.js",

//是否对js文件进行编译 默认false
"allowJs": true,
//是否检查js代码是否符合法语法规范,默认是false
"checkJs":true,
//是否移除注释 默认false
"removeComments":true,
//不生成 编译后的文件,默认flase,开启为true
//开启这个选项 就只用ts检查一哈语法而已
"noEmit":false,
//有错误的时候不编译成js文件 默认false
"noEmitOnError": true,

/* 所有严格检查的总开关 推荐 true */
"strict":true,

//用来设置编译后的 js是否开启严格模式 默认flase
"alwaysStrict": true,

//不允许隐式any类型。默认false
"noImplicitAny": true,

//不允许不明确类型的this
"noImplicitThis": true,

//严格的检查空值,有可能是null的都会报错 默认false
"strictNullChecks": false,


}

}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!