若是一个目录下存在一个tsconfig.json文件,那么意味着这个目录是TypeScript的根目录。node
tsconfig.json文件中指定了用来编译这个项目的根文件和编译选项。一个项目能够经过如下方式之一来编译:json
tsconfig.json示例文件:bash
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts",
"binder.ts",
"checker.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
"tsc.ts",
"diagnosticInformationMap.generated.ts"
]
}复制代码
{
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "../../built/local/tsc.js",
"sourceMap": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}复制代码
"compilerOptions"能够被忽略,这时编译器会使用默认值。ui
"files"指定了一个包含相对或绝对文件路径的列表。"include"和"exclude"属性指定一个文件glob匹配模式列表,支持的glob通配符有:spa
若是一个glob模式里的某部分只包含*或者.*,那么仅有支持的文件扩展名类型被包含在内。命令行
若是"files"和"include"都没有被指定,编译器默认包含当前目录和子目录下全部的TypeScript文件(.ts,.d.ts,.tsx)code