Bower integration for your ruby apps.
Add bower
to your application's Gemfile:
gem 'bower'
Rails 4 ships with an updated version of Sprockets that supports bower's bower.json
file. If you are running, Rails 3, then you need to require Sprockets 2.2.2.backport1
:
gem 'sprockets', '2.2.2.backport1'
The gem includes a generator that sets up your project:
rails generate bower:install
This will install a configuration file (.bowerrc
) in your project's root. The configuration file tells bower where to install components and where it expects bower.json
.
{
"directory" : "bower_components"
}
You can change the destination directory if you like, though putting Bower components under app/assets/
can cause problems (see rails/rails#7968). Add your dependencies to bower.json
or use bower install
as you would in any other project.
While offering less capability than when used in Rails' asset pipeline, you can still use the bower
gem in a non-Rails project. Just require the gem and append the corresponding directory to Sprocket's load path:
require 'sprockets'
require 'bower'
environment = Sprockets::Environment.new
environment.append_path Bower.environment.directory
For Rails apps, integrating bower components into lib/assets
and/or vendor/assets
seems like the wrong approach. Since bower can support multiple searchpaths, the need to make a distinction between external dependencies and frameworks does not exist. It can all be managed in once place. This gem takes a more opinionated approach and installs components to bower_components/
in your project's root by default. You can always change it to another location.
If this approach isn't to your liking, you may want to take a look at bower-rails
.
When used with Sprockets, you still need to use a require
directive in order to require a component's files. This seems like something that should just work.
Pull requests welcome: fork, make a topic branch, commit (squash when possible) with tests and I'll happily consider merging your contributions.
Copyright (c) 2015 Steve Agalloco. See LICENSE for details.