Question

I am currently using Grunt and livereload, but for some reason in the last while it no longer does a full server restart when server files are changed. It is watching the server files and I get a Reload server/some_dir/some_file.js message when a file changes but that doesn't seem to be enough.

watch: {
  jade: {
    files: [
      '<%= yeoman.server %>/**/*.jade',
      '<%= yeoman.app %>/**/*.jade'
    ],
    tasks: ['jade']
  },
  compass: {
    files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
    tasks: ['compass']
  },
  livereload: {
    options: { livereload: true },
    files: [
      '{.tmp,<%= yeoman.server %>}/**/*.js',
      '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
      '{.tmp,<%= yeoman.app %>}/scripts/**/*.js',
      '{.tmp,<%= yeoman.app %>}/**/*.html',
      '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
    ],
    tasks: ['livereload']
  },
  server: {
    files:  [ './server/**/*' ],
    tasks:  [ 'express:dev', 'livereload-start' ]
  }
}

grunt.registerTask('server', [
  'clean:server',
  'jade',
  'compass:server',
  'express:dev',
  'livereload-start',
  'connect:livereload',  
  'watch'  // if I replace this with 'watch:server' the server does restart properly, but html/css updates are obviously gone
]);
Was it helpful?

Solution 2

Changing

server: {
  files:  [ './server/**/*' ],
  tasks:  [ 'express:dev', 'livereload-start' ]
}

to

server: {
  files:  [ './server/**/*' ],
  tasks:  [ 'express:dev', 'livereload' ]
}

Not sure what recent change caused this to break. According to git the former snippet was used since the start of the project.

OTHER TIPS

I'm not sure what version of these packages you're using but livereload is no longer (and hasn't been for a few months) a task in and of itself. It should now be run as an option of watch https://github.com/gruntjs/grunt-contrib-watch#optionslivereload.

Here's an example:

watch: {
    assets: {
        files: ['assets/**/*'],
        tasks: ['copy:assets']
    },
    scripts: {
        files: ['scripts/source/*.js'],
        options: {
            livereload: true
        }
    }
}

grunt.registerTask('default', ['watch']);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top