我使用 grunt-contrib-watch 任务(v. 0.5.3)来启用 LiveReload:
livereload: {
options: {
middleware: function (connect) {
return [lrSnippet, mountFolder(connect, '.tmp'),
mountFolder(connect, 'src'),
proxySnippet];
}
}
}
//...some other tasks...
watch: {
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'src/*.html'
]
}
}
//...................................
grunt.registerTask('server', [
'clean:server',
'recess:compile',
'configureProxies',
'connect:livereload',
'open',
'watch'
]);
在运行grunt server --verbose
(包括watch
任务)时,我最终得到以下控制台输出:
Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.livereload.files exists in config...OK
Live reload server started on port: 35729
Watching src/404.html for changes.
Watching src/app for changes.
Watching src/assets for changes.
Watching src/common for changes.
Watching src/less for changes.
Watching src/vendor for changes.
Watching src/index.html for changes.
例如,我们在这里看到的src/index.html
是观察到的,因此我尝试更改页面标题以查看实时修改。但是,一旦我保存我的文件,进程就会退出..
我了解到watch
如果提供的文件路径无效,任务可能会退出。但是,Watching src/index.html for changes
断言它存在,不是吗?
我不明白。