在Rails 4的开发中禁用Sprockets资产缓存 [英] Disable Sprockets asset caching in development on Rails 4
问题描述
另一个问题 在开发中禁用Sprockets资产缓存解决了如何在Rails 3.2中禁用Sprockets缓存。您如何在Rails 4上做同样的事情?我正在研究深入资产管道的宝石,必须清除 tmp / cache / *
并重新启动Rails会很累。
Another question "Disable Sprockets asset caching in development" addresses how to disable Sprockets caching in Rails 3.2. How do you do the same thing on Rails 4? I am working on a gem that is deep in the asset pipeline and having to clear tmp/cache/*
and restart Rails is getting tiring.
推荐答案
如果您查看链轮,请源,您可以看到,如果 cache_classes
为true,则 app.assets
设置为 app.assets.index
,并且不再检查文件系统。
If you look at the Sprockets source, you can see that if cache_classes
is true then app.assets
gets set to app.assets.index
, and the filesystem is no longer checked.
为了在开发中解决此问题,您可以添加类似于以下到您的 development.rb
配置:
In order to get around this in development, you can add something similar to the following to your development.rb
configuration:
# Sprockets configuration: prevent sprockets from caching assets in development
# when cache_classes is set to true
sprockets_env = nil
config.assets.configure do |env|
sprockets_env = env
# Sprockets environment configuration goes here
# env.js_compressor = :uglifier # or :closure, :yui
# env.css_compressor = :sass # or :yui
end
if config.cache_classes
config.after_initialize do
Rails.application.assets = sprockets_env
end
end
从本质上讲,这在Sprockets :: Environment对象被Sprockets ::覆盖之前就赢得了人们的崇敬:索引一,即使 cache_classes
为true,也允许检查文件系统中的新资产。这似乎在开发中对我们有用,因此希望它对其他人也有帮助。
This essentially grabs a reverence to the Sprockets::Environment object before it is overwritten by the Sprockets::Index one, and allows the filesystem to be checked for new assets even when cache_classes
is true. This seems to work for us in development, so hopefully it helps someone else out as well.
这篇关于在Rails 4的开发中禁用Sprockets资产缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!