gulp-watch
![Dependency Status](https://camo.githubusercontent.com/f2b3e5bd8653cb92f98378b269a148e8ad88787de0831bc063820161adedf87e/687474703a2f2f696d672e736869656c64732e696f2f64617669642f666c6f617464726f702f67756c702d77617463682e7376673f7374796c653d666c6174)
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
.
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
Default: false
This options will enable more verbose output (useful for debugging).
Returned Stream
from constructor have some useful methods:
close()
— callinggaze.close
and emittingend
, aftergaze.close
is done.
end
— all files are stop being watched.ready
— just re-emitted event fromgaze
.error
— when something happened inside callback, you will get notified.
- 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 (floatdrop@gmail.com)