javascript - 将 grunt-contrib-watch 与 grunt-express 组合使用时,浏览器 livereload 不起作用

标签 javascript node.js gruntjs livereload

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

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

他们工作得很好。 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']);

};

最佳答案

在 watch 配置上添加:

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

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

关于javascript - 将 grunt-contrib-watch 与 grunt-express 组合使用时,浏览器 livereload 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31463669/

相关文章:

javascript - Kendo UI [DropDownList] - 多个元素中的冲突

javascript - 类似于页面布局的 Flipboard

javascript - 在 NodeJS 的 Controller 中返回 Promise 有什么意义吗?

node.js - 使用 .bat 文件启动 Node 服务器

node.js - 如何使用 grunt 将编译好的 Jade 文件复制到目标文件夹

javascript - 如何将 javascript 对象格式化为模式数据的 JSON 对象?

javascript - 使用延迟加载作为每次滚动的动画效果?

javascript - Node js Postgresql - 插入表时出错

python - NPM - 无法在 Windows 8.1 上安装 css-sprite

twitter-bootstrap - 将 Bootstrap config.json 文件与 Bower 一起使用