gulp-watch
![Dependency Status](https://camo.githubusercontent.com/f2b3e5bd8653cb92f98378b269a148e8ad88787de0831bc063820161adedf87e/687474703a2f2f696d672e736869656c64732e696f2f64617669642f666c6f617464726f702f67756c702d77617463682e7376673f7374796c653d666c6174)
File watcher that uses super-fast chokidar and emits vinyl objects.
Run npm install --save-dev gulp-watch
.
var gulp = require('gulp'),
watch = require('gulp-watch');
gulp.task('stream', function () {
return gulp.src('css/**/*.css')
.pipe(watch('css/**/*.css'))
.pipe(gulp.dest('build'));
});
gulp.task('callback', function (cb) {
watch('css/**/*.css', function () {
gulp.src('css/**/*.css')
.pipe(watch('css/**/*.css'))
.on('end', cb);
});
});
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 a watcher that will spy on files that are matched by glob
which can be a
glob string or array of glob strings.
Returns a pass through stream that will emit vinyl files
(with additional event
property) that corresponds to event on file-system.
This function is called when events happen on the file-system.
All incoming files that are piped in are grouped and passed to the events
stream as is.
vinyl
โ is vinyl object that corresponds to the file that caused the event. Additionalevent
field is added to determine what caused changes.
Possible events:
add
- file was added to watch or createdchange
- file was changedunlink
- file was deleted
This object is passed to the chokidar
options directly. Options for gulp.src
are also available. If you do not want content from watch
, then add read: false
to the options
object.
options.ignoreInitial
Type: Boolean
Default: true
Indicates whether chokidar should ignore the initial add events or not.
Type: Array
Default: ['add', 'change', 'unlink']
List of events, that should be watched by gulp-watch. Contains event names from chokidar.
Type: String
Default: undefined
Use explicit base path for files from glob
. Read more about base
and cwd
in gulpjs docs.
Type: String
Default: undefined
Name of the watcher. If it is present in options, you will get more readable output.
Type: Boolean
Default: false
This option will enable verbose output.
Type: Number
Default: 10
Wait for readDelay
milliseconds before reading the file.
Returned Stream
from constructor has some useful methods:
add(path / paths)
unwatch(path / paths)
close()
All events from chokidar:
add
,change
,unlink
,addDir
,unlinkDir
,error
,ready
,raw
MIT (c) 2014 Vsevolod Strukchinsky ([email protected])