Gulp和TS编译 [英] Gulp and TS compilation
本文介绍了Gulp和TS编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
gulp.task('dev:build:scripts',function( ){
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
});
取得所有脚本,并创建源映射到 static / DIST
。我的tsProject:
var tsProject = ts.createProject('tsconfig.json',{
outDir:paths.dist +'/ app'
});
而我的 tsconfig.json
{
compilerOptions:{
target:es5,
module :system,
moduleResolution:node,
sourceMap:true,
emitDecoratorMetadata:true,
experimentalDecorators:true,
removeComments:false,
noImplicitAny:false,
outDir:static / dist / app
},
exclude:[
node_modules
]
}
但是,项目,它不编译JS,并且不创建源代码 - 只有当我更改任何ts文件时才这样做。我该如何解决这个问题?
解决方案 我认为你忘了写实际结果。试试这个:
gulp.task('dev:build:scripts',()=>
{
var tsProject = ts.createProject('tsconfig.json');
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
return tsResult.js.pipe(sourcemaps.write())。pipe(gulp.dest(paths.dist +'/ app'));
});
I have defined task in my gulp file:
gulp.task('dev:build:scripts', function () {
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
});
Which takes all of the scripts, and creates source maps to the static/dist
. My tsProject:
var tsProject = ts.createProject('tsconfig.json', {
outDir: paths.dist +'/app'
});
And my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "static/dist/app"
},
"exclude": [
"node_modules"
]
}
However, after the gulp runs the project, it doesnt compile the JS and doesnt create sourcemaps - it only does so, when I make a change to any ts file. How can I fix this?
解决方案
I think you forgot to actually write your results. Try this one:
gulp.task('dev:build:scripts', () =>
{
var tsProject = ts.createProject('tsconfig.json');
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
return tsResult.js.pipe(sourcemaps.write()).pipe(gulp.dest(paths.dist +'/app'));
});
这篇关于Gulp和TS编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文