赞
踩
学习地址:https://www.bilibili.com/video/BV1Xy4y1v7S2?p=1
- {
- // tsconfig.json是ts编译器的配置文件,ts编辑器可以根据他的信息来对代码进行编译
- /*
- “include”用来指定那些ts文件需要被编译 可以为多个
- 路劲 ** 表示任意目录 *表示任意文件
- */
- "include": [ // 包含
- "./src/**/*"
- // "./src1/**/index.ts"
- ],
- /*
- "exclude" 不需要被编译的文件目录
- 默认值["node_modules", "bower_components", "jspm_packages"]
- */
- // "exclude": [ // 不包含
- // "./src/app/*"
- // ],
- /*
- 表示继承
- extends表示继承其他config.json文件里面的配置
- "extends": "./configs/base"表示当前配置文件中会自动包含config目录下base.json中的所有配置
- */
- // "extends": "./configs/base",
- /*
- 被编译的文件列表(只有需要编译的文件少的时候才用的到)
- */
- // "files": [
- // "wenjian1.ts",
- // "wenjian2.ts",
- // "..."
- // ],
- /*
- 编译器的选项
- */
- "compilerOptions": {
- /*
- target :用来指定ts被编译成es的版本
- 可选值为:'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'
- 'esnext': 表示为最新版本
- */
- "target": "es6",
- /*
- module: 指定要使用的模块化规范(import export)
- 可选值为:'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'
- */
- "module": "system",
- /*
- 用来指定项目中用到的库例如document等(如果不是像做node项目那种只是做前端在项目一般不需要修改)
- 可选值为:'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": ["dom"],
- /*
- outDir:文件编译之后的输出目录
- 编译完成之后会创建dist目录变异的文件都会在这个目录下面
- */
- "outDir": "./dist",
- /*
- outFile:将编译的代码全放到这个指定的文件下
- 设置outFile之后所有的编译之后的所有全局作用域文件都会放到这个文件里
- 如果设置的模块化规范和代码使用的模块化规范不匹配则会报错
- Only 'amd' and 'system' modules are supported alongside --outFile.
-
- 40 "module": "commonjs",
- */
- "outFile": "./dist/index.js",
- /*
- allowJs: 是否对JS文件进行编译
- 默认是false 不编译JS文件 设置为true的话会编译JS文件
- */
- "allowJs": true,
- /*
- checkJs: 是否对JS文件语法进行编译
- 默认是false 不检查JS语法 设置为true的话会检查JS的语法
- 在JS内部let a = 10; a = '11' 是可以的 如果设置为true则会报错
- */
- "checkJs": false,
- /*
- removeComments: 是否移除注释
- 默认是false 不移除 设置为true的话ts文件内写的注释不会输出到编译之后的js文件中
- */
- "removeComments": false,
- /*
- noEmit:不生成编译之后的文件
- 默认是false 生成编译之后的文件
- 设置为true的话tsc命令编译之后不会生成编译之后的文件
- (一般用于语法检查不需要编译文件则会将这一项设置为true)
- */
- "noEmit": false,
- // 下述所有(包含不在这里的)严格检查均为true(下面的就可以不写了),如果需要设置为false的则需要单独设置
- "strict": true,
- /*
- noEmitOnError: 编译出错时不生成编译之后的文件
- 默认是false 出错也会生成编译之后的文件
- 设置为true的话tsc命令编译时如果报错了(语法错误或者其他错误等)不会生成编译之后的文件
- */
- "noEmitOnError": false,
- /*
- alwaysStrict: 用来指定编译之后的文件是否启用严格模式
- 默认是false 不使用严格模式
- 设置为true的话编译之后的js文件都是"use strict"模式 (import export这种模块化的文件默认都是严格模式)
- */
- "alwaysStrict": false,
- /*
- noImplicitAny: 不允许隐式的any
- 默认是false 允许隐式的any function fn(a, b) {return a + b}是不会报错的 其中参数a、b均为隐式的any
- 设置为true的话之前那种写法就会报错需要改为function fn(a:number, b:number) {return a + b} 这种指定类型
- */
- "noImplicitAny": false,
- /*
- noImplicitThis: 不允许不明确类型的this
- 默认是false允许 function fn() {alert(this)}是不会报错的其中this就是指向不明的(和函数的调用方法有关)
- 设置为true的话之前那种写法就会报错需要改为function fn(this:window) {alert(this)} 这种就不会报错
- */
- "noImplicitThis": false,
- /*
- strictNullChecks: 严格检查空值
- 默认是false 不严格检查空值 如果某一个值可能为空还绑定了事件或者做了其他用则可能会导致报错
- 设置为false这种写法 let box = document.getElementById('box')
- box.addEventListener('click', function() {
- console.log(111)
- })不会报错
- 设置为true的话就会严格检查需要加个判断
- box?.addEventListener('click', function() {
- console.log(111)
- })这样才不会报错
- */
- "strictNullChecks": false,
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
没事多复习复习,知道每个配置的含义,目前我公司项目中都没有用到这么具体的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。