Showing posts with label Bower. Show all posts
Showing posts with label Bower. Show all posts

Wednesday, 13 July 2016

Difference Between Bower and NPM



  • Npm and Bower are both Project dependency management tools. But the main difference between both is npm is used for installing Node js modules but bower js is used for managing front end components like html,css,js etc.



  • npm is most commonly used for managing Node.js modules, but it works for the front-end too when combined with Browserify etc



  • Bower is front-end Package Manager. The biggest difference is that npm does nested dependency tree that increases its size eventually while Bower requires a flat dependency tree No nested versioning of Packages

NESTED DEPENDENCY TREE
A nested dependency tree means the dependencies or Packages we added in our project can also be dependent on other dependencies and those can further have more dependencies and so on. This is not a problem for a website where you does not care about space and performance of application . It tells you need to care about dependency conflicts as all your dependencies use their own version of Underscore.This increases size and make heavy load for pages. Imagine a site having to download three copies of jQuery as due to different packages require different version of jquery

The reason many projects use both is that they use Bower for front-end packages and npm for developer tools like Yeoman, Grunt, Gulp, JSHint, CoffeeScript, etc.

SEPARATE PACKAGE DEPENDENCY APPROACH
The main difference between npm and Bower is the approach for installing package dependencies. npm installs dependencies for each package separately, and as a result makes a big package dependency tree (node_modules/grunt/node_modules/glob/node_modules/...), where there could be several version of the same package. For client-side JavaScript this is unacceptable: you can't add two different version for jQuery or any other library to a page. With Bower each package is installed once (jQuery will always be in the bower_components/jquery folder, regardless of how many packages depend on it) and in the case of a dependency conflict, Bower simply won't install the package incompatible with one that's already installed.

Tuesday, 12 July 2016

What is Bower And Why To Use Bower


Websites are made up of number of Things That include - Framework , Libraries , HTML , CSS , Javascript , Fonts, Images etc

To Keep Track of All These Packages and Making Sure they are up todate is not an easy thing . Bower act as an rescue for us

BOWER IS A FRONT-END PACKAGE MANAGER

Bower Do the Work of Installing and Updating Project Dependencies . That Includes Libraries that project uses like jquery etc .What it does is to go To All Library Websites Downloading the packages Unpacking them and place them in project folder so that project can use them and all of this is done use some set of commands.

Bower Help Us To Manage Components like HTML, CSS , Javascript ,fonts , images etc . Bower Just tries to maintain Version of the package as per our Dependency and Need For the Project as specified .

Bower Contains a File 'Manifest File' - bower.json This file is used by bower to keep track of managing packages . It work by fetching, saving , installing package from web and update them in bower.json

Getting Started With Bower

Complete List Of Bower Commands
https://bower.io/docs/api/

How To Install Bower

In Order to Install Bower You Need To Install NPM . The best way to install npm is to install node using the node.js installer. npm is installed as part of node.

Download NPM 

If you are using Linux Use Command Below to install NPM
sudo npm install npm -g

After Installing NPM Install Bower By Using Command Below
npm install -g bower

Intalling Packages Using Bower

$ bower install <package>

After Execution of this command bower_components folder will be create and all packages will reside under this folder


Bower Example

> bower install --save jquery # or bower i -S jquery
This command will download the latest version of jQuery into the bower_components/jquery folder.

Sample bower.js File

# installs the project dependencies listed in bower.json
$ bower install
# registered package
$ bower install jquery
# GitHub shorthand
$ bower install desandro/masonry
# Git endpoint
$ bower install git://github.com/user/package.git
# URL
$ bower install http://example.com/script.js