Gulp.js,保存文件时监视任务运行两次

Gulp.js, watch task runs twice when saving files(Gulp.js,保存文件时监视任务运行两次)
本文介绍了Gulp.js,保存文件时监视任务运行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

鉴于我的 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 保存了一个临时文件或类似文件,这会导致 gulp watch 函数运行两次.

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,保存文件时监视任务运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)