grunt-contrib-watch
grunt-contrib-watch copied to clipboard
How do you make grunt watch livereload ignore dotfiles?
emacs creates some .files when a file is being edited, this is causing grunt to blow a gasket trying to deal with livereload. I think I could fix this if I just knew how to tell livereload to ignore dotfiles, but under the livereload task, I have:
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
If files was a "normal" object then I could just add
dot: false
and all would be well? Docs don't help with this problem at all...
Read http://gruntjs.com/configuring-tasks#globbing-patterns
this thing: "! at the beginning of a pattern will negate the match"
So just add one more rule that will search for filenames starting with a dot and then just negate it.
It should ignore dotfiles by default. Unless the dot
option is set:
watch: {
target: {
options: { dot: true },
files: ['lib/.test.js'],
},
},
You can explicitly ignore dot files like @kamiltrebunia said. Just make sure the pattern is at the end that you want to negate:
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'!.**/*',
]
}
So I've modified livereload like this:
livereload: {
options: {
livereload: '<%= connect.options.livereload %>',
dot: false
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'!.**/*'
]
}
And grunt keeps doing this:
Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.compass.files exists in config...OK
Verifying property watch.styles.files exists in config...OK
Verifying property watch.livereload.files exists in config...OK
Warning: ENOENT, no such file or directory '/home/mark/js/project/app/scripts/.#app.js'
Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.compass.files exists in config...OK
Verifying property watch.styles.files exists in config...OK
Verifying property watch.livereload.files exists in config...OK
Warning: ENOENT, no such file or directory '/home/mark/js/project/app/scripts/.#app.js'
several times a second
Ah I think that may be this upstream issue in shama/gaze#45
Yea, I think you are onto something! Seems the the exact same problem.
Gaze claims to have solved this problem in the 0.6.x series of Gaze. Any chance someone who is more familiar with these project could bump the dependency? (I tried but a few tests broke.)
@pezra More changes are needed in gaze before we can bump the dependency here.
It's not just gaze, other grunt plugins seem guilty of this as well.
Any update on this? It looks like gaze fixed the problem almost a year ago.
@shama What is missing to be able to update gaze dependency to 0.6? I am also hit by this bug and this is annoying.
- All tests need to pass (OSX, Linux, and Windows with Node.js v0.12, v0.10 and io.js) on this branch: https://github.com/shama/gaze/tree/navelgazer
- All tests need to pass (OSX, Linux, and Windows with Node.js v0.12, v0.10 and io.js) after integrating that next version of gaze here on grunt-contrib-watch
I'll get to it eventually (I've been saying that for a year sorry) but maybe there is a hero that could help get it done sooner?