我正在尝试使用livereload选项配置grunt-contrib-watch。我正在使用Ubuntu 13.04和Firefox 26.0 / Chrome
这是我的Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
watch: {
options: {
livereload: true
},
html: {
files: ['*.php', '*.html'],
}
}
});
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
};
这是index.html
<html>
<head>
<title>Grunt, Gruntfile.js</title>
</head>
<body>
<h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
<script src="//localhost:35729/example/livereload.js"></script>
</body>
</html>
我通过在终端启动 grunt watch 并在 localhost / example / index.html 打开浏览器来测试它,我尝试过Firefox和Chrome。< / p>
在尝试编辑index.html文件后,我注意到终端上的文件“index.html”已更改。,grunt watch正在运行,但浏览器根本没有自动重新加载。
我还安装了Firefox和Chrome LiveReload扩展程序,但它也无效。