rails 3.1资产管道:忽略gem中的资产 [英] rails 3.1 asset pipeline: ignore assets from a gem

查看:71
本文介绍了rails 3.1资产管道:忽略gem中的资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定实际行为是什么,所以我的第一个问题是:
是否总是编译来自gem(在我的例子中为Spree)中的资产(例如javascript)?我不使用Spree的javascript,因此不希望它们被编译.我不需要在 application.js 或任何其他javascript文件中使用它们,但是

I'm not quite sure what the actual behavior is, so my first question is:
Are assets (e.g. javascripts) from a gem (in my case Spree) always compiled? I don't use Spree's javascripts, and therefore don't want them to be compiled. I don't require them in my application.js or any other javascript file, but

rake assets:precompile

仍然编译它们.我只是不想让他们躺在我的 public/assets 文件夹中.

compiles them nonetheless. I just don't want them lying around in my public/assets folder.

所以我想我的问题是,有没有办法禁止从gem编译javascript?

So I guess my question is, is there a way to disable compiling javascripts from a gem?

推荐答案

我想有一种聪明的方法可以使用 sprockets 实现目标.也许有些 require_directory 而不是 require_tree .

I guess there is a smart way to achieve your goal using sprockets. Maybe some require_directory instead of require_tree.

但是最直接的事情是从您的资产路径中删除这些资产.为此,请在 application.rb 文件的最后添加 (在初始化程序中不起作用):

But the most direct thing would be to remove theses assets from your assets paths. To achieve this, add this at the very end of your application.rb file (doesn't work in an initializer):

class Engine < Rails::Engine
   initializer "remove assets directories from pipeline" do |app|
     app.config.assets.paths = app.config.assets.paths - app.config.assets.paths.grep(/nice_regexp_here_to_match_the_dir_where_the_unwanted_files_live/)
   end
end


刚刚尝试了一种破解方法:将代码放入 initializer 中,但要求在 application.rb 的末尾:

require "config/initializers/your_file'

我希望通过这种方式可以看到非常具体的代码.

I prefer very specific code to be visible this way.

这篇关于rails 3.1资产管道:忽略gem中的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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