请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

在 VS Code 里自动编译TypeScript文件

对于使用 VS Code IDE的同学,可以用Gulp来做TypeScript的实时编译。

1.  npm install gulp gulp-typescript typescript --save

2.  在根目录下创建一个 gulpfile.js 文件

3. 之后把下面的代码 Copy到gulpfile.js文件中

var gulp = require('gulp');

var ts = require('gulp-typescript');

var tsProject = ts.createProject('tsconfig.json');


gulp.task('tsc', function(){

  gulp.src('./server/*.ts').pipe(tsProject()).pipe(gulp.dest('./build'));

});


gulp.task('tsc:w',['tsc'], function() {

  gulp.watch('./server/*.ts',['tsc']);

});

4. 之后在控制台上输入 gulp tsc:w 

现在你改ts文件的同时,就会在 build的目录下生成相应的 js文件 


正在回答 回答被采纳积分+3

3回答

小爽子 2018-04-18 10:49:49

找到一个其他的解决方法,在菜单栏中选择“”任务-运行任务-tsc:构建tsconfig.json“”

0 回复 有任何疑惑可以回复我~
  • 我也是用的“任务-运行任务-tsc:构建tsconfig.json”方法,但是报错了,
    提示:“tsc : The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
    name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1
    + tsc -p c:\ng4learn\server\tsconfig.json
    + ~~~
        + CategoryInfo          : ObjectNotFound: (tsc:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    ”,你有遇到这个错误吗?
    回复 有任何疑惑可以回复我~ 2018-06-23 15:49:37
小爽子 2018-04-18 10:44:42

https://img1.sycdn.imooc.com//szimg/5ad6b0f60001cb7213160976.jpg
不是可运行的命令,报错

0 回复 有任何疑惑可以回复我~
提问者 DanielLittle 2017-04-12 08:55:54

https://img1.sycdn.imooc.com/szimg//58ed7cf70001fe5911450371.jpg

目录设置样例

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信