可能是,这与您所要求的不完全一样,但它是一种做同样事情的方法。我希望,它可能有用。首先,正如这里http://docs.asp.net/en/latest/client-side/using-gulp.html 所述,您可以在VS2015 中使用gulp。然后,在您的 tsconfig.json 文件中,您应该将 typescript 编译器选项设置为如下所示:
//tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true
},
"exclude": [
".vscode",
"node_modules",
"typings",
"public"
]
}
最后,gulp 文件——例如来自我的一个项目——用于将 ES6 转换为 ES5:
// gulpfile.js
'use strict';
var gulp = require("gulp"),
ts = require("gulp-typescript"),
babel = require("gulp-babel");
var tsSrc = [
'**/*.ts',
'!./node_modules/**',
'!./typings/**',
'!./vscode/**',
'!./public/**'
];
gulp.task("ts-babel", function () {
var tsProject = ts.createProject('tsconfig.json');
return gulp.src(tsSrc)
.pipe(tsProject())
.pipe(babel({
presets: ['es2015'],
plugins: [
'transform-runtime'
]
}))
.pipe(gulp.dest((function (f) { return f.base; })));
});
现在您可以使用命令 gulp ts-babel 转译文件。并且不要忘记安装所需的 npm 包,例如 babel-preset-es2015 和 babel-plugin-transform-runtime。
更新。感谢 Ashok M A 的关注。将 pipe(ts()) 改为 pipe(tsProject())