diff --git a/docs/watch-options.md b/docs/watch-options.md index a8e5509..40d5a1f 100644 --- a/docs/watch-options.md +++ b/docs/watch-options.md @@ -198,6 +198,9 @@ Default: `process.cwd()` Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks. Or an object to set each independently. Such as `options: { cwd: { files: 'match/files/from/here', spawn: 'but/spawn/files/from/here' } }`. +Set `options: { cwd: { files: 'a/path', event: 'a/path' }}` to strip off `a/path` before emitting events. This option is useful for specifying the base directory to use with livereload. + + ## options.livereloadOnError Type: `Boolean` Default: `true` diff --git a/tasks/watch.js b/tasks/watch.js index e309d1c..547b0b0 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -95,6 +95,11 @@ module.exports = function(grunt) { target.options.event = [target.options.event]; } + var eventCwd = process.cwd(); + if (target.options.cwd && target.options.cwd.event) { + eventCwd = target.options.cwd.event; + } + // Set cwd if options.cwd.file is set if (typeof target.options.cwd !== 'string' && target.options.cwd.files) { target.options.cwd = target.options.cwd.files; @@ -128,7 +133,7 @@ module.exports = function(grunt) { return; } - filepath = path.relative(process.cwd(), filepath); + filepath = path.relative(eventCwd, filepath); // Skip empty filepaths if (filepath === '') {