Gulp.js,手表任务在保存文件时运行两次 [英] Gulp.js, watch task runs twice when saving files
问题描述
从我的gulpfile.js中获得以下代码片段,每次我保存或更改文件时,该任务将运行两次而不是一次,这是为什么?我只是想让它运行一次。
Given the following piece of code from my gulpfile.js, everytime I save or change a file, the task runs twice instead of one single time, why is that? I just want it to run one time.
var gulp = require('gulp');
gulp.task('default', function() {
gulp.watch('server/**/*.js', function(){
console.log('This runs twice everytime I change/save a javascript file located at server/**/*.js');
});
});
我也遇到过grunt和名为grunt-contrib-watch的插件。 >
I have also experienced the same with grunt and the plugin called grunt-contrib-watch.
推荐答案
似乎这个问题的答案是使用了Coda 2的编辑器的功能。根据这里的一些评论和使用多个编辑器进行测试,似乎Coda 2会保存一个临时文件或类似文件,并导致吞噬观察功能运行两次。
Seems like the answer to this question is a feature of the editor that was used, Coda 2. Based on some of the comments here and testing with multiple editors, it seems like Coda 2 saves a temporary file or similar and that causes the gulp watch function to be run twice.
我还没有找到可行的解决方案当使用Coda 2时,最终切换到Sublime Text 3。
I have not found a viable solution to this when using Coda 2, ended up with switching to Sublime Text 3.
这篇关于Gulp.js,手表任务在保存文件时运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!