At the start of every JavaScript-based applications, especially for AJAX and other web-centric technologies.
To connect all of my libraries quickly and to get the latest library versions you should use the package managers. In this article, I will talk about my favorite Bower by Twitter and the most recent library versions can be maintained by Bower.
Bower depends on Node and npm. Also, you need to install GIT on your system. To begin the installation, you should open the GIT command line and execute the command:
npm install -g bower
Now you can work with your manager, switching in command line to the projects folder. For example we can connect Jquery:
bower install jquery
bower install jquery
After this the folder "components/jquery", you will find the latest files for this library, and they will appear in the folder of your project . If you need a particular version of the library, you should just specify the version like this:
bower install jquery#1.9
Of course, you may change the folder for library settings. For this, you have to create the configuration file «.bowerrc» and post it in the project folder. In the file you should write:
{
"directory" : "app/js"
}
If you use the same libraries in different projects you should create one more configuration file, where you can find the description of what libraries and their versions you want install. It is more convenient than to install every library by separate commands. For this, you should create the file «bower.json» (or bower init) in the root of project. For example you should fill it like this:
{
"name": "project1",
"version": "1.0.0",
"dependencies": {
"jquery": "1.9",
"backbone-amd": "latest",
"underscore-amd": "latest",
"fancybox": "latest"
}
}
Now you should run the command Bower install in the command line and all libraries from list above will be installed.
To renew the package, you should use the command - update.
Also, you can add your packages (libraries) in Bower repository:
bower register mypackade git://github.com/my/mypackade
After this, you can install your library in the same way as the other libraries:
bower install mypackade
So, this is a simple and quick guide to installing the JS libraries you would like with the help of Bower. You can see the biggest list of components here.
See also: PhoneGap - Quick Cross-platform Program Development for Mobile Devices