如何使用guard-livereload编写Javascript项目?

时间:2012-08-11 10:40:19

标签: javascript ruby google-chrome google-chrome-extension guard

我想开始学习JS。 我发现了gem guard-livereload。

在我的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扩展程序打开Chrome(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

My Guard版本:

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

*** LOCAL GEMS ***

guard (1.3.0)
guard-livereload (1.0.0)

一切似乎都有效,但Chrome不刷新页面。

1 个答案:

答案 0 :(得分:2)

在Chrome中,您必须明确授予文件网址的扩展权限。右键单击LiveReload图标,转到管理扩展,并为文件URL提供LiveReload权限。