Sunday 12 April 2015

Bower Fundamentals Part 2

Creating bower.json file

bower.json file maintains the record of all the dependencies you have installed in your project.
To create bower.json file, type following command on to your terminal
bower init
It will ask your few simple questions and after that, a bower.json file will be created in your project.

Installing from bower.json file

If you have bower.json file and it has all the dependencies mentioned in it then you can install all those dependencies into your project by executing below command
bower install

Changing default location of Bower installation directory

By default bower installs all the dependencies in bower_components directory. But let say you want to install these dependencies in a folder 'public/lib'.
You can do it by create a file .bowerrc in the root of your folder and inside this file give the following configuration
{
    "directory": "public/lib"
}

Using --save and --save-dev flags

If you want to install a package in your project and you want your bower.json file to get updated with this installation then use --save flag.
Some dependencies are meant for development purpose like testing dependencies and they do not have anything to do with the production code. So it is better not include such dependencies and keep them as dev dependencies. To install a package as dev dependency we should use --save-dev flag. For example,
bower install lodash --save-dev
Now when you want to deploy your code into production then you can ignore these dependencies and install only those packages which are needed in production. this can be done through
bower install --production
It will not install dev-dependencies.

Bower Cache

Bower maintains a cache, if the requested package is in cache then it will not make network connection to fetch it, it would rather install it from the cache,
To list down the packages available in cache, execute the following command
bower cache list
To clean the cache
bower cache clean
To explicitly install from cache only, use -o flag
bower install angular -o

For further more instructions, try out
bower help

No comments:

Post a Comment