Mar*_*sen 6 ruby-on-rails sprockets asset-pipeline
我不太确定实际的行为是什么,所以我的第一个问题是:
来自gem(在我的Spree中)的资产(例如javascripts)是否总是被编译?我不使用Spree的javascripts,因此不希望它们被编译.我不需要在我application.js或任何其他javascript文件中,但是
rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
虽然编译它们.我只是不希望他们躺在我的public/assets文件夹中.
所以我想我的问题是,有没有办法禁止从gem编译javascripts?
我想有一种聪明的方法可以使用 来实现您的目标sprockets。也许一些require_directory而不是require_tree.
但最直接的方法是将这些资产从您的资产路径中删除。要实现此目的,请在文件的最后application.rb添加以下内容(在初始化程序中不起作用):
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
Run Code Online (Sandbox Code Playgroud)
刚刚尝试了一个技巧:将代码放入initializer但需要它在你的末尾application.rb:
require "config/initializers/your_file'
Run Code Online (Sandbox Code Playgroud)
我更喜欢以这种方式显示非常具体的代码。