Typescript项目直接执行.ts代码;include/exclude设置;compliler Options编辑器属性配置

原创
小哥 3年前 (2022-10-26) 阅读数 8 #js教程

1.自动监视ts自动编译更改;

1.监视单个ts文件

tsc 文件名 -w

2.监视多个ts文件
第一步.在根目录下创建一个。tsconfig.json归档;把这个放在json 只留下 {} 即可


第二步 根目录下
运行 cmd 运行 txc -w 可以监控所有ts发生变化


2.tsconfig.json配置


include和exclude例如,示例LOWER‘


complilerOptions 编辑器选项配置

1.target,用于指定ts编辑过的Es版本;targe缺省值如下;
‘es3’, ‘es5’, ‘es6’, ‘es2015’, ‘es2016’, ‘es2017’, ‘es2018’, ‘es2019’, ‘es2020’, ‘es2021’, ‘esnext’;

2.mudule:指定要使用的模块化规范;缺省值如下;
‘none’, ‘commonjs’, ‘amd’, ‘system’, ‘umd’, ‘es6’, ‘es2015’, ‘es2020’, ‘es2022’, ‘esnext’, ‘node12’, ‘nodenext’;

3.lib:用于指定要在项目中使用的库;(建议使用默认值而不重写)
‘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’, ‘es2021.intl’, ‘esnext.array’, ‘esnext.symbol’, ‘esnext.asynciterable’, ‘esnext.intl’, ‘esnext.bigint’, ‘esnext.string’, ‘esnext.promise’, ‘esnext.weakref’;

4.outDir:指定工程的编译文件所在的目录,即js文件的存储地址(默认) ‘./dist’);

5.outFile:将编译的js这些文件被合并为一个文件js文件;

6.allowJs:是否将js这些文件是一起编译的。dist在文件下;默认false - 不 ;想要编译true;
7.checkjs:检查js文件是否符合规范,默认false;

8.removeComments:是否删除备注;默认false,是将注释带到已编译的文件中,更改true是删除所有评论;
9.noEmit:不生成编译后的文件;false,生成dist文件;true不是为了生成dist中的文件;

10.noEmitOnError:代码中的任何错误都不会编译。dist中的文档,
默认false有错误,文件被编译,
true如果有错误,则不会进行编译;

11.alwaysStrict:js是否使用严格模式,默认false不适用,true每个已编译的js文件的顶部是自动生成的。 “use strict”;

12.noImplicitAny:不允许隐式any(false);

13:noImplicitThis:不允许使用不明确的类型。this(默认false),true必须指定this的类型;

14.strictNullChecks:预测它是否会出现null不存在,默认情况下false不预判,true预判;

15.strict:严格模式总开关;

    "complilerOptions" : {
        "target": "ES5",
        "module": "ES2015",
        //    "lib": ["es2015"]
        "outDir": "./dist",
        "outFile": "./dist/app.js",
        "allowJs": true,
        "checkJs": true,
        "removeComments": true,
        "noEmitOnError": true,
        "noEmit": true,
        "alwaysStrict": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strictNullChecks": true,
        "strict": true
    }

版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除