【问题标题】:Grunt livereload not workingGrunt livereload 不工作
【发布时间】:2013-07-23 15:28:18
【问题描述】:

我对 grunt 很陌生,我正在尝试启用 livereload。 问题是我似乎无法让它工作。

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"
  }
}

我没有收到任何错误, 我试过:“咕噜”和“咕噜 livereaload-start”。 通过 localhost 访问我的网站时 - 它无法连接。 并且通过file://协议查看网站在css文件发生变化时不会重新加载。

提前致谢。

【问题讨论】:

    标签: gruntjs livereload


    【解决方案1】:

    实时重新加载已移至监视任务。请看:https://github.com/gruntjs/grunt-contrib-watch#live-reloading

    grunt.initConfig({
      watch: {
        livereload: {
          options: { livereload: true },
          files: ['dist/**/*'],
        },
      },
    });
    

    【讨论】:

    • 谢谢!当我将手表版本更改为 ~0.4.0 时它起作用了
    猜你喜欢
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 2014-03-05
    • 2018-07-27
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多