3

我想开始学习JS。 我发现了宝石守卫 - livereload。如何使用guard-livereload编写JavasScript项目?

在我的Rails应用程序中,它的效果很好。但我想用它来为简单的JS脚本重新加载本地文件。

所以我安装了guard-livereload到rvm gemset global。创建新的目录javascript 加入Guardfile

# https://github.com/guard/guard-livereload 
guard :livereload do 
    watch(%r{.+\.(html|css|js)$}) 
end 

与Livereload扩展名(1.6)

这是我的控制台打开浏览器:

> guard                                         /Users/rege/Code/javascript 1.9.3p194 @ 
Guard could not detect any of the supported notification libraries. 
Guard is now watching at '/Users/rege/Code/javascript' 
LiveReload 1.6 is waiting for a browser to connect. 
Browser connected. 
Browser URL: file://localhost/Users/rege/Code/javascript/examples/example_1_2.html 
Reloading browser: examples/example_1_2.html 
Reloading browser: examples/example_1_2.html 
Reloading browser: examples/example_1_2.html 

我的卫队版本:

> gem list guard                                       /Users/rege/Code/javascript 1.9.3p194 @ 

*** LOCAL GEMS *** 

guard (1.3.0) 
guard-livereload (1.0.0) 

所有似乎的作品但Chrome并没有刷新页面。

+0

它也不适用于我。我发现Firefox的这个附加组件也适用于JavaScript:http://stackoverflow.com/questions/8710613/livereload-not-working-guard-firefox – zigomir 2012-08-23 17:13:16

+0

你的问题帮助我使用livereload,谢谢! (我不知道我必须运行'guard'命令) – mik01aj 2012-11-28 08:14:50

回答

2

在Chrome中,您必须明确给文件URL添加扩展权限。右键单击LiveReload图标,转到管理扩展,并授予LiveReload权限以提交URL。