gulp-watch
Watch, that actually is an endless stream
Last updated 6 years ago by floatdrop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install gulp-watch 
SYNC missed versions from official npm registry.

gulp-watch Build Status: Linux Build Status: Windows Dependency Status

File watcher that uses super-fast chokidar and emits vinyl objects.

Installation

npm install --save-dev gulp-watch

Usage

var gulp = require('gulp'),
    watch = require('gulp-watch');

gulp.task('stream', function () {
	// Endless stream mode
    return watch('css/**/*.css', { ignoreInitial: false })
        .pipe(gulp.dest('build'));
});

gulp.task('callback', function () {
	// Callback mode, useful if any plugin in the pipeline depends on the `end`/`flush` event
    return watch('css/**/*.css', function () {
        gulp.src('css/**/*.css')
            .pipe(gulp.dest('build'));
    });
});

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.

API

watch(glob, [options, callback])

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.

Callback function(vinyl)

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. Additional event field is added to determine what caused changes.

Possible events:

  • add - file was added to watch or created
  • change - file was changed
  • unlink - file was deleted

Options

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.

options.events

Type: Array
Default: ['add', 'change', 'unlink']

List of events, that should be watched by gulp-watch. Contains event names from chokidar.

options.base

Type: String
Default: undefined

Use explicit base path for files from glob. Read more about base and cwd in gulpjs docs.

options.name

Type: String
Default: undefined

Name of the watcher. If it is present in options, you will get more readable output.

options.verbose

Type: Boolean
Default: false

This option will enable verbose output.

options.readDelay

Type: Number
Default: 10

Wait for readDelay milliseconds before reading the file.

options.read

Type: Boolean
Default: true

Setting this to false will return file.contents as null and not read the file at all. Most useful as an optimization if your plugins pipeline doesn't make use of the file contents (e.g. gulp-clean), or to avoid reading the file twice if you use gulp.src() inside the callback instead of the file object that is passed as argument.

Methods

Returned Stream from constructor has some useful methods:

  • add(path / paths)
  • unwatch(path / paths)
  • close()

Events

All events from chokidar:

  • add, change, unlink, addDir, unlinkDir, error, ready, raw

Changelog

License

MIT (c) 2014 Vsevolod Strukchinsky (floatdrop@gmail.com)

Current Tags

  • 0.7.0-alpha2                                ...           0.7.0-alpha2 (11 years ago)
  • 0.7.0-alpha3                                ...           0.7.0-alpha3 (10 years ago)
  • 4.2.5                                ...           beta (9 years ago)
  • 5.0.1                                ...           latest (6 years ago)

84 Versions

  • 5.0.1                                ...           6 years ago
  • 5.0.0                                ...           7 years ago
  • 4.3.11                                ...           8 years ago
  • 4.3.10                                ...           8 years ago
  • 4.3.9                                ...           8 years ago
  • 4.3.8                                ...           9 years ago
  • 4.3.7                                ...           9 years ago
  • 4.3.6                                ...           9 years ago
  • 4.3.5                                ...           9 years ago
  • 4.3.4                                ...           9 years ago
  • 4.3.3                                ...           9 years ago
  • 4.3.2                                ...           9 years ago
  • 4.3.1                                ...           9 years ago
  • 4.3.0                                ...           9 years ago
  • 4.2.5                                ...           9 years ago
  • 4.2.4                                ...           10 years ago
  • 4.2.3                                ...           10 years ago
  • 4.2.2                                ...           10 years ago
  • 4.2.1                                ...           10 years ago
  • 4.2.0                                ...           10 years ago
  • 4.1.1                                ...           10 years ago
  • 4.1.0                                ...           10 years ago
  • 4.0.3                                ...           10 years ago
  • 4.0.2                                ...           10 years ago
  • 4.0.1                                ...           10 years ago
  • 4.0.0                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.2.1                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.0.8                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.7                                ...           10 years ago
  • 1.0.6                                ...           10 years ago
  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.7.1                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.10                                ...           10 years ago
  • 0.6.9                                ...           10 years ago
  • 0.7.0-alpha3                                ...           10 years ago
  • 0.6.8                                ...           11 years ago
  • 0.6.7                                ...           11 years ago
  • 0.6.6-1                                ...           11 years ago
  • 0.7.0-alpha2                                ...           11 years ago
  • 0.6.6                                ...           11 years ago
  • 0.6.5                                ...           11 years ago
  • 0.6.4                                ...           11 years ago
  • 0.6.3                                ...           11 years ago
  • 0.6.2                                ...           11 years ago
  • 0.6.1                                ...           11 years ago
  • 0.6.0                                ...           11 years ago
  • 0.5.4                                ...           11 years ago
  • 0.5.3                                ...           11 years ago
  • 0.5.2                                ...           11 years ago
  • 0.5.0                                ...           11 years ago
  • 0.4.2                                ...           11 years ago
  • 0.4.1                                ...           11 years ago
  • 0.4.0                                ...           11 years ago
  • 0.3.4                                ...           11 years ago
  • 0.3.3                                ...           11 years ago
  • 0.3.2                                ...           11 years ago
  • 0.3.1                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.7                                ...           11 years ago
  • 0.2.6                                ...           11 years ago
  • 0.2.5                                ...           11 years ago
  • 0.2.4                                ...           11 years ago
  • 0.2.3                                ...           11 years ago
  • 0.2.2                                ...           11 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.3                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Maintainers (2)
Downloads
Total 8
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 6
Dependencies (12)
Dev Dependencies (11)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE