Recently i blogged on Modern Web App development, in which i mentioned few tools which will ease the web development. Let’s see one of the tools which is also my fav – Bower, the package manager for web.
As you aware that modern web application development requires one to many libraries or frameworks, and maintaining all of them is really hard, especially while upgrading! What if, if we have a tool to do this job. Cool, right! Let’s dig into that 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 which out chaos!
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.
Bower requires Git. So install Git before you proceed with Bower installation.
So, before installing Bower, install the following dependencies –
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 –
Interactively create bower.json – You can create the bower.json interactively using –
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> [<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 even 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 it gave you an idea to kick start with Bower. I will be back with another tool in my next post.
Happy Web Programming!!!