Description
I want to exclude all assets I am not using from precompiling.
I understand that config.assets.excluded_paths
exists and that it requires a full path.
In my case Rails.application.config.assets.paths
returns
["/usr/src/app/app/assets/builds",
"/usr/src/app/app/assets/images",
"/usr/local/bundle/gems/view_component-2.53.0/app/assets/vendor",
"/usr/local/bundle/gems/unobtrusive_flash-3.3.1/lib/assets/javascripts",
"/usr/local/bundle/gems/unobtrusive_flash-3.3.1/lib/assets/stylesheets",
"/usr/local/bundle/gems/turbo-rails-1.0.1/app/assets/javascripts",
"/usr/local/bundle/gems/nested_form-0.3.2/vendor/assets/javascripts",
"/usr/local/bundle/gems/heroicon-0.4.0/app/assets/images",
"/usr/local/bundle/gems/actioncable-7.0.2.3/app/assets/javascripts",
"/usr/local/bundle/gems/actionview-7.0.2.3/lib/assets/compiled"]
I would like to exclude most of them, e.g. "/usr/local/bundle/gems/nested_form-0.3.2/vendor/assets/javascripts"
or "/usr/local/bundle/gems/actionview-7.0.2.3/lib/assets/compiled"
.
I have two reasons for this: It takes comparatively long (e.g. assets from heroicon
), I don't like to waste space (I know, it is not too much) and I like to have a clean directory with only the files I really use.
This is the only way I found to do so:
Rails.application.config.assets.excluded_paths << File.join(Heroicon.root, 'app/assets/images')
# rubocop:disable Style/StringConcatenation
Rails.application.config.assets.excluded_paths << (Pathname.new(Gem.find_files_from_load_path('nested_form').first) + '../../vendor/assets/javascripts')
Rails.application.config.assets.excluded_paths << (Pathname.new(Gem.find_files_from_load_path('turbo-rails').first) + '../../app/assets/javascripts')
Rails.application.config.assets.excluded_paths << (Pathname.new(Gem.find_files_from_load_path('unobtrusive_flash').first) + '../../lib/assets/stylesheets')
Rails.application.config.assets.excluded_paths << (Pathname.new(Gem.find_files_from_load_path('unobtrusive_flash').first) + '../../lib/assets/javascripts')
Rails.application.config.assets.excluded_paths << (Pathname.new(Gem.find_files_from_load_path('view_component').first) + '../../app/assets/vendor')
# rubocop:enable Style/StringConcatenation
Note: I am unable to use this methodology to exclude actionview
or actioncable
.
Pathname.new(Gem.find_files_from_load_path('whaever').first)
does not look like a good solution
What is the recommended way?
How can this be simplified?