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

sharing livereload with other concurrent tasks

Open amitport opened this issue 11 years ago • 2 comments

I'm using watch and nodemon with concurrent.

The problem is that nodemon restarts when server files change but only watch triggers livereload

currently, I use watch for watching server files and a simple '2SecDelay' task that gives nodemon time to restart the server.

So, I got a patch, but it's ugly:

grunt.registerTask '2SecDelay', 'just taking some time', ->
  done = @async()
  setTimeout((() -> done()), 2000)

...

nodemon:
  server:
    ... run server and watch server related files ...
watch:
  server: 
    files: ... same files as the nodemon watches ...
    tasks: ['2SecDelay']
concurrent:
  server:
    ['nodemon', 'watch']

any suggestions?

amitport avatar Dec 15 '13 13:12 amitport

I've had a similar issue, this might work for you.

...
concurrent: {
  dev: {
    tasks: ['nodemon', 'watch'],
    options: {
      logConcurrentOutput: true
    }
  }
},
nodemon: {
  dev: {
    script: 'server.js',
    options: {
      nodeArgs: ['--debug'],
      env: {
        PORT: '3000'
      },
      callback: function(nodemon) {
        nodemon.on('log', function(event) {
          console.log(event.colour);
        });

        // refresh on server reboot
        nodemon.on('restart', function() {
          // delay before server listens on port
          setTimeout(function() {
            require('fs').writeFileSync('.grunt/rebooted', 'rebooted');
          }, 1000);
        });
      }
    }
  }
},
watch: {
  server: {
    files: [
      '.grunt/rebooted'
      // , + other files to watch
    ],
    options: {
      livereload: true
    }
  }
}

Hope it helps.

parties avatar Feb 14 '14 23:02 parties

What I did ti was to make contact with the actual livereolad server

nodemon.on('restart', function() {
    setTimeout(() => request.post('http://localhost:35729/changed?files=public/scripts/client.js'), 1000);
});

Hope it helps someone else =)

ryanez avatar Aug 12 '16 18:08 ryanez