1.自动监视ts变化自动进行编译;
1.监视单个ts文件
tsc 文件名 -w
2.监视多个ts文件
第一步.根目录下创建一个tsconfig.json文件;把这个json 只留下 {} 即可
第二步 根目录下
运行 cmd 运行 txc -w 即可监听所有ts发生变化
2.tsconfig.json配置
include和exclude样例如下‘
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
}