gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Basic watch is watching more files than I specified #481

Open jml6m opened 8 years ago

jml6m commented 8 years ago

This is in my Gruntfile.js:

watch: {
    dev: {
        files: [ 'Gruntfile.js' ],
        tasks: [ 'jshint' ]
    }
}

Yet when I run grunt watch:dev -v, it says it's watching all folders in my root:

Running "watch:dev" (watch) task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.dev.files exists in config...OK
Watching Gruntfile.js for changes.
Watching .git for changes.
Watching .sass-cache for changes.
Watching app for changes.
Watching config for changes.
Watching dist for changes.
Watching img for changes.
Watching node_modules for changes.
Watching styles for changes.
Watching tmp for changes.

Changing code to files: [ 'Gruntfile.js', '!node_modules/**' ] doesn't matter, it still prints out that same list of "watching"

facultymatt commented 8 years ago

+1 getting the same issue here.

emri99 commented 8 years ago

+1 Same here.

Seems to happen when watching file at project root path.

Below sample works as expected

grunt.initConfig({
        watch: {
            styles: {
                files: ['styles/**/*'],
                tasks: ['styleguide-generate'],
            }
        }
        ...
});
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.styles.files exists in config...OK
Watching styles for changes
Watching styles/XXXXX for changes....
Watching styles/XXXXX for changes....
....

Adding README.md to watch list produce more watch than expected:

grunt.initConfig({
        watch: {
            styles: {
                files: ['styles/**/*', 'README.md'],
                tasks: ['styleguide-generate'],
            }
        }
        ...
});
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.styles.files exists in config...OK
Watching styles for changes.
Watching README.md for changes.
Watching .git for changes.
Watching bower_components for changes.
Watching docs for changes.
Watching styles/XXXXX for changes....
Watching styles/XXXXX for changes....
....
jacksonrayhamilton commented 8 years ago

Thanks @emri99, was also experiencing this bug and that fixed it for me. The trick seems to be changing a glob like this: styles/** to this: styles/**/*.