0

In grunt-contrib-watch I want to watch for changes in both <%%= yeoman.app %>/*.html and changes to any HTML file one folder deeper.

Therefore, my watch task looks like this:

watch: {
    html: {
        files: ['<%%= yeoman.app %>/{,*/}*.html'],
        tasks: ['copy:html', 'replace', 'processhtml:dev']
    }
},

When I save changes to <%%= yeoman.app %>/index.html, the watch task runs as expected. However, when I create a directory inside <%%= yeoman.app %> then create newfile.html inside that new directory, watch doesn't get fired.

I have also tried files: ['<%%= yeoman.app %>/*.html', '<%%= yeoman.app %>/*/*.html'], and even files: ['<%%= yeoman.app %>/**/*.html'] to match all sub directories, but still watch doesn't fire when an HTML file inside the sub directory is edited.

What am I missing?

Fisu
  • 3,294
  • 9
  • 39
  • 61

1 Answers1

1

I think your underscore template is malformed. Try this instead:

files: ['<%= yeoman.app %>/**/*.html']

Running grunt watch --verbose will give you a list of all files that will be watched by the task. Make sure the paths you expect to be watched are in there.

Ben
  • 10,106
  • 3
  • 40
  • 58
  • Changing from `<%%=` to `<%=` causes the browser to hang, and besides all the rest of my tasks use `<%%=` format with no issue. Running `watch --verbose` simply states `Verifying property watch.html.files exists in config…OK` – Fisu Oct 16 '13 at 11:53
  • If you don't get any files listed when using the `--verbose` option then grunt isn't watching any files. You should get a bunch of lines like: `Watching some/path/to/example-file.html for changes.` Can you switch out the dynamic `<%%= yeoman.app %>` with an explicit directory that you know is valid, use the `/**/` syntax, and see what the `--verbose` option spits out? – Jordan Kasper Oct 16 '13 at 17:23
  • When I switch to a non-dynamic path: `app/**/*.html` I get the same problem - it responds to changes to `app/index.html` but not to changes to a newly created `app/new_dir/index.html`. Running `--verbose` does list all the HTML files I expect, but after creating `new_dir/index.html` I have to stop _watch_ then restart it to get it to watch `new_dir/index.html`. – Fisu Oct 16 '13 at 18:29
  • Ah. Looks like this is a known issue; have a look on the issues tracker for further information. https://github.com/gruntjs/grunt-contrib-watch/issues/166 – Ben Oct 16 '13 at 18:34