You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.3 KiB

  1. # Settings
  2. There are a number of options available. Please review the [minimatch options here](https://github.com/isaacs/minimatch#options). As well as some additional options as follows:
  3. ## files
  4. Type: `String|Array`
  5. This defines what file patterns this task will watch. Can be a string or an array of files and/or minimatch patterns.
  6. ## tasks
  7. Type: `String|Array`
  8. This defines which tasks to run when a watched file event occurs.
  9. ## options.nospawn
  10. Type: `Boolean`
  11. Default: false
  12. This instructs the watch task to not spawn task runs in a child process. Setting this option also speeds up the reaction time of the watch (usually 500ms faster for most) and allows subsequent task runs to share the same context (i.e., using a reload task). Not spawning task runs can make the watch more prone to failing so please use as needed.
  13. Example:
  14. ```js
  15. watch: {
  16. scripts: {
  17. files: ['**/*.js'],
  18. tasks: ['livereload'],
  19. options: {
  20. nospawn: true
  21. }
  22. }
  23. }
  24. ```
  25. ## options.interrupt
  26. Type: `Boolean`
  27. Default: false
  28. 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.
  29. Example:
  30. ```js
  31. watch: {
  32. scripts: {
  33. files: '**/*.js',
  34. tasks: ['jshint'],
  35. options: {
  36. interrupt: true
  37. }
  38. }
  39. }
  40. ```
  41. ## options.debounceDelay
  42. Type: `Integer`
  43. Default: 500
  44. 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.
  45. Example:
  46. ```js
  47. watch: {
  48. scripts: {
  49. files: '**/*.js',
  50. tasks: ['jshint'],
  51. options: {
  52. debounceDelay: 250
  53. }
  54. }
  55. }
  56. ```
  57. ## options.interval
  58. Type: `Integer`
  59. Default: 100
  60. 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*.
  61. #### options.event
  62. Type: `String|Array`
  63. Default: `'all'`
  64. Specify the type watch event that trigger the specified task. This option can be one or many of: `'all'`, `'changed'`, `'added'` and `'deleted'`.
  65. Example:
  66. ```js
  67. watch: {
  68. scripts: {
  69. files: '**/*.js',
  70. tasks: ['generateFileManifest'],
  71. options: {
  72. event: ['added', 'deleted']
  73. }
  74. }
  75. }
  76. ```
  77. ## options.forever
  78. Type: `Boolean`
  79. Default: true
  80. This is *only a task level option* and cannot be configured per target. By default the watch task will duck punch `grunt.fatal` and `grunt.warn` to try and prevent them from exiting the watch process. If you don't want `grunt.fatal` and `grunt.warn` to be overridden set the `forever` option to `false`.
  81. ## options.livereload
  82. Type: `Boolean|Number|Object`
  83. Default: false
  84. Set to `true` or set `livereload: 1337` to a port number to enable live reloading. Default and recommended port is `35729`.
  85. If enabled a live reload server will be started with the watch task per target. Then after the indicated tasks have ran, the live reload server will be triggered with the modified files.
  86. Example:
  87. ```js
  88. watch: {
  89. css: {
  90. files: '**/*.sass',
  91. tasks: ['sass'],
  92. options: {
  93. livereload: true,
  94. },
  95. },
  96. },
  97. ```