Rails:对资产管道使用livereload [英] Rails: Use livereload with Asset Pipeline
问题描述
关于Rails专业人员的快速提问...
Quick question for rails pros out there...
在使用Rails 3.0.x应用程序时,我经常使用Guard和LiveReload.但是,似乎在Rails 3.1中使用资产管道时,livereload保护器不知道对Sass文件的更改应触发向浏览器发送新的CSS.
When working with Rails 3.0.x apps I was a heavy user of Guard and LiveReload. However, it seems that when using the asset pipeline in Rails 3.1 the livereload guard does not know that changes to a Sass file should trigger sending new css to the browser.
有人在资产管道中使用LiveReload吗?如果是这样,您如何使它工作?
Is anyone using LiveReload with the Asset Pipeline? If so, how are you making it work?
谢谢!
推荐答案
在Github上跟踪了一些问题线程之后,我发现以下问题已解决:
After following some issue threads on Github I found the following fixed my problem:
1)确保所有scss文件均按照新的资产约定命名,如下所示:filename.css.scss
1) Make sure all scss files are named following the new asset convention, like so: filename.css.scss
我在Rails 3.1之前使用scss,并且刚刚将我所有的sass文件命名为filename.scss
.
I was using scss before Rails 3.1 and had just named all my sass files filename.scss
.
2)将以下内容用于防护文件中的livereload:
2) Use the following for livereload in your guardfile:
guard 'livereload' do
watch(%r{app/helpers/.+\.rb})
watch(%r{app/views/.+\.(erb|haml)})
watch(%r{(public/).+\.(css|js|html)})
watch(%r{app/assets/stylesheets/(.+\.css).*$}) { |m| "assets/#{m[1]}" }
watch(%r{app/assets/javascripts/(.+\.js).*$}) { |m| "assets/#{m[1]}" }
watch(%r{lib/assets/stylesheets/(.+\.css).*$}) { |m| "assets/#{m[1]}" }
watch(%r{lib/assets/javascripts/(.+\.js).*$}) { |m| "assets/#{m[1]}" }
watch(%r{vendor/assets/stylesheets/(.+\.css).*$}) { |m| "assets/#{m[1]}" }
watch(%r{vendor/assets/javascripts/(.+\.js).*$}) { |m| "assets/#{m[1]}" }
watch(%r{config/locales/.+\.yml})
end
这篇关于Rails:对资产管道使用livereload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!