Reprint Link: http://m.blog.csdn.net/csdn_yudong/article/details/74853527
Bower is a front-end package management tool that is handy for managing dependent packages that need to be used in your project. Install Bower Global installation Bower
NPM Install-g Bower
1 View version Information
Bower-v
1
using Bower
Once the installation is complete, you can use the Bower command directly at the command line.
We create a new folder and execute it under the folder path:
Bower Install jquery
1
Bower creates the Bower_components folder in the directory and places the downloaded package in the folder. At this point the directory structure is as follows:
.
└──bower_components
└──jquery
├──mit-license.txt
├──bower.json
├──dist
│ ├──jquery.js
│ ├──jquery.min.js
│ └──jquery.min.map
└──src
...
1 2 3 4 5 6 7 8 9 10 11
From the Bower jquery#~2.1.4 can be found that Bower is through the # to determine the need to download the version, we do not specify the version, Bower automatically help us download the latest. Therefore, if you need to download a specific version of the package, you can use the # Sign in the installation command to declare it.
Bower Install jquery#1.9.1
1
Bower Install command and more options are available. This is not for the moment. View the current Bower downloaded packages
Bower List command to view currently downloaded packages
The Bower list–paths command can view the corresponding paths in the project for all packages that are currently downloaded.
The most useful moment of this command is when you need to declare/configure the front-end dependency package address in other tools.
Bower list--paths
jquery: ' Bower_components/jquery/jquery.js '
1 2
using Bower.json files to manage dependency packs
As with Nodejs Package.json files, you can manage the packages that the project needs to download by Bower.json files. So that the other members of the project team do not need to go bower install all kinds of bags.
The Bower.json file generation method is also very similar to the Package.json. Can be generated by the Bower init command, or manually directly under the project root directory.
Using the Bower init command, Bower will ask some questions and answer them directly.
When all problems are completed, the Bower.json file is generated in the project root directory. If you create it manually, follow the corresponding format. The folder structure is now as follows:
.
├──bower.json
└──bower_components
...
1 2 3 4
When a Bower.json file is already in the project folder, the Bower Install command is automatically downloaded, and all dependent packages are download. download and save the dependency package to Bower.json
Use the install Command's-s option (note S must be uppercase) to automatically add the downloaded package information to the Bower.json file while downloading.
Bower Install-s Backbone
1
After the download is complete Bower.json files are as follows:
...
" Dependencies ": {" jquery ":
" 1.9.0 ",
" backbone ":" ~1.2.1 "
}
...
1 2 3 4 5 6
Bower Customization
What if you want to download the dependency pack to your desired directory? Quite simply, use the. bowerrc file.
Create a. bowerrc file in the project root, written in JSON format.
{
"directory": "App/vender/"
}
1 2 3
After you save it, perform the Bower install command to see the effect.
.
├──app
│ └──vendor
│ ├──backbone
│ │ ... │ ├──jquery
│ │ ... │
└──bower.json
1 2 3 4 5 6 7 8 9
Note: the. bowerrc file needs to be used in conjunction with Bower.json. The package was automatically downloaded after declaring the download directory in. BOWERRC because it was declared in Bower.json's dependencies.