AngularJS - Intro to bower

Bower is a package manager for the web. To install angular,

bower install angular

Angular is grabbed from github. We get a bower_components directory with angular inside of it. We get 1.0.8 by default, and we can specify the release:

bower install angular#1.2.0-rc.1

We can also install other libraries, like jQuery, Boostrap, and Underscore, with the same command:

bower install jquery
bower install boostrap
bower install underscore

These will also exist inside the bower_components directory.

To create a bower json file, run

bower init

And accept all the defaults. This gives you bower.json:

{
  "name": "BowerDemo",
  "version": "0.0.0",
  "authors": [
    "Matt Frisbie <me@email.com>"
  ],
  "license": "MIT",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "angular": "1.2.0-rc.1",
    "bootstrap": "~3.0.0",
    "jquery": "~2.0.3",
    "underscore": "~1.5.2"
  }
}

It contains a list of all the information entered at the prompts, and the dependencies. These dependencies mean that it is possible to run

bower install

And all the listed dependencies will be fetched.

Registering a project with bower can be accomplished by committing the project to github with a bower.json file:

bower register projectname

Then 'bower install projectname' will fetch the project. It is also possible to search for registered projects with

bower search angular

This will return a list of all the bower projects with the word ‘angular’ in it.