【问题标题】:browser livereload not working when using grunt-contrib-watch with combination of grunt-express将 grunt-contrib-watch 与 grunt-express 结合使用时,浏览器 livereload 无法正常工作
【发布时间】:2015-07-16 20:12:21
【问题描述】:

我开始测试 grunt watch 插件 (grunbt-contrib-watch) 和 grunt express server (grunt-express) 组合的 livereload 能力。 我的目录在根目录中有一个 gruntfile.js 文件,所有 npm 模块都安装在 npm_modules 文件夹中,并且有一个名为“build”的文件夹包含一个 html 文件。 使用 npm 安装的 3 个软件包:

  1. 咕噜声
  2. grunt-contrib-watch
  3. 咕噜声

他们工作正常。 watch 插件正在成功观看 html 文件并且服务器在 localhost:3000 运行,唯一的问题是当我更改 HTML 文件时 express 插件的 livereload 属性不起作用。我不知道为什么?

我的 guntfile.js 如下所示:

module.exports = function(grunt) {
grunt.initConfig({
    watch: {
        html: {
            files: ['build/*.html'],
            tasks: []
        }
    },
    express: {
        all: {
            options: {
                bases: 'build',
                livereload: true,
                open: 'http://localhost:3000'
            }
        }
    }
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express');
grunt.registerTask('start', ['express','watch']);

};

【问题讨论】:

    标签: javascript node.js gruntjs livereload


    【解决方案1】:

    在手表配置上添加:

     options: {
              nospawn: true,
              atBegin: true,
            }
    

    参考链接:http://thanpol.as/grunt/Grunt-with-express-server-and-Livereload/

    【讨论】:

    • 恐怕这并没有解决问题。当我添加这两个选项时,它会启动服务器,但会显示无限次警告说它无法读取未定义的属性长度。
    猜你喜欢
    • 2017-03-18
    • 2014-03-21
    • 2017-06-12
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多