gulp-watch
Watch, that actually is an endless stream
This is an reimplementation of bundled gulp.watch
with an endless-stream approach. If gulp.watch
is working for you, stick with it; otherwise, you can try this gulp-watch
plugin.
The main reason for gulp-watch
's existence is that it can easily achieve per-file rebuilding on file change:
Run npm install gulp-watch
.
var gulp = require('gulp'),
watch = require('gulp-watch');
gulp.task('default', function () {
gulp.src('css/**/*.css')
.pipe(watch('css/**/*.css', function(files) {
return files.pipe(gulp.dest('./one/'));
}))
.pipe(gulp.dest('./two/'));
// `one` and `two` will contain same files
});
Protip: until gulpjs 4.0 is released, you can use gulp-plumber to prevent stops on errors.
More examples can be found in docs/readme.md
.
Creates watcher that will spy on files that were matched by glob
which can be a
node-glob
string or array of strings.
Returns pass through stream, that will emit vinyl files
(with additional event
property) that corresponds to event on file-system.
This function is called, when some group of events (that grouped with
gulp-batch
) is happens on file-system.
All incoming files that piped in will be grouped and passed to events
stream as is.
events
— isStream
of incoming events. Events will be grouped by timeout to prevent multiple tasks to be executed repeatedly by commands likegit pull
.done
— is callback for your function signal to batch once you are done. This allows you to run your callback as soon as the previousend
.done
can be omitter iff callback returningStream
orPromise
, otherwise it will block next events.
This object is passed to gaze
options directly (refer to gaze
documentation). For batched mode, we are using gulp-batch
, so options from there are also available. And of course options for gulp.src
are used too. If you do not want content from watch
, then add read: false
to the options
object.
Type: String
Default: undefined
Use explicit base path for files from glob
.
Type: String
Default: undefined
Name of the watcher. If it present in options, you will get more readable output:
Type: Boolean
/ undefined
Default: undefined
This options will enable more verbose output (on true
) or disable it completly (on false
).
Returned Stream
from constructor have some useful methods:
close()
— callinggaze.close
and emittingend
, aftergaze.close
is done.
Also it has _gaze
property to access Gaze instance.
end
— all files are stop being watched.ready
— just re-emitted event fromgaze
.error
— when something happened inside callback, you will get notified.
Before 2.0.0
version there was a bug in gulp-batch
- it does not prevent tasks to execute in same time. In 2.0.0
version of gulp-batch
was bumped.
This can cause your watch tasks to hang, if you do not calling done
in callback or returning Stream
/Promise
from it.
- watch is not emmiting files at start - read «Starting tasks on events» and «Incremental build» for workarounds.
- watch is now pass through stream - which means that streaming files into watch will not add them to gaze. It is very hard to maintain, because watch is not aware about
glob
, from which this files come from and can not re-create vinyl object properly without maintaining cache of thebase
properties of incoming files (yuck). - array of tasks is not accepted as callback - this was not working anyway, but rationale behind it - requiring gulp and calling internal method start is bad. This feature will become more clear, when gulp 4.0.0 will be released with new task system. Read «Starting tasks on events» for right way to do it.
MIT (c) 2014 Vsevolod Strukchinsky ([email protected])