grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

How do you make grunt watch livereload ignore dotfiles?

Open mark0978 opened this issue 11 years ago • 11 comments

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...

mark0978 avatar Nov 24 '13 20:11 mark0978

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.

hyperscientist avatar Nov 24 '13 20:11 hyperscientist

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}',
      '!.**/*',
    ]
  }

shama avatar Nov 24 '13 21:11 shama

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

mark0978 avatar Nov 24 '13 23:11 mark0978

Ah I think that may be this upstream issue in shama/gaze#45

shama avatar Nov 25 '13 02:11 shama

Yea, I think you are onto something! Seems the the exact same problem.

mark0978 avatar Nov 25 '13 02:11 mark0978

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 avatar May 23 '14 15:05 pezra

@pezra More changes are needed in gaze before we can bump the dependency here.

shama avatar May 23 '14 15:05 shama

It's not just gaze, other grunt plugins seem guilty of this as well.

tleen avatar Jun 29 '14 12:06 tleen

Any update on this? It looks like gaze fixed the problem almost a year ago.

emosesSfdc avatar Mar 20 '15 23:03 emosesSfdc

@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.

vincentbernat avatar Aug 06 '15 17:08 vincentbernat

  1. 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
  2. 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?

shama avatar Aug 06 '15 17:08 shama