Go to file
2012-10-16 16:31:34 -07:00
tasks Fix and add tests for spawn once and interrupt 2012-10-16 16:31:34 -07:00
test Fix and add tests for spawn once and interrupt 2012-10-16 16:31:34 -07:00
.gitignore first commit 2012-09-17 16:01:19 -05:00
.jshintrc Updates to run on Grunt v0.4 2012-10-09 15:10:58 -07:00
.travis.yml Add .travis.yml file 2012-10-08 22:47:41 -07:00
AUTHORS docs 2012-09-17 16:03:20 -05:00
CHANGELOG Only spawn per task one at a time. Add interrupt option. 2012-10-16 15:23:43 -07:00
Gruntfile.js Fix line endings from windows to unix 2012-10-16 15:25:07 -07:00
LICENSE-MIT prep for 0.4 2012-10-03 13:14:12 -05:00
package.json Bump v0.1.1 2012-10-16 14:11:42 -07:00
README.md Fix and add tests for spawn once and interrupt 2012-10-16 16:31:34 -07:00

grunt-contrib-watch Build Status

Run predefined tasks whenever watched file patterns are added, changed or deleted.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-contrib-watch

Then add this line to your project's Gruntfile.js gruntfile:

grunt.loadNpmTasks('grunt-contrib-watch');

Overview

Inside your Gruntfile.js file, add a section named watch. This section specifies the files to watch, tasks to run when an event occurs and the options used.

files string|array

This defines what file patterns this task will watch. Can be a string or an array of files and/or minimatch patterns.

tasks string|array

This defines which tasks to run when a watched file event occurs.

options array

This controls how this task operates and should contain key:value pairs, see options below.

Options

There are a number of options available. Please review the minimatch options here. As well as some additional options as follows:

interrupt boolean

As files are modified this watch task will spawn tasks in child processes. The default behavior will only spawn a new child process per target when the previous process has finished. Set the interrupt option to true to terminate the previous process and spawn a new one upon later changes.

Example:

watch: {
  scripts: {
    files: '**/*.js',
    tasks: ['jshint'],
    options: {
      interrupt: true
    }
  }
}
debounceDelay integer

How long to wait before emitting events in succession for the same filepath and status. For example if your Gruntfile.js file was changed, a changed event will only fire again after the given milliseconds. Default is 500ms.

Example:

watch: {
  scripts: {
    files: '**/*.js',
    tasks: ['jshint'],
    options: {
      debounceDelay: 250
    }
  }
}
interval integer

The interval is passed to fs.watchFile. Since interval is only used by fs.watchFile and this watcher also uses fs.watch; it is recommended to ignore this option. Default is 100ms.

Config Examples

// Simple config to run jshint any time a file is added, changed or deleted
grunt.initConfig({
  watch: {
    files: '**/*',
    tasks: ['jshint']
  }
});
// Advanced config. Run specific tasks when specific files are added, changed or deleted.
grunt.initConfig({
  watch: {
    gruntfile: {
      files: 'Gruntfile.js',
      tasks: ['jshint:gruntfile'],
      options: {
        nocase: true
      }
    },
    src: {
      files: ['lib/*.js', 'css/**/*.scss', '!lib/dontwatch.js'],
      tasks: ['default']
    },
    test: {
      files: '<%= jshint.test.src %>',
      tasks: ['jshint:test', 'qunit']
    }
  }
});