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