Skip to content

Instantly share code, notes, and snippets.

@omarramos
Forked from afeld/gist:5704079
Created October 22, 2014 18:02
Show Gist options
  • Save omarramos/4a9b6a66092d09e9256f to your computer and use it in GitHub Desktop.
Save omarramos/4a9b6a66092d09e9256f to your computer and use it in GitHub Desktop.

TODO: make gem for this

This was tested using Rails 3.2 and Rails 4.0 on Ruby 2.0.0.

Bower

  1. Set the install directory for Bower components:

    // .bowerrc
    {
      "directory": "vendor/assets/components"
    }
  2. 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",
      }
    }
  3. 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
    // ...
  4. Ignore the components in your repo.

    # .gitignore
    /vendor/assets/components
    
  5. Install the componenets.

    npm install -g bower
    bower install

It's just that easy!!! ::facepalm::

Additional resources:

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