Bower – A Package Manager

Recently I blogged on Modern Web App development, in which I mentioned few tools which will ease the web development. Today, let’s explore one more tool – Bower, the package manager for Web.

As you may aware that modern web application development requires one to many libraries or frameworks, and maintaining all of them is really hard, especially while upgrading! Isn’t cool, if we have a tool to do this job! Let’s take a look at the tool –

Bower is a great tool which helps us to maintain the project or app dependencies in more elegant way!

How it works?

Bower uses bower.json manifest (similar to package.json) file to hold all the package information. You can easily edit this manifest file. Works like a configuration file for your packages. Using Bower commands you can install all those packages at once.

Installing Bower

You can install Bower using npm (Node Package Manager). If you don’t know what is npm, you can learn here – https://docs.npmjs.com/. So, if you don’t have npm installed on your machine. Install the Node.js, which will install Node as well as npm.

NOTE: Bower requires Git. So install Git before you proceed with Bower installation.

  1. Node.js 
  2. Git

You may have to open Terminal(on MAC OS) or PowerShell / Command Prompt (on Windows). [I recommend PowerShell on Windows than Command Prompt.]

Type the following command –

npm install -g bower

NOTE: You may get permission issues, so you run the above command using sudo in MAC. On Windows, run the PowerShell or Command Prompt with Administrator Privileges.

Once you are done installing Bower globally, now we are ready to play with it!

Now, we need to create bower.json manifest file. You can create this manifest file manually or through bower.

Manually creating bower.json – Create a file and rename it to bower.json. That’s it! Data included in this manifest file should adhere to the spec –  https://github.com/bower/bower.json-spec

A Sample bower.json for Angular app

{
 "name": "demo-app",
 "version": "1.0.0",
 "dependencies": {
 "angular": "^1.3.0",
  "bootstrap": "^3.2.0",
 "angular-animate": "^1.3.0",
 "angular-cookies": "^1.3.0",
 "angular-resource": "^1.3.0",
 "angular-route": "^1.3.0",
 "angular-sanitize": "^1.3.0",
 "angular-touch": "^1.3.0"
 },
 "devDependencies": {
 "angular-mocks": "~1.3.0",
 "angular-scenario": "~1.3.0"
 },
 
}

Interactively create bower.json – You can create the bower.json interactively using  –

bower init

Answer the questions popped by Bower and it will create the file for you.

How to add new packages?

Try the following command –

//install the package and add it to bower.json dependencies
bower install <package-name> --save
//Ex: bower install jquery --save

You can search for available packages  – http://bower.io/search/

Update the bower package  –

bower update <package-name> <package-name> [options]

//-F: Force latest version on conflict

//Ex: bower update jquery -F

Uninstall the bower package  –

bower uninstall <package-name> [options]

//-S: Remove uninstalled packages from the project’s bower.json dependencies

//Ex: bower uninstall jquery -S

More Bower API’s – http://bower.io/docs/api/

Can I register my own package or library?

Yep, you can do that using bower register – 

bower register <your-package-name> <git-endpoint>

//Ex: bower register mylibrary git://github.com/user/example.git

You can also unregister – http://bower.io/docs/creating-packages/#unregister

Bower comes with lot of tools, which allows you to integrate the Bower with other IDE’s and tools. More info – http://bower.io/docs/tools/

Hope you have got quick overview of Bower package manager and usage of the tool.

Happy Web Programming!

One thought on “Bower – A Package Manager

  1. Your wower tool helps me to development a modern web app development on WordPress. We can easily edit manifest files . This tool helps to maintain the project and app dependencies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s