-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtsconfig.json
206 lines (201 loc) · 14.8 KB
/
tsconfig.json
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
{
"compilerOptions": {
// 不报告执行不到的代码错误。
"allowUnreachableCode": true,
// 不报告未使用的标签错误
"allowUnusedLabels": false,
/* Basic Options */
// 编译的目标是什么版本的
/* 用来指定编译后的js要使用的模块标准: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2015",
// ES2015这样打包后校验的属性不能动态显示。
// 指定生成哪个模块系统代码
/* 用来指定编译后的js要使用的模块标准: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "ESNext",
// 编译过程中需要引入的库文件的列表
/* lib用于指定要包含在编译中的库文件 */
/* Specify library files to be included in the compilation. */
"lib": [
// "es5",
// "es2015",
// "es2016",
// "es2017",
// "es2018",
"dom",
"ESNext"
],
// 允许编译javascript文件。
/* allowJs设置的值为true或false,用来指定是否允许编译js文件,默认是false,即不编译js文件 */
/* Allow javascript files to be compiled. */
// "allowJs": true,
/* Report errors in .js files. */
/* checkJs的值为true或false,用来指定是否检查和报告js文件中的错误,默认是false */
// "checkJs": true,
/* 指定jsx代码用于的开发环境: 'preserve', 'react-native', or 'react'. */
/* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"jsx": "preserve",
// 是否自动创建类型声明文件
/* declaration的值为true或false,用来指定是否在编译的时候生成相应的".d.ts"声明文件。
如果设为true,编译每个ts文件之后会生成一个js文件和一个声明文件。
但是declaration和allowJs不能同时设为true */
/* Generates corresponding '.d.ts' file. */
// "declaration": true,
// 类型声明文件的输出目录
// "declarationDir": "./dist/types",
/* declarationMap值为true或false,指定是否为声明文件.d.ts生成map文件 */
/* Generates a sourcemap for each corresponding '.d.ts' file. */
// "declarationMap": true,
/* sourceMap的值为true或false,用来指定编译时是否生成.map文件 */
/* Generates corresponding '.map' file. */
"sourceMap": true,
/* outFile用于指定将输出文件合并为一个文件,它的值为一个文件路径名。
比如设置为"./dist/main.js",则输出的文件为一个main.js文件。
但是要注意,只有设置module的值为amd和system模块时才支持这个配置 */
/* Concatenate and emit output to single file. */
// "outFile": "./",
/* outDir用来指定输出文件夹,值为一个文件夹路径字符串,输出的文件都将放置在这个文件夹 */
/* Redirect output structure to the directory. */
"outDir": "./js",
/* 用来指定编译文件的根目录,编译器会在根目录查找入口文件,如果编译器发现以rootDir的值作为根目录查找入口文件并不会把所有文件加载进去的话会报错,但是不会停止编译 */
/* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "rootDir": "./",
/* 是否编译构建引用项目 */
/* Enable project compilation */
// "composite": true,
// "incremental": true, /* Enable incremental compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
/* removeComments的值为true或false,用于指定是否将编译后的文件中的注释删掉,设为true的话即删掉注释,默认为false */
/* Do not emit comments to output. */
"removeComments": true,
/* 不生成编译文件,这个一般比较少用 */
/* Do not emit outputs. */
// "noEmit": true,
/* importHelpers的值为true或false,指定是否引入tslib里的辅助工具函数,默认为false */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
/* 当target为'ES5' or 'ES3'时,为'for-of', spread, and destructuring'中的迭代器提供完全支持 */
/* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"downlevelIteration": true,
/* isolatedModules的值为true或false,指定是否将每个文件作为单独的模块,默认为true,它不可以和declaration同时设定 */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
/* strict的值为true或false,用于指定是否启动所有类型检查,如果设为true则会同时开启下面这几个严格类型检查,默认为false */
/* Enable all strict type-checking options. */
"strict": true,
/* noImplicitAny的值为true或false,如果我们没有为一些值设置明确的类型,编译器会默认认为这个值为any,如果noImplicitAny的值为true的话。则没有明确的类型会报错。默认值为false */
// 是否默认禁用 any /* Raise error on expressions and declarations with an implied 'any' type. */
// "noImplicitAny": true,
/* strictNullChecks为true时,null和undefined值不能赋给非这两种类型的值,别的类型也不能赋给他们,除了any类型。还有个例外就是undefined可以赋值给void类型 */
// "strictNullChecks": true, /* Enable strict null checks. */
/* strictFunctionTypes的值为true或false,用于指定是否使用函数参数双向协变检查 */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
/* 设为true后会对bind、call和apply绑定的方法的参数的检测是严格检测的 */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
/* 设为true后会检查类的非undefined属性是否已经在构造函数里初始化,如果要开启这项,需要同时开启strictNullChecks,默认为false */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
/* 当this表达式的值为any类型的时候,生成一个错误 */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
/* alwaysStrict的值为true或false,指定始终以严格模式检查每个模块,并且在编译之后的js文件中加入"use strict"字符串,用来告诉浏览器该js为严格模式 */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
/* 用于检查是否有定义了但是没有使用的变量,对于这一点的检测,使用eslint可以在你书写代码的时候做提示,你可以配合使用。它的默认值为false */
// "noUnusedLocals": true, /* Report errors on unused locals. */
/* 用于检查是否有在函数体中没有使用的参数,这个也可以配合eslint来做检查,默认为false */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
/* 用于检查函数是否有返回值,设为true后,如果函数没有返回值则会提示,默认为false */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
/* 用于检查switch中是否有case没有使用break跳出switch,默认为false */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
/* 用于选择模块解析策略,有'node'和'classic'两种类型' */
"moduleResolution": "node",
/* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
/* baseUrl用于设置解析非相对模块名称的基本目录,相对模块不会受baseUrl的影响 */
"baseUrl": "./",
// 工作根目录 /* Base directory to resolve non-absolute module names. */
// 指定模块的路径,和baseUrl有关联,和webpack中resolve.alias配置一样
/* 用于设置模块名称到基于baseUrl的路径映射 */
/* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"paths": {
"src": [
//指定后可以在文件中直接 import * from 'src';
"./src"
]
},
/* rootDirs可以指定一个路径列表,在构建时编译器会将这个路径列表中的路径的内容都放到一个文件夹中 */
/* List of root folders whose combined content represents the structure of the project at runtime. */
// "rootDirs": [],
/* typeRoots用来指定声明文件或文件夹的路径列表,如果指定了此项,则只有在这里列出的声明文件才会被加载 */
/* List of folders to include type definitions from. */
// "typeRoots": [],
/* types用来指定需要包含的模块,只有在这里列出的模块的声明文件才会被加载进来 */
//指定引入的类型声明文件,默认是自动引入所有声明文件,一旦指定该选项,则会禁用自动引入,改为只引入指定的类型声明文件,如果指定空数组[]则不引用任何文件
// "types": [], /* Type declaration files to be included in compilation. */
/* 用来指定允许从没有默认导出的模块中默认导入 */
"allowSyntheticDefaultImports": true,
/* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
/* 通过为导入内容创建命名空间,实现CommonJS和ES模块之间的互操作性 */
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"esModuleInterop": true,
/* 不把符号链接解析为其真实路径,具体可以了解下webpack和nodejs的symlink相关知识 */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
/* sourceRoot用于指定调试器应该找到TypeScript文件而不是源文件位置,这个值会被写进.map文件里 */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
/* mapRoot用于指定调试器找到映射文件而非生成文件的位置,指定map文件的根路径,该选项会影响.map文件中的sources属性 */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
/* 指定是否将map文件的内容和js文件编译在同一个js文件中,如果设为true,则map的内容会以//# sourceMappingURL=然后拼接base64字符串的形式插入在js文件底部 */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
/* 用于指定是否进一步将.ts文件的内容也包含到输入文件中 */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
/* 用于指定是否启用实验性的装饰器特性 */
"experimentalDecorators": true,
// 启用实验性的ES装饰器 /* Enables experimental support for ES7 decorators. */
/* 用于指定是否为装饰器提供元数据支持,关于元数据,也是ES6的新标准,可以通过Reflect提供的静态方法获取元数据,如果需要使用Reflect的一些方法,需要引入ES2015.Reflect这个库 */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"forceConsistentCasingInFileNames": true,
// 禁止对同一个文件的不一致的引用。
// "resolveJsonModule": true, // 允许从 .json 中导入、导出其类型 TS5071: Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'.
"skipLibCheck": true,
// 忽略所有的声明文件(*.d.ts)的类型检查。
"noLib": false
// 不包含默认的库文件(lib.d.ts)。
},
// 指定一个匹配列表(属于自动指定该路径下的所有ts相关文件)
// include也可以指定要编译的路径列表,但是和files的区别在于,这里的路径可以是文件夹,也可以是文件,
// 可以使用相对和绝对路径,而且可以使用通配符,比如"./src"即表示要编译src文件夹下的所有文件以及子文件夹的文件
"include": [
"src/**/*",
"type-dom/type-node/**/*"
],
// 指定一个排除列表(include的反向操作)
// exclude表示要排除的、不编译的文件,它也可以指定一个列表,规则和include一样,可以是文件或文件夹,可以是相对路径或绝对路径,可以使用通配符
"exclude": [
"demo.ts",
"node_modules",
"dist/**"
],
// 指定哪些文件使用该配置(属于手动一个个指定文件)
// files可以配置一个数组列表,里面包含指定文件的相对或绝对路径,编译器在编译的时候只会编译包含在files中列出的文件,
// 如果不指定,则取决于有没有设置include选项,如果没有include选项,则默认会编译根目录以及所有子目录中的文件。
// 这里列出的路径必须是指定文件,而不是某个文件夹,而且不能使用* ? **/ 等通配符
// "files": [
// "demo.ts"
// ]
// extends可以通过指定一个其他的tsconfig.json文件路径,来继承这个配置文件里的配置,继承来的文件的配置会覆盖当前文件定义的配置。
// TS在3.2版本开始,支持继承一个来自Node.js包的tsconfig.json配置文件
// "extends": "",
// compileOnSave的值是true或false,如果设为true,在我们编辑了项目中的文件保存的时候,编辑器会根据tsconfig.json中的配置重新生成文件,不过这个要编辑器支持
// "compileOnSave": true,
// 一个对象数组,指定要引用的项目
// "references": [],
"typedocOptions": {
"entryPoints": [
"src/**/*.ts"
],
"out": "docs"
}
}