tsconfig.json的部分配置选项

本文详细介绍了如何创建tsconfig.json文件,包括指定编译文件、排除文件、文件编译选项等,以优化TypeScript项目的构建流程。重点讲解了target、module、lib等关键编译器选项。

根目录创建tsconfig.json文件:

{
    // tsconifig.json 是ts编译器的配置文件,ts编译器可以根据他的信息来对代码进行编译
    // 指定编译文件
    // 路径:** 任意目录 * 任意文件
    "include": [
        "./src/**/*"
    ],
    // 不需要被编译的文件
    "exclude": [
        "./src/hello/**/*"
    ],
    // 继承
    "extends": "",
    // 对象中的文件都将被编译
    "files": [
        "index.ts",
        "core.ts",
        "types.ts"
    ],
    // compilerOptions 编译器的选项
    "compilerOptions": {
        // target 指定JS编译版本 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'
        "target": "ES2015", 
        // module 指定要使用的模块化 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'
        "module": "ES2015", 
        // 指定项目中使用的库,es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.bigint', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref'
        "lib": [],
        // 指定编译后的JS文件所在位置
        "outDir": "./dist",
        // 设置outFile后,将所有全局作用域中的代码合并为一个文件
        "outFile": "",
        // 是否对JS文件进行编译,默认为false
        "allowJs": false,
        // 是否检测JS代码是否符合语法规范,默认为false
        "checkJs": false,
        // 是否移除注释,默认为false
        "removeComments": false,
        // 不生成编译后的文件
        "noEmit": false,
		// 所有严格检查的总开关
		"strict": true,
        // 当有错误时不生成编译后的文件,默认为false
        "noEmitOnError": true,
				// 用来设置编译后的文件是否使用严格模式
				"alwaysStrict": true,
				// 不允许隐式的any类型
				"noImplicitAny": true,
				// 不允许不明确类型的this
				"noImplicitThis": true,
				// 严格检查空值
				"strictNullChecks": true
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值