Skip to content

Instantly share code, notes, and snippets.

@jhliberty
Forked from afeld/gist:5704079
Last active August 29, 2015 14:13
Show Gist options
  • Save jhliberty/9bc113b099b7b7f21aab to your computer and use it in GitHub Desktop.
Save jhliberty/9bc113b099b7b7f21aab to your computer and use it in GitHub Desktop.

Updated for Rails 4.0.0+

Bower

  1. Set up the bower gem.

  2. 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",
      }
    }
  3. Include them in your JavaScript:

    // 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. If you prefer to "vendor" your dependencies, skip this step.

    # .gitignore
    /bower_components/
    
  5. 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.

Heroku

To have Heroku deploys (Cedar stack only) install and compile Bower components on push:

  1. Add the rails_12factor gem.

  2. 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:

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