Using Rails+Bower on Heroku
Updated for Rails 4.0.0+
Set up the bower
gem.
Follow the Bower instructions and list your dependencies in your bower.json
, e.g.
// bower.json
{
// ...
"dependencies": {
"d3": "~3.1.0",
"underscore": "~1.4.4",
}
}
Include them in your JavaScript:
// app/assets/javascripts/application.js
//
// Bower packages
//= require d3/d3
//= require underscore/underscore
//
//= require jquery
//= require jquery_ujs
// ...
Ignore the components in your repo. If you prefer to "vendor" your dependencies, skip this step.
# .gitignore
/bower_components/
Install the components.
npm install -g bower
bower install
At this point, make sure your app runs and the JS libs installed by Bower are loading on the page.
To have Heroku deploys (Cedar stack only) install and compile Bower components on push:
Use a custom Heroku buildpack that includes Node.js and Bower (see heroku/heroku-buildpack-ruby#67). If you vendored your components (skipping the .gitignore
step above), you can skip this step and use the regular Ruby buildpack.
heroku config:set BUILDPACK_URL='git://github.com/qnyp/heroku-buildpack-ruby-bower.git#run-bower'
Try a deploy: it should successfully compile assets.
Additional resources: