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:
@afeld Hi, I built a sample application over the last days based on your gist and some other postings on the net. Let me ask a question:
Why to you specify "app/assets/components" in .bowerrc? I did so too and it added basically all packages to Git. So I could deploy it actually without the specific heroku build pack.
I later on changed the directory to "vendor/assets/components", removed everything from "app/assets/components" and the deployment on Heroku failed. After configuring the custom build pack installation went very smooth. That's how it should be, shouldn't it?