自动编译单个文件:tsc app.ts -w
自动编译所有ts文件: tsc -w(前提:必须得有ts配置文件tsconfig.json)
// tsconfig.json是ts编译器的配置文件,ts编译器可以根据它的信息来对代码进行编译
{
// 用来指定哪些ts文件需要被编译
"include" : [
"./src/**/*"
],
// 默认值:["node_modules", "bower_components", "jspa_packages"]
"exclude": [
"node_modules",
],
// 继承配置文件
"extends": [],
// 同include,files指定具体文件,include写文件夹
"files": [],
"compilerOptions": {
"target": 'es5', // 用来指定ts被编译成的版本
"module": "es2015", // 用来指定要使用的模块化的规范,例如commonjs、amd等
"lib": [ // 指定浏览器要使用的库
"dom",
"es5",
"es2015.promise"
],
"outDir": "./", // 指定编译好的文件所放位置
"outFile": "./dist/app.js", // 所有的全局作用域ts代码合并到一个文件
"allowJs": false, // 是否对js文件进行编译,默认为false
"checkJs": false, // 是否检查js代码符合js规范
"removeComments": true, // 是否移除注释
"noEmit": true, // 不生成编译后的文件
"noEmitOnError": true, // 当有错误时不生成编译后的文件
"alwaysStrict": true, // 用来设置编译后的文件是否使用严格模式.当是模块时,自动是严格模式
"noImplicitAny": true, // 不允许隐式的any
}
}