在开发中禁用Sprockets资产缓存 [英] Disable Sprockets asset caching in development

查看:43
本文介绍了在开发中禁用Sprockets资产缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.2.13和Rails资产管道.我想使用Asset Pipeline,以便可以对资产使用SASS,CoffeeScript和ERB,并让Pipeline自动编译它们,因此无法在开发中关闭管道.我从来没有在开发中预先编译资产,甚至没有public/assets/目录.

I'm using Rails 3.2.13 and the Rails Asset Pipeline. I want to use the Asset Pipeline so I can use SASS and CoffeeScript and ERB for my assets and have the Pipeline automatically compile them, so I cannot turn off the pipeline in development. I am not precompiling assets in development ever and there is not even a public/assets/ directory.

但是,当我更改包含文件(例如,包含在(cc)文件中的(渲染)的_partial.html.erb文件)时,却不更改文件本身(在本例中为layout.html.erb ),Sprockets不会检测到更改并使缓存无效,因此我会不断获取相同的过时文件.在主动开发中执行此操作时,我想禁用资产的任何缓存,以便我可以对每个请求进行更改,但是我不知道如何执行此操作.我在development.rb中设置了以下所有内容:

However, when I make changes to an included file, such as to a _partial.html.erb file that is included (rendered) in a layout.html.erb file, without changing the file doing the including itself (in this example layout.html.erb), Sprockets doesn't detect the change and invalidate the cache, so I keep getting the same stale file. When I'm doing this in active development, I want to disable any caching of assets so I can get the changes on every request but I cannot figure out how to do this. I have set all of the following in my development.rb:

config.action_controller.perform_caching = false
config.action_dispatch.rack_cache =  nil
config.middleware.delete Rack::Cache
config.assets.debug = true
config.assets.compress = false
config.cache_classes = false

尽管如此,文件仍显示在tmp/cache/assets/tmp/cache/sass/下,并且将来的请求中无法进行更改.现在,每次我想查看更改时,我都必须手动删除这些目录.

Still, even with this, files show up under tmp/cache/assets/ and tmp/cache/sass/ and changes are not available on future requests. Right now I have to manually delete those directories every time I want to see a change.

不幸的是,《资产管道RoR指南》中缓存的工作方式部分的全部内容是:

Unfortunately, the entire contents of the How Caching Works section of the RoR Guide for the Asset Pipeline is:

Sprockets使用默认的Rails缓存存储区来缓存资产 开发和生产.

Sprockets uses the default Rails cache store to cache assets in development and production.

TODO:添加有关更改默认存储的更多信息.

TODO: Add more about changing the default store.

那么,如何让Sprockets按需编译资产而不缓存结果?

So, how can I get Sprockets to compile assets on demand but not cache the results?

推荐答案

这是魔咒:

config.assets.cache_store = :null_store  # Disables the Asset cache
config.sass.cache = false  # Disable the SASS compiler cache

资产管道具有自己的缓存实例,并且设置config.assets.cache = false不会执行任何操作,因此您必须将其缓存设置为null_store才能禁用它.

The asset pipeline has it's own instance of a cache and setting config.assets.cache = false does nothing, so you have to set its cache to be the null_store to disable it.

即使那样,SASS编译器也具有它自己的缓存,如果需要禁用它,则必须单独禁用它.

Even then, the SASS compiler has it's own cache, and if you need to disable it, you have to disable it separately.

这篇关于在开发中禁用Sprockets资产缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆