Rails 3.1 Asset Pipeline: Ignore Gem Assets

I'm not quite sure what the real behavior is, so my first question is:
Are assets (like javascripts) always made from gem (in my case, Spree)? I do not use Spree java scripts and therefore do not want them to be compiled. I do not require them in my application.js or any other javascript file, but

 rake assets:precompile 

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

So, I think my question is, is there a way to disable compilation of gem javascripts?

+6
source share
2 answers

I think there is a reasonable way to achieve your goal using sprockets . Perhaps some require_directory instead of require_tree .

But the most immediate is to remove these points from your resource paths. To achieve this, add this to the very end of your application.rb file (does not work in the 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 

Just tried to hack: put the code in the initializer , but require it at the end of your application.rb :

 require "config/initializers/your_file' 

I prefer very specific code to be visible this way.

+2
source

This does not work on Rails 4.X, possibly a (dirty) workaround:

 require 'sprockets/railtie' Bundler.require(:default, Rails.env) module Sprockets module Paths SKIP_GEMS = ["rails-assets-jquery", "rails-assets-bootstrap"] def append_path_with_rails_assets(path) append_path_without_rails_assets(path) unless SKIP_GEMS.any? { |gem| path.to_s.start_with?(Gem.loaded_specs[gem].full_gem_path) } end alias_method_chain :append_path, :rails_assets end end 
+3
source

Source: https://habr.com/ru/post/895687/


All Articles