TypeScript配置文件设置详解

TypeScript配置文件设置

    • 1. include
    • 2. exclude
    • 3. extends
    • 4. files
    • 5. compilerOptions
      • 5.1 target
      • 5.2 module
      • 5.3 lib
      • 5.4 outDir
      • 5.5 outFile
      • 5.6 allowJs
      • 5.7 checkJs
      • 5.8 removeComments
      • 5.9 onEmit
      • 5.10 onEmitOnError
      • 5.11 alwaysStrict
      • 5.12 noImplicitAny
      • 5.13 noImplicitThis
      • 5.13 strictNullChecks
      • 5.14 strict

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
	}
}

你可能感兴趣的:(前端,typescript,ubuntu,linux)