1,在线编译,进入typescript官网http://www.typescriptlang.org/,点击里面的playground就可以直接写代码了。
2,在本地编译运行Typescript需要使用npm下载typescript npm install -g typescript
tsc Hello.ts
运行后就会发现在同一文件夹下生成了Hello.js
3,webstorm编辑器可以自动生成相应的js
4,简便方法压缩ts资源
目录中创建文件app.js
下载egret引擎源代码,以4.1.0为例,在tools中拷贝typescript-plus文件夹,uglify-js文件夹,FileUtil.ts,FileUtil.js到app.js相同目录
app.js代码入下,并用node运行
var file = require("./FileUtil"); var path = require("path"); var ts = require("./typescript-plus/lib/typescript"); var uglifyJS = require("./uglify-js/uglifyjs"); var baseUrl = "F:/work/" var url = baseUrl + "tsconfig.json"; //var configObj = JSON.parse(file.read(url)); var configObj = { "compilerOptions":{ "target": "es5", "experimentalDecorators": true, "lib": [ "es5", "dom", "es2015.promise" ] }, "exclude": [ "node_modules" ] }; var configParseResult = ts.parseJsonConfigFileContent(configObj, ts.sys, path.dirname(url)); let compilerOptions = configParseResult.options; let fileNames = configParseResult.fileNames; compilerOptions.outFile = path.join(baseUrl, "main.min.js"); var compilerHost = ts.createCompilerHost(compilerOptions); var program = ts.createProgram(fileNames, compilerOptions, compilerHost); var sortResult = ts.reorderSourceFiles(program); program.emit(); var outfile = compilerOptions.outFile; //UglifyJS参数参考这个页面:https://github.com/mishoo/UglifyJS2 var result = uglifyJS.minify(outfile, {compress: {global_defs:true }, output:{beautify:false}}); file.save(outfile, result.code);