Friday 10 April 2015

Bower Fundamentals Part 1

What is Bower?

Bower is a tool which fetches the client side libraries for your web application. Bower takes care of finding and downloading the library or package for you and then add it into your project. It manages all these dependencies in a file called bower.json.

Installing Bower

To install Bower you need to have node.js installed in your system. Once you find that node.js is installed then you can run the below command on terminal
npm install -g bower 
-g flag is to make it global

** Do not run npm with sudo because there might be some dependencies which needs permission to write but are not able to do so, so if you are not able to run npm without sudo then run the following before installing bower
sudo chown username /usr/local
npm cache clean
here username is the name of the user

Installing packages using Bower

Suppose you want to install angularJS in your project then you can install it by executing following command. First create a bower.json file by init command
bower init
It will ask you few basic questions and after that it will create a bower.json file. Now you can install angularJS via below command
bower install angular --save
If you are using --save flag then it will save it into your project and update the bower.json file. If you are running it without --save flag then it will not modify the bower.json file. Now if you run
bower prune
then it will remove all the dependencies which are not there in bower.json file

Installing Specific version of package

to install a specific version of a particular package you can use a # symbol and specify the version afterwards, as shown below
bower install angular#1.3

Uninstalling Packages

Packages can be uninstalled by using this simple command
bower uninstall angular
and done, it will remove the entry from bower.json file also.

Getting info about a package and its version history

To install a particular version of a package you need to know the version history about that package, and you can do it by executing this command to get the history of that package
bower info angular

Listing installed packages

To list down all the packages installed in your web app, you can run the below command
bower list

Searching a package with Bower

To search a specific package with the name, but you are not sure about the complete name of that package. Then you can run the following command to get the list of all the packages containing that name along with their github URLs.
bower search angular
This will return a list of all the packages containing the word angular along with their github URLs
...to be continued

No comments:

Post a Comment