吞咽手表立即终止 [英] gulp watch terminates immediately

查看:126
本文介绍了吞咽手表立即终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常小的gulpfile,如下所示,注册一个监视任务:

  var gulp = require(gulp ); 
var jshint = require(gulp-jshint);
$ b gulp.task(lint,function(){
gulp.src(app / assets / ** / *。js)
.pipe(jshint( ))
.pipe(jshint.reporter(default));
});
$ b gulp.task('watch',function(){
gulp.watch(app / assets / ** / *。js,[lint]);
});

我无法让监视任务继续运行。

我清除了npm缓存,重新安装了依赖关系等,但没有骰子。

  $ gulp手表
[gulp]使用gulpfile gulpfile.js
[gulp]开始'手表' ...
[gulp] 23 ms后完成'watch'


解决方案

这不是退出,它本身是运行任务同步



您需要从 lint 任务返回流,否则gulp doesn' t

  gulp.task(lint,function(){
return gulp .src(./ src / *。js)
^^^^^^
.pipe(jshint())
.pipe(jshint.reporter(default)) ;
});






另外,您可能不想使用 gulp.watch 以及这类腕表的任务。使用 gulp-watch 插件可能更有意义您只能处理已更改的文件,如下所示:

  var watch = require('gulp-watch'); 

gulp.task('watch',function(){
watch({glob:app / assets / ** / *。js})
.pipe jshint())
.pipe(jshint.reporter(default));
});

当文件发生变化时,此任务不仅会起毛,还会添加所添加的任何新文件还有。


I have a very minimal gulpfile as follows, with a watch task registered:

var gulp = require("gulp");
var jshint = require("gulp-jshint");

gulp.task("lint", function() {
  gulp.src("app/assets/**/*.js")
    .pipe(jshint())
    .pipe(jshint.reporter("default"));
});

gulp.task('watch', function() {
  gulp.watch("app/assets/**/*.js", ["lint"]);
});

I cannot get the watch task to run continuously. As soon as I run gulp watch, it terminates immediately.

I've cleared my npm cache, reinstalled dependencies etc, but no dice.

$ gulp watch
[gulp] Using gulpfile gulpfile.js
[gulp] Starting 'watch'...
[gulp] Finished 'watch' after 23 ms

解决方案

It's not exiting, per se, it's running the task synchronously.

You need to return the stream from the lint task, otherwise gulp doesn't know when that task has completed.

gulp.task("lint", function() {
  return gulp.src("./src/*.js")
  ^^^^^^
    .pipe(jshint())
    .pipe(jshint.reporter("default"));
});


Also, you might not want to use gulp.watch and a task for this sort of watch. It probably makes more sense to use the gulp-watch plugin so you can only process changed files, sort of like this:

var watch = require('gulp-watch');

gulp.task('watch', function() {
  watch({glob: "app/assets/**/*.js"})
    .pipe(jshint())
    .pipe(jshint.reporter("default"));
});

This task will not only lint when a file changes, but also any new files that are added will be linted as well.

这篇关于吞咽手表立即终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆