gulp


gulp.watch running same task multiple times when saving many files


Is there a way to configure gulp.watch to run task just once when multiple watched files change? I have my task setup like this:
var bs = require('browser-sync').create();
module.exports = function (gulp, plugins, config) {
return function watch() {
gulp.watch(
config.source.javascript,
// {debounceDelay: 500},
gulp.series('js', 'wp', bs.reload)
);
};
};
..and when I save multiple watched files at once (Save all in text editor), my gulp.series (I'm using gulp 4.0) tasks are run once for each changed file. Is there a way to change this and make gulp.watch run gulp.series tasks just once?
Thanks..
I've added a 'buffer' function like this:
var reload = false;
var delay = 500;
function brsync_reload(done) { brsync.reload(); queue_reset(done); }
function brsync_stream(done) { brsync.reload({ stream: true }); queue_reset(done); }
function queue_reload() { gulp.series(gulp.queue.concat(brsync_reload))(); }
function queue_stream() { gulp.series(gulp.queue.concat(brsync_stream))(); }
function queue_reset(done) { gulp.queue = []; reload = false; done(); }
function queue_tasks(tasks, last) {
reload = reload || last == brsync_reload;
gulp.queue = gulp.queue || [];
if (gulp.queue.length == 0)
setTimeout(reload ? queue_reload : queue_stream, delay);
gulp.queue = gulp.queue
.concat(tasks.filter(task => !gulp.queue.some(queued => queued == task)));
// console.log(gulp.queue);
}
brsync.init(CONFIG.BRSYNC);
gulp.watch(CONFIG.SRC.JAVASCRIPT, () => queue_tasks(['javascript'], brsync_reload));
gulp.watch(CONFIG.SRC.STATIC, () => queue_tasks(['static'], brsync_reload));
gulp.watch(CONFIG.SRC.STYLES, () => queue_tasks(['styles'], brsync_stream));
gulp.watch(CONFIG.SRC.TYPESCRIPT, () => queue_tasks(['typescript'], brsync_reload));
Now, when I change one file output is:
[21:40:17] Starting '<anonymous>'...
[21:40:17] Starting '<anonymous>'...
[21:40:18] Starting 'typescript'...
[21:40:21] Finished 'typescript' after 3.16 s
[21:40:21] Starting 'brsync_reload'...
[21:40:21] Finished 'brsync_reload' after 2.73 ms
...when I change 3 files (2x typescripe, 1x stylus), output is:
[21:41:19] Starting '<anonymous>'...
[21:41:19] Starting '<anonymous>'...
[21:41:19] Starting '<anonymous>'...
[21:41:19] Starting '<anonymous>'...
[21:41:19] Starting '<anonymous>'...
[21:41:19] Starting '<anonymous>'...
[21:41:20] Starting 'typescript'...
[21:41:22] Finished 'typescript' after 2.02 s
[21:41:22] Starting 'styles'...
[21:41:23] Finished 'styles' after 1.82 s
[21:41:23] Starting 'brsync_reload'...
[21:41:23] Finished 'brsync_reload' after 1.92 ms
Works nicely, only these logs of anonymous functions are annoying (;

Related Links

Is there a gulp plugin that can create empty folder / sub-folder structures?
How do I copy partial paths into the gulp destination [duplicate]
How could i code this more efficiently? - a gulp task
Gulp not executing the zip task
GULP Sprite create SCSS
gulp-stubby-server dosen't work well
How to get Gulp4 to wait for file write tasks to compete?
Jasmine tests in Karma - Uncaught Error: Cannot find module
External SASS Sources in Gulp.js
Any gulp task to concatenate and override properties
Unuglify Code with Gulp and Sourcemaps
Update bower package configured by git url branch
how cann I show console.log() with gulp
Error: Cannot find module 'gulp-minify-css'
How to Load Data into Gulp dynamically?
Error while requiring gulp-tslint

Categories

HOME
pact
spring-boot
logging
model-view-controller
ssh
service
qemu
python-requests
stdout
query-string
datetimepicker
confluence-rest-api
wavefront
vichuploaderbundle
solidity
console-application
google-closure-compiler
brightway
openscad
orange
cherrypy
android-navigation-drawer
typedef
bootstrap-accordion
mongoose-im
pydub
marionette
large-files
setup-project
edsdk
boost-log
foxpro
tikz
circle
epub
node-soap
incapsula
odp.net
minitest
hippocms
outlook-2010
iterm2
linkurious
delphi-xe
collation
ocamlbuild
jks
serialversionuid
jcifs
jenkins-docker
sharpssh
zedgraph
suitesparse
blackberry-webworks
deck.js
cosign-api
falcon
weblogic-maven-plugin
transaction-isolation
nugetgallery
music-player
jsondoc
fadein
bluetooth-lowenergy-4.2
wonderware
recode
database-project
transbase
photogrammetry
vectordrawable
skview
gmaps4jsf
asp.net-2.0
indices
grunt-contrib-connect
formbuilder
windows-search
pnunit
sat4j
oxygenxml
dotcmis
xts
disabled-control
winrun4j
surfaceview
myrrix
nokogiri
record-locking
stringstream
dynamic-expresso
freeimage
big-endian
states
datasheet
jqueryi-ui-buttonset
utm
cgaffinetransform
openwrap
opendir
jquery-click-event
qvariant
excellibrary
onunload
conditional-operator
xslt-grouping
linq-to-mysql
for-xml
konsole

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App