在 VS Code 里自动编译TypeScript文件

来源:8-2 web服务器

DanielLittle

2017-04-12

对于使用 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回答

小爽子

2018-04-18

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

0
1
Emily_Zhy
我也是用的“任务-运行任务-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
共1条回复

小爽子

2018-04-18

//img.mukewang.com/szimg/5ad6b0f60001cb7213160976.jpg
不是可运行的命令,报错

0
0

DanielLittle

提问者

2017-04-12

//szimg.mukewang.com/58ed7cf70001fe5911450371.jpg

目录设置样例

0
0

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程