LoginSignup
42
49

More than 5 years have passed since last update.

guard-livereloadを使う

Last updated at Posted at 2013-05-01

viewのファイルやjs, cssを更新した時に、ブラウザが自動更新するようになる。

導入

Gemfileに追加して、gemをインストールする。

Gemfile
group :development do
  gem 'guard-livereload'
end
$ bundle install
$ bundle exec guard init livereload

Guardfileが作成されて以下の内容が追加される。監視するファイルはプロジェクトによって適宜変更するとよさそう。

Guardfile
guard 'livereload' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{public/.+\.(css|js|html)})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end

guardを起動する。

$ bundle exec guard

livereloadのブラウザ拡張をインストールする。chrome拡張
拡張機能の設定で「ファイルの URL へのアクセスを許可する」にチェックを入れる。
firefoxのアドオンではなぜかうまくいきませんでした。(設定等必要??)

Rails等を起動する。

これでGuardfileで指定されたファイルを更新すると、ブラウザが自動更新するようになる。

参考

あとがき

書いてから気づいたけど、ほぼ README の内容だったorz

42
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
49