Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@benschwarz
Last active April 3, 2019 07:55
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benschwarz/5874031 to your computer and use it in GitHub Desktop.
Save benschwarz/5874031 to your computer and use it in GitHub Desktop.
Bower + Rails asset pipeline
{
"directory": "vendor/assets/components"
}
//= require pkgname
npm install -g bower
# From your rails project directory
curl https://raw.github.com/gist/5874031/.bowerrc > ./.bowerrc
bower install <pkgname>
@benschwarz
Copy link
Author

Prior ❤️ to @josh

@DylanFM
Copy link

DylanFM commented Jun 27, 2013

Thanks Ben :)

@dlindahl
Copy link

You can also symlink /components to /vendor/assets/javascripts

You get the small added benefit of leaving the .bowerrc out of the repo so that other devs can personalize (if you are into that sort of thing)

@RobLoach
Copy link

JavaScripts

@sj26
Copy link

sj26 commented Jun 27, 2013

<3

@mipearson
Copy link

If you're on Rails 3.2 (ie sprockets < 2.6), you'll need to do this in your application.js instead:

require package/path/to/js

instead. eg:

//= require underscore/underscore
//= require angular/angular

@joefiorini
Copy link

Nice, thanks @benschwarz! Also, if you want to completely replace the asset pipeline with Bower & Grunt check out Half Pipe.

@benschwarz
Copy link
Author

Its also worth noting that some bower packages haven't defined the main attribute in the package definition file (thats bower.json) — in that case, you'll need to require them by a more complete path.

So instead of:

//= require jquery-placeholder

You'll need to use a more complete path to the library:

//= require jquery-placeholder/jquery.placeholder.js

FYI, I've been filing pull requests (1, 2, 3) for packages as I come across them. Until bower implements package validation, we're boned.

@oivoodoo
Copy link

Is it possible somehow to use images with rails pipeline from the components?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment