rails-assets icon indicating copy to clipboard operation
rails-assets copied to clipboard

How to handle assets conflict (bootstrap)

Open shir opened this issue 10 years ago • 34 comments

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?

shir avatar Mar 31 '14 11:03 shir

Did you try @import "bootstrap-sass"; instead @import "bootstrap";?

sheerun avatar Mar 31 '14 12:03 sheerun

@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)

shir avatar Mar 31 '14 12:03 shir

That's because you mix rails-assets and non-rails-assets components.

Use rails-assets-bootstrap-sass and @import "bootstrap-sass";

sheerun avatar Mar 31 '14 12:03 sheerun

@sheerun this library doesn't have mixins and variables. Only compiled css file.

shir avatar Apr 01 '14 11:04 shir

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 and require bootstrap-sass-official
  • rails-assets-twbs--bootstrap-sass and require bootstrap-sass

sheerun avatar Apr 01 '14 11:04 sheerun

@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

shir avatar Apr 02 '14 06:04 shir

This may be a bug. Let me try to make a demo app or fix it.

sheerun avatar Apr 02 '14 10:04 sheerun

@shir this seems to be a known bug https://github.com/rails-assets/rails-assets/issues/136

MichaelSp avatar Apr 25 '14 18:04 MichaelSp

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.

jdurand avatar May 13 '14 17:05 jdurand

@shir I answered your issue in #136

sheerun avatar Jun 03 '14 14:06 sheerun

+1 for having a way to include a rails-asset without its dependencies

poteto avatar Jun 27 '14 01:06 poteto

+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 avatar Jul 09 '14 11:07 pjanik

@pjanik Maybe gem 'rails-assets-jquery', require: false will help.

sheerun avatar Aug 14 '14 16:08 sheerun

@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).

rosskevin avatar Sep 03 '14 21:09 rosskevin

I don't think it's a good idea to use rails-assets in gems.

sheerun avatar Sep 03 '14 22:09 sheerun

@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?

rosskevin avatar Sep 03 '14 23:09 rosskevin

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.

sheerun avatar Sep 03 '14 23:09 sheerun

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.

rosskevin avatar Sep 03 '14 23:09 rosskevin

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.

sheerun avatar Sep 03 '14 23:09 sheerun

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.

vinc avatar Sep 17 '14 22:09 vinc

please use bootstrap-sass gem instead (not rails-assets-bootstrap)

sheerun avatar Sep 17 '14 22:09 sheerun

That's what I'm using, the latter is only required by rails-assets-seiyria-bootstrap-slider which is the problem.

vinc avatar Sep 17 '14 22:09 vinc

then do:

gem 'rails-assets-bootstrap', require: false

sheerun avatar Sep 17 '14 22:09 sheerun

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.

vinc avatar Sep 17 '14 22:09 vinc

I edited my previous comment.

sheerun avatar Sep 17 '14 22:09 sheerun

Oh, that I hadn't tried, but I still get the first Sass::SyntaxError.

vinc avatar Sep 17 '14 22:09 vinc

I can't help then.

You need to make sure all bootstrap gems except bootstrap-sass have require: false

sheerun avatar Sep 17 '14 22:09 sheerun

Thank you for your time! I'll report back if I find something new about this issue.

vinc avatar Sep 17 '14 23:09 vinc

@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.

jb41 avatar Oct 01 '14 13:10 jb41

:+1:

bopm avatar Oct 08 '14 09:10 bopm