另一个问题“在开发中禁用Sprockets资产缓存”解决了如何在Rails 3.2中禁用Sprockets缓存。您如何在Rails 4上做同样的事情?我正在研究资产管道中深处的一颗宝石,不得不清除tmp/cache/*
并重新启动Rails变得很累。
如果查看Sprockets源,可以看到ifcache_classes
为true,然后app.assets
将其设置为app.assets.index
,并且不再检查文件系统。
为了在开发中解决此问题,您可以在配置中添加类似于以下内容的内容development.rb
:
# 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 :: Index 1覆盖之前就引起了人们的崇敬,并允许检查文件系统中是否有新资产,即使该属性cache_classes
为true。这似乎在开发中对我们有用,因此希望它对其他人也有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句