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

I can't get the data-uri() function to work on gulp.js to base64 an image on mac
How to inject bower dependencies in karma.conf.js file with gulp?
Getting Libsass Gulp Susy to work together
Gulp compass without config.rb
gulp-webserver: Default to index.html if available, else show directories
gulp-uglify notify on failing build
Declaring optional dependencies
gulp html minification error
Can an IIFE be added to a browserify bundle?
Gulp: Error Messages and Notifications with Plumber
Gulp - gulp-load-plugins not working
How to configure Gulp task to copy bower resources
gulp-jscs doesn't output anything when used in gulp-watch pipeline
ES6 project does not compile because modules not found
Gulp - can't set multiple relative destinations
Deploy a Yeoman Application With Gulp

Categories

HOME
autohotkey
postgresql
url
itunesconnect
formatting
python-requests
android-ndk
postsharp
boxplot
magento-1.9.2.1
query-string
google-docs-api
confluence-rest-api
perl6
glympse
scapy
virtualhost
ionic-native
phpexcel
ng2-charts
mbed
hql
background-image
dompdf
multibinding
novacode-docx
printf
passbook
gpo
sonarlint
rndis
ng-tags-input
jira-zephyr
rancher
knapsack-problem
continuous-fourier
multiple-inheritance
launchd
ocl
ios9
openoffice-impress
undo
deferred
directions
incapsula
azure-storage-files
realloc
stochastic-process
framebuffer
keychain
autodesk-data-management
rexx
libzip
taiga
servicebus
android-doze-and-standby
rivets.js
import.io
e4
jscoverage
vertex
webmatrix
nsalert
therubyracer
stripes
optional-parameters
mongodb-3.3
consolidation
symantec
visual-web-developer
sprockets
objectify
kik
window.location
paypal-subscriptions
jersey-test-framework
windows-kernel
jts
clearquest
stderr
jeet-grid
genero
asp.net-2.0
backtrace
crtdbg.h
caption
apache-pivot
diffmerge
os.walk
windows-search
banana-pi
azure-caching
node-amqp
facebook-likebox
kendo-window
infomaker
http-compression
cloudmade
feincms
yii-components
xcode4.6.3
pinchzoom
towerjs
rjs
discussion-board
xcdatamodel
arraycollection
oaw
database-agnostic
p4.net
dgml
qlibrary
software-update
weak-typing
hotfix

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