Rails 3.1 资产管道:忽略来自 gem 的资产
我不太确定实际行为是什么,所以我的第一个问题是:
来自 gem(在我的例子中 Spree)的资产(例如 javascript)是否总是被编译?我不使用 Spree 的 javascript,因此不希望编译它们。我的 application.js
或任何其他 javascript 文件中不需要它们,但
rake assets:precompile
仍然编译它们。我只是不想让它们躺在我的 public/assets
文件夹中。
所以我想我的问题是,有没有办法禁用从 gem 编译 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
compiles them nonetheless. I just don't want them lying around in my public/assets
folder.
So I guess my question is, is there a way to disable compiling javascripts from a gem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rails 4.X
它在 Rails 4.X 上不起作用,一个可能的(肮脏的)解决方法是:
自 Rails 5.X 起,Rails 5.X
alias_method_chain
的更新已被弃用。这是使用
prepend
的更新版本,并覆盖Sprockets::Environment
模块而不是Sprockets::Paths
。Rails 4.X
It didn't work on Rails 4.X, a possible (dirty) workaround is:
Update for Rails 5.X
alias_method_chain
is deprecated since Rails 5.X. Here is an updated version usingprepend
, and overriding theSprockets::Environment
module instead ofSprockets::Paths
.我想有一种聪明的方法可以使用
sprockets
来实现您的目标。也许是一些require_directory
而不是require_tree
。但最直接的方法是将这些资产从您的资产路径中删除。要实现此目的,请将此添加到
application.rb
文件的最末尾(在初始化程序中不起作用):刚刚尝试了hack:将代码放入
initializer
中,但在application.rb
末尾需要它:我更喜欢以这种方式显示非常具体的代码。
I guess there is a smart way to achieve your goal using
sprockets
. Maybe somerequire_directory
instead ofrequire_tree
.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):Just tried a hack: put the code in an
initializer
but require it at the end of yourapplication.rb
:I prefer very specific code to be visible this way.