rails 3.1资产管道:忽略gem中的资产

编程入门 行业动态 更新时间:2024-10-26 19:31:05
本文介绍了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中的资产

本文发布于:2023-07-08 01:06:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资产   管道   rails   gem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!