Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt livereload not working

I'm quite new to grunt, and I'm trying to enable livereload. The problem is that I can't seem to get it working.

Gruntfile.js:

module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
          '<%= grunt.template.today("yyyy-mm-dd") %> */'
      },
      my_target: {
        files: {
          'dest/complete.min.js': ['scripts/*.js']
        }
      }
    },
    jshint: {
      files: ['gruntfile.js', 'srcipts/*.js'],
      options: {
        // options here to override JSHint defaults
        globals: {
          jQuery: true,
          console: true,
          module: true,
          document: true
        }
      }
    },
    livereload  : {
      options   : {
        base    : '/',
      },
      files     : ['/**/*']
    },
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-livereload');

  grunt.registerTask('default', ['jshint', 'uglify','livereload']);

};

package.json:

{
  "name": "my-app",
  "version": "0.0.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-jshint": "~0.6.0",
    "grunt-contrib-livereload": "0.1.2",
    "matchdep": "~0.1.2"
  }
}

I don't get any errors, I've tried: "grunt" and "grunt livereaload-start". When going to my website via localhost - it won't connect. And viewing the website via the file:// protocol will not reload when changes are made to css files.

Thanks in advance.

like image 630
funerr Avatar asked Feb 01 '26 04:02

funerr


1 Answers

Live reloading has been moved to the watch task. Please see: https://github.com/gruntjs/grunt-contrib-watch#live-reloading

grunt.initConfig({
  watch: {
    livereload: {
      options: { livereload: true },
      files: ['dist/**/*'],
    },
  },
});
like image 141
Kyle Robinson Young Avatar answered Feb 04 '26 00:02

Kyle Robinson Young



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!