当grunt-contrib-watch与grunt-express结合使用时,浏览器负载不工作

browser livereload not working when using grunt-contrib-watch with combination of grunt-express

本文关键字:浏览器 负载 工作 grunt-contrib-watch grunt-express 结合      更新时间:2023-09-26

我开始测试grunt watch插件(grunbt-contrib-watch)和grunt express服务器(grunt-express)组合的肝脏负载能力。我的目录在根目录下有一个gruntfile.js文件,所有的NPM模块都安装在npm_modules文件夹中,还有一个名为"build"的文件夹,其中包含一个HTML文件。使用NPM安装的3个包:

  1. 繁重
  2. grunt-contrib-watch
  3. grunt-express

他们工作得很好。手表插件成功地观看html文件,服务器运行在localhost:3000,唯一的问题是,当我改变html文件时,快递插件的liverload属性不工作。我不知道为什么?

my 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']);

};

on watch config add:

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

ref link: http://thanpol.as/grunt/Grunt-with-express-server-and-Livereload/