rails-assets
rails-assets copied to clipboard
Handle Assets conflicts for bootstrap wgile using boostrap-xyz packages
The solution suggested in #132 to avoid conflicts with rails-assets and non-rails-assets for bootstrap is to use an initalizer with :
Rails.configuration.assets.paths.reject! do |path|
path.include?('rails-assets-bootstrap')
end
However, this seems to result in rejecting from the asset pipe any rails-assets whose packahe name starts with boostrap-
such as bootstrap-datepicker
or bootstrap-timepicker
since their path looks like [...]/rails-assets-bootstrap-datepicker-[version]/[...]
To avoid this, I ended adding a -3
in the excluded string :
Rails.configuration.assets.paths.reject! do |path|
path.include?('rails-assets-bootstrap-3')
end
This is probably not perfect, but it does the trick.
for anyone googling I've just stuck a Rails 5 compatible answer to this over on #314.
This example lets you set an array of gem names to reject, it includes the gem version in the final check to safely reject specific gems only. You must explicitly add all gems with asset paths you wish to reject to the array:
Rails.application.config.after_initialize do
# add the gem names you wish to reject to the below array
excluded_gem_names = [
'rails-assets-bootstrap',
'rails-assets-jquery',
]
excluded_gem_full_names = Gem::Specification.select { |g| excluded_gem_names.include? g.name }.flat_map { |a| a.full_name }
Rails.application.config.assets.paths.reject! do |path|
excluded_gem_full_names.any? { |gem_name| path.include? gem_name }
end
end
@rjocoleman although this indeed excludes the gem names specified from Rails.application.config.assets.paths
, if a rails-asset specifies them as a dependency inside bower.json, it will still get included (Rails 5.2.0). Super strange.