当grunt-contrib-watch与grunt-express结合使用时,浏览器livereload无法正常工作

时间:2015-07-16 20:12:21

标签: javascript node.js gruntjs livereload

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

  1. 咕噜
  2. 咕噜-的contrib手表
  3. 咕噜快车
  4. 他们工作正常。 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']);
    

    };

1 个答案:

答案 0 :(得分:0)

on watch config add:

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

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

相关问题