Manage Git-driven Packages with Bower

Bower is a handy tool by Twitter that serves as a front-end package manager. It’s based on node.js and compliments other related tool such as Grunt that became popular in the WordPress Core project itself.

Bower uses Git to manage repositories, and given the popularity of GitHub (and other git-driven projects, for that matter) it makes the component management much easier.

You’ve probably used Composer already, which is a dependency manager for PHP. There are various libraries that could be found in both repositories, but Composer is more of a backend-centric manager while Bower is mostly used for frontend libraries. PHP developers could find Bower useless if it’s the only tool that requires NPM (the Node Packaged Modules) while Composer requires only PHP. However, if your stack uses other node.js tools such as Grunt, you could make use of the integration between both tools (and others).

Assuming that you have npm installed already, you could install Bower globally for your system:

npm install -g bower

This would install Bower in your ~/.npm folder with all related dependencies required by the library itself.

For a given project, we could enter the project folder and initialize the configuration file for the project. There is a handy CLI wizard that would lead you through the setup once you type bower init:

bower init

[?] name: bower-demo
[?] version: 0.1
[?] description: Demo Bower project
[?] main file: .
[?] keywords:
[?] authors: mpeshev <>
[?] license: MIT
[?] homepage:
[?] set currently installed components as dependencies? No
[?] add commonly ignored files to ignore list? Yes
[?] would you like to mark this package as private which prevents it from being accidentally published to the registry? Yes

As a result, this would generate our bower.json configuration file:

name: 'bower-demo',
version: '0.1',
authors: [
'mpeshev <>'
description: 'Demo Bower project',
main: '.',
license: 'MIT',
homepage: '',
private: true,
ignore: [

To find a given library in the repository, we could run a bower search:

bower search ember.js
Search results:

ember.js git://

If you just type ember it would find various Ember-related repositories as well.

We could add the project to our dependencies list and specify a version. To keep that up-to-date, we could make use of the latest version in the repository as well. In the ember context, we could strip down the ignore list from our config (if we don’t have tests or other node modules or anything) and wrap the config file by adding the new dependencies:

"private": true,
"dependencies": {
"ember.js": ">=1.2.0"

Running bower install in our project folder would install the latest available ember.js version (currently 1.3.0-beta3):

[nofearinc@nofearinc bower-demo]$ bower install
bower ember.js#>=1.2.0 cached git://
bower ember.js#>=1.2.0 validate 1.2.0 against git://>=1.2.0
bower ember.js#>=1.2.0 new version for git://>=1.2.0
bower ember.js#>=1.2.0 resolve git://>=1.2.0
bower ember.js#>=1.2.0 download
bower ember.js#>=1.2.0 extract archive.tar.gz
bower ember.js#>=1.2.0 resolved git://
bower ember.js#>=1.2.0 install ember.js#1.3.0-beta.3

ember.js#1.3.0-beta.3 bower_components/ember.js

By default Bower installs libraries in the bower_components folder. If you want to change the folder, you could create a .bowerrc file in your project (next to bower.json) with the following snippet:

"directory": "ext"

This would install Bower libraries in the ext directory, which could be lib, assets or anything you would prefer.

Additionally, you could simple install remote packages (and also specify a given version):

bower install <somepackage>

bower install <somepackage>#<someversion>

For Grunt integration, you could integrate Bower into Grunt with the grunt-bower-task. This would allow you to bundle the libraries within the build process, manage versions and everything.

Your thoughts?