rails-assets
rails-assets copied to clipboard
How to handle assets conflict (bootstrap)
I use bootstrap-sass
gem because I like to use variable and mixins form it:
gem 'bootstrap-sass'
I've installed bootstrap-multiselect
library form rails-assets:
gem 'rails-assets-bootstrap-multiselect'`
But bootstrap-multiselect depends on rails-assets-bootstrap
and it has been installed by dependency. Now, when I include bootstrap in my sass file
@import "bootstrap";
version from rails-assets-bootstrap
gem is included which is not sass version and doesn't have any variables and mixins.
How can I handle this conflict and load bootstrap version from bootstrap-sass
gem?
Did you try @import "bootstrap-sass";
instead @import "bootstrap";
?
@sheerun I don't think it will work because both libraries have only file bootrsrap.scss
(in rails-assets version actually has css version but with scss
extension)
That's because you mix rails-assets and non-rails-assets components.
Use rails-assets-bootstrap-sass
and @import "bootstrap-sass";
@sheerun this library doesn't have mixins and variables. Only compiled css file.
Oh. It turns out bower's bootstrap-sass
points to jlong/sass-twitter-bootstrap
, not an official repository. You can click on version number on https://rails-assets.org/components to see available files.
You'd need to use one of the following:
-
rails-assets-bootstrap-sass-official
andrequire bootstrap-sass-official
-
rails-assets-twbs--bootstrap-sass
andrequire bootstrap-sass
@sheerun May be I don't understand something but looks like both of this libraries are not working (may be it's only on rails 4.1?). When I try to use any of this libraries, then I got error that file bootstrap/affix.js
can't be found. I think it's because in bootstrap.js
files are required as bootstrap/affix.js
, but not like bootstrap-sass-official/bootstrap/affix.js
This may be a bug. Let me try to make a demo app or fix it.
@shir this seems to be a known bug https://github.com/rails-assets/rails-assets/issues/136
It would be nice to have a way to include a Rails Asset without its dependencies.
For instance, I'm using ember-rails
(from rubygems) which includes the supported versions of ember.js
and friends. Now I want to use rails-assets-ember-hammer
without rails-assets-ember
, rails-assets-handlebars
, rails-assets-jquery
and manually add the required rails-assets-hammerjs
.
This would solve the OPs issue.
I'm, wondering if this is more of a bundler issue though... or if this is an issue at all.
The real issue here is that bundling gems from 2 different source trees can and will create ambiguity.
@shir I answered your issue in #136
+1 for having a way to include a rails-asset
without its dependencies
+1
In my case I have bower package that depends on jQuery. You can imagine that at the same time many other gems also depend on "traditional" jquery-rails gem. Both rail-assets jQuery and jquery-rails library can be included using the same //= require jquery
. So which one would be included finally?
I think it may be popular scenario. Not sure if package without dependencies is the best solution. Other could to require rails-assets explicitly like //=require rails-assets-jquery
so there is no conflict.
@pjanik Maybe gem 'rails-assets-jquery', require: false
will help.
@sheerun I have the same problem as @pjanik, though I'm trying to bring in add_dependency 'rails-assets-jquery.easing'
through a gemspec file. :require
false, while I've never used it so don't claim familiarity, doesn't work in a gemspec. I'm not sure which solution is better, but I find that we are gravitating towards bower packages much more than rails gems on the front end (though not totally away from them).
I don't think it's a good idea to use rails-assets in gems.
@sheerun I'm curious, if it isn't a good idea to use in gems, then why would it be a good idea to use in a rails app? What is the basis for your comment?
By using Rails Assets in gem you are forcing users of this gem to use Rails Assets, what is not desired by some companies (you need to trust both Ruby Gems and us). Coupling gem with 2 providers isn't fine.
Using Rails Assets in own application is fine because you make a deliberate choice to.
Thank you. This happens to be private so there are a number of assumptions in use of it and it isn't an issue.
Even if it were public, I'd argue that it is the choice of the gem author, and if gem users are hung up on it, they can choose something else.
I don't see anything wrong with using RA in private gem.
You can always do:
gem 'rails-assets-something', require: false
even if the rails-assets-something
is dependency of your private gem.
Using bower components directly is fine too. Just little harder to setup and deploy properly.
I'm using the gem bootstrap-sass
and I want to use rails-assets-seiyria-bootstrap-slider
but it depends on rails-assets-bootstrap
resulting on:
Sass::SyntaxError at /
File to import not found or unreadable: bootstrap/less/bootstrap.
I tried various things with rails-assets-bootstrap
, rails-assets-bootstrap-sass
and rails-assets-bootstrap-sass-official
without much luck.
please use bootstrap-sass
gem instead (not rails-assets-bootstrap
)
That's what I'm using, the latter is only required by rails-assets-seiyria-bootstrap-slider
which is the problem.
then do:
gem 'rails-assets-bootstrap', require: false
But then I end up with:
Sprockets::FileNotFound at /
couldn't find file 'seiyria-bootstrap-slider'
I switched to using bower-rails
instead on my project (https://github.com/vinc/cities.vinc.cc/commit/9ee01689b298a8c60d85bfafda1116486c7d1071) but I would prefer to avoid it.
I edited my previous comment.
Oh, that I hadn't tried, but I still get the first Sass::SyntaxError
.
I can't help then.
You need to make sure all bootstrap gems except bootstrap-sass
have require: false
Thank you for your time! I'll report back if I find something new about this issue.
@vinc you have to add initializer to /app/initializers with:
Rails.configuration.assets.paths = Rails.configuration.assets.paths.reject do |path|
path.to_s.include?('rails-assets-bootstrap')
end
and gem 'rails-assets-bootstrap', require: false
to you Gemfile.
:+1: