TODO: make gem for this
This was tested using Rails 3.2 and Rails 4.0 on Ruby 2.0.0.
-
Set the install directory for Bower components:
// .bowerrc { "directory": "vendor/assets/components" }
-
Follow the Bower instructions and create a
bower.json
file in your directory with your dependencies, e.g.// bower.json { // ... "dependencies": { "d3": "~3.1.0", "underscore": "~1.4.4", } }
-
Include them in your JavaScript:
# config/application.rb # include Bower components in compiled assets config.assets.paths << Rails.root.join('vendor', 'assets', 'components')
// /Users/aidan/dev/code_cruise/app/assets/javascripts/application.js // // Bower packages //= require d3/d3 //= require underscore/underscore // //= require jquery //= require jquery_ujs // ...
-
Ignore the components in your repo.
# .gitignore /vendor/assets/components
-
Install the componenets.
npm install -g bower bower install
It's just that easy!!! ::facepalm::
Additional resources: