Gulp Watch 只运行一次

编程入门 行业动态 更新时间:2024-10-07 18:30:05
本文介绍了Gulp Watch 只运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用这个 Gulp Watch 示例:github/floatdrop/gulp-watch/blob/master/docs/readme.md#starting-tasks-on-events.

I'm using this Gulp Watch sample: github/floatdrop/gulp-watch/blob/master/docs/readme.md#starting-tasks-on-events.

var gulp = require('gulp'); var watch = require('gulp-watch'); var batch = require('gulp-batch'); gulp.task('build', function () { console.log('Working!'); }); gulp.task('watch', function () { watch('**/*.js', batch(function () { gulp.start('build'); })); });

当我在我的 Windows 8 机器上运行它时,它只在我第一次更改文件时运行:

When I run it on my Windows 8 machine, it only runs the first time I change a file:

C: est>gulp watch [08:40:21] Using gulpfile C: estgulpfile.js [08:40:21] Starting 'watch'... [08:40:21] Finished 'watch' after 2.69 ms [08:40:31] Starting 'build'... Working! [08:40:31] Finished 'build' after 261 µs

下次什么都没有发生.为什么?

Next time nothing happens. Why?

推荐答案

如果您仔细阅读文档,您会看到以下短语:

If you read the documentation closely, you see the following phrase:

您可以传递普通回调,它将在每个事件上调用或将其包装在 gulp-batch 中以运行它一次

You can pass plain callback, that will be called on every event or wrap it in gulp-batch to run it once

所以,这基本上就是 gulp-batch 的处理.要持续观看,只需删除批处理调用:

So, that's basically the deal with gulp-batch. To constantly watch it, just remove the batch call:

gulp.task('build', function (done) { console.log('Working!'); done(); }); gulp.task('watch', function () { watch('app/*.js', function () { gulp.start('build'); }); });

(并将完成"回调添加到 build 以让 Gulp 知道您何时完成).

(and add the 'done' callback to build to let Gulp know when you're finished).

顺便说一句...我不确定,但我认为 gulp-watch 不仅意味着观看文件,而且还直接返回乙烯基对象.所以实际使用内置的 gulp.watch 应该也是一样的效果:

Btw... I'm not sure, but I think gulp-watch is meant to not only watch files, but also directly returning a vinyl object. So actually using the built-in gulp.watch should have the same effect:

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

更多推荐

Gulp Watch 只运行一次

本文发布于:2023-11-24 00:49:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Gulp   Watch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!