简体   繁体   English

Gulp被困在无限循环中

[英]Gulp Is Getting Stuck in Infinite Loop

I have Gulp set up on an express app project, and it does really well watching my JS files and linting those and then injecting them into my layout file and everything. 我已经在一个快速应用程序项目上设置了Gulp,它确实很好地观察了我的JS文件并将它们打印出来然后将它们注入我的布局文件和所有内容中。 The Gulpfile.js also injects bower dependencies for me using wiredep and other files I've determined using gulp-inject. Gulpfile.js还使用wiredep和我使用gulp-inject确定的其他文件为我注入了Bower依赖项。 All of that works as planned. 所有这些都按计划进行。

However, when I add the typescript compiling task, I get stuck in an infinite loop. 但是,当我添加typescript编译任务时,我陷入无限循环。 Is there something in my file I'm missing that could keep this from happening? 我的文件中缺少某些东西可以阻止这种情况发生吗? Here's the link to the Gulpfile in a gist . 这是gist中指向Gulpfile的链接

Thanks for your help! 谢谢你的帮助!

I also had a problem with gulp and typescript. 我也有吞咽和打字稿的问题。 Gulp didn't wait for the typescript compilation task to finish and started watching the js files, and as they were generated, my page was refreshed multiple times. Gulp并没有等待打字稿编译任务完成并开始观看js文件,并且在生成js文件时,我的页面被刷新了多次。

I managed to solve it by creating and returning a promise instead of a stream. 我设法通过创建并返回一个promise而不是一个流来解决它。

var Q = require('q');

gulp.task('typescript', function() {
    var d = Q.defer();

    var result = tsProject.src(paths.typescript)
        .pipe(ts(tsProject));

    result.js.pipe(gulp.dest('server/public/app/'));

    result
        .on('end', d.resolve)
        .on('error', d.reject);

    return d.promise;
});

Hope this can help you. 希望这可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM