TypeScript配置文件设置详解


TypeScript配置文件名时tsconfig.json,文件内部写json,其中比较常用的配置属性有一下几种

1. include

用来指定那些目录下的配置文件需要被编译

//       ** 表示任意目录
//       *  表示任意文件
{
	"include" : [
		"./scr/**/*"
	]
}

2. exclude

用来指定那些目录的文件不需要被编译

{
	"exclude":[
		"./static/**/*"
	]
}

3. extends

指定继承哪个配置文件的配置

{
	"extends": ""
}

4. files

指定被编译的文件

{
	"files":[
		"./src/index.ts"
	]
}

5. compilerOptions

编译器选项

5.1 target

指定ts编译后的js版本,默认ES3

{
	"compilerOptions":{
		"target":"ES6"
	}
}

5.2 module

指定编译后的模块类型,默认commonjs

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015"
	}
}

5.3 lib

编译时需要引入的库文件

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"lib": ["amd"]
	}
}

5.4 outDir

指定编译文件的输出位置

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
	}
}

5.5 outFile

将编译后的文件合并问指定文件

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"outFile": "./dist/index.js"
	}
}

5.6 allowJs

是否允许编译js文件,默认false

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true
	}
}

5.7 checkJs

是否检查js文件

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
	}
}

5.8 removeComments

是否移出注释

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
	}
}

5.9 onEmit

是否不生成编译后的文件

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
	}
}

5.10 onEmitOnError

是否在编译文件出错时停止编译

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
	}
}

5.11 alwaysStrict

是否以严格模式编译

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
		"alwaysStrict":true,
	}
}

5.12 noImplicitAny

是否允许使用any

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
		"alwaysStrict":true,
		"onImplicitAny":false,
	}
}

5.13 noImplicitThis

是否允许使用隐式的this

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
		"alwaysStrict":true,
		"onImplicitAny":false,
		"noImplicitThis":false,
	}
}

5.13 strictNullChecks

是否严格检查Null

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
		"alwaysStrict":true,
		"onImplicitAny":false,
		"noImplicitThis":false,
		"strictNullChecks":true
	}
}

5.14 strict

所有严格检查的总开关

{
	"compilerOptions":{
		"target":"ES6",
		"module": "es2015",
		"outDir": "./dist",
		"allowJs": true,
		"checkJs": true,
		"removeComments": true,
		"onEmit": false,
		"onEmitOnError":false,
		"alwaysStrict":true,
		"onImplicitAny":false,
		"noImplicitThis":false,
		"strictNullChecks":true,
		"strict":true
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值