Академический Документы
Профессиональный Документы
Культура Документы
How can one ensure the right set of versions / dependencies are installed by
everyone in the team and every where in the application?
Bower Introduction
For server side JavaScript, npm is the standard package manager. However, in
order to use npm in client side a module loader is required.
Bower is the package manager for web that exposes libraries as global resources.
It helps you manage the packages and assets that are used to implement your front
end web development projects.
Bower works by fetching and installing packages from all over, taking care
of hunting, finding, downloading and saving the packages one is looking for.
To install Bower, one must have node.js, npm and Git installed.
As you follow along, it is recommended that you play with bower in Katacoda
playground.
npm --version
mkdir myFirstTutorial
Let us now navigate to the newly created project directory and install all the
needed libraries.
cd myFirstTutorial
Assuming your application might need jQuery, you can try installing the same
using Bower command.
bower install jquery
Since there is no version of the jQuery mentioned, Bower fetches the latest version
of the jQuery from its repository, creates a new folder
called bower_components and places the jQuery files.
You could see jquery.js and jquery.min.js listed under jquery folder.
You could just specify the version while doing the installation.
bower list
This would eliminate the same setup being done individually by everyone in the tea
m.
Well, Bower provides an easy way to save all the bower components added to
a single file called bower.json file. This file can be version-controlled and
shared with everyone in the team
bower init
Now you would see a single file called bower.json getting created.
You might notice bower.json file has captured all the 3 dependencies viz.,
jquery, angular, and backbone added.
Dependencies Installation
bower.json file is all that is needed for anyone to add the needed project
dependencies.
Your team can download this file from the version control and install dependencies
by executing bower install.
rm -rf bower_components
bower install.
You should see the bower_components back in your project directory, installing all the
needed dependencies as per the bower.json file. This is the beauty of bower.
Simply run bower install bootstrap and add appropriate version if needed.
Now, how do you get this new addition propagated to rest of your team?
Refresh your bower.json file and see that bootstrap is getting added
automatically.
You could go ahead and commit this json file to your version repository so that
others can find it.
Dependencies Path
Find the path of your dependencies, using:
<html>
<script src="bower_components/angular/angular.js">
</script>
<body>
</body>
</html
If you consider any version, say, angular 1.6.2, 1 is the major version, 6 is the minor
version and 2 could be a bug fix.
^ in front of the version indicates, the major version should be 1 and minor
version can be anything i.e.., bower can bring any 1.x.x version as
dependency
~ indicates right most digit in the version can be anything. i.e.., bower can
bring any 1.6.x version as dependency
>= indicates bower can bring any version greater than or equal to angular
1.6.2 as dependency
Update Package
Updating a package is pretty simple. You could say bower update. This
updates all the outdated or old packages wherever there is a new version
available.
You could also choose to update a single dependency i.e., bower update
angular.
Uninstall Package
Uninstalling a package is similar to installation. You could just run bower
uninstall <package>.
From our earlier example, try bower uninstall angular. See what happens
to thebower.json file and bower_components.
Just like how installing multiple packages are possible, uninstall will also work
the same way. i.e.., bower uninstall angular backbone bootstrap.
bower cache list - Lists all the packages installed earlier and are cached
You have added a new dependency some time in the middle of the project.
How do you get this new dependency shared across with everyone in the
team - Use --save option. The dependency gets added to the .json file which can be distributed
to others
Your project uses angular 1.2.26. However you would like to override this
version for specific needs with angular 1.3. Which option in the bower.json
file allows you to use to do so? - "angular": "angularjs#^1.2.26"
Bower can be used as a package manager for both server side and client
side applications – False
You are trying to install a particular jQuery version 1.9.15 using bower
install angular. What happens to the installation? ( Hint - jQuery 1.9.15 is
not a valid version ) Errors out saying 'No tag found that was able to satisfy 1.9.15'
How do you get the latest version of the dependencies as per the json file
installed? - Execute "bower update"
When the dependencies are added through bower, how do you refer them
in your HTML / CSS etc. code? Execute 'bower list -path' and pick the path of the
dependencies for inclusion
Is Git essential for installing Bower? - Yes. Since Git is required to access the
packages for inclusion
When does bower.json get created? - bower.json gets created when 'bower init' is run