我很难让Grunt的“实时重新加载”功能(如grunt-contrib-watch
中实现的)在我的应用程序中起作用。最终我不得不咬紧牙关,尝试做出一个最小的示例。希望有人能轻松注意到缺少了什么。
文件结构:
├── Gruntfile.js
├── package.json
├── index.html
package.json
{
"name": "livereloadTest",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3"
}
}
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
src: {
files: ['*.html'],
options: { livereload: true }
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
};
index.html
<!doctype html>
<html>
<head><title>Test</title></head>
<body>
<p>....</p>
<script src="//localhost:35729/livereload.js"></script>
</body>
</html>
我接着运行grunt watch
,并且没有出现任何问题。然而,浏览器窗口没有自动打开(应该打开吗?)。
当我在chrome中打开http://localhost:35729/
时,我会收到这个json:
{"tinylr":"Welcome","version":"0.0.4"}
在该端口上尝试任何其他路径都会给我
{"error":"not_found","reason":"no such route"}