Go to: Bower client library management tool

Source: Internet
Author: User

    • Overview
    • Common Operations
    • Library Installation
    • Search and view Databases
    • Library update and uninstall
    • List all databases
    • Configuration File. bowerrc
    • Library Information File Bower. JSON
    • Related Links
Overview

As web functions become more and more complex, loading multiple JavaScript function libraries on the same web page has become a common habit. Developers increasingly need a tool to manage various libraries on the browser side, such as searching, automatic installation/uninstallation, checking for updates, and ensuring dependencies. Bower is a browser-oriented library management tool designed to solve this problem.

Bower is based on node. js. Therefore, you must ensure that node. js has been installed before installation.

sudo npm install bower -global

After running the preceding command, the bower has been installed in your system. Run the HELP command to check whether the bower is successfully installed.

bower help

The following command can be used to update or Uninstall a bower.

sudo npm update -g bowersudo npm uninstall -global bower
Installation of common operation Libraries

The Bower install command is used to install a library. You must specify the library name.

bower install backbone

Bower uses the library name to search for the library URL in the Online Index. In some cases, if a library is very new (or you do not want to use the default URL), you may need to manually specify the URL of the library.

bower install git://github.com/documentcloud/backbone.gitbower install http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.jsbower install ./some/path/relative/to/this/directory/backbone.js

The preceding command indicates that the specified URL can be a GitHub address, an http url, or a local file.

By default, the latest version of the library is installed, but you can also manually specify the version number.

bower install jquery-ui#1.10.1

The above command specifies to install version 1.10.1 of jquery-UI.

If a library depends on another library, the dependent library is installed together by default during installation. For example, if jquery-UI depends on jquery, it will be installed together with jquery during installation.

The installed library is stored in the bower_components subdirectory of the project by default. to specify other locations, you can set the Directory attribute in the. bowerrc file.

Search and view Databases

The Bower SEARCH command is used to search related databases from online indexes using keywords.

bower search jquery

The above command will get the following result.

Search results:    jquery git://github.com/components/jquery.git    jquery-ui git://github.com/components/jqueryui    jquery.cookie git://github.com/carhartl/jquery-cookie.git    jquery-placeholder git://github.com/mathiasbynens/jquery-placeholder.git    jquery-file-upload git://github.com/blueimp/jQuery-File-Upload.git    jasmine-jquery git://github.com/velesin/jasmine-jquery    jquery.ui git://github.com/jquery/jquery-ui.git    ...

The Bower info command is used to view the details of a database.

bower info jquery-ui

The dependencies and available versions of the database are listed ).

Library update and uninstall

Bower update is used to update a library and update it to the latest version.

bower update jquery-ui

If no database name is provided, all databases are updated.

The Bower uninstall command is used to uninstall the specified library.

bower uninstall jquery-ui

Note: by default, it will be detached together with the dependent database. For example, if jquery-UI depends on jquery, it will be detached together with jquery during uninstallation, unless other libraries depend on jquery.

List all databases

The Bower list or Bower LS command is used to list all libraries used by the project.

Bower listBower ls
Configuration File. bowerrc

The. bowerrc file under the project root directory (which can also be placed in the user's main directory) is the configuration file of Bower, which is like the following.

{  "directory" : "components",  "json"      : "bower.json",  "endpoint"  : "https://Bower.herokuapp.com",  "searchpath"  : "",  "shorthand_resolver" : ""}

The attribute meanings are as follows.

    • Directory: the sub-directory name that stores the library file.
    • JSON: The JSON file name of each database.
    • Endpoint: the Online Index URL used to search for various databases.
    • Searchpath: An array to store alternative online index URLs. If a library cannot be found in the endpoint, search for the URL specified by this attribute. It is usually used to store some non-public libraries.
    • Shorthand_resolver: defines the abbreviated form of each database name.
Library Information File Bower. JSON

The Bower. JSON file is stored in the root directory of the Library. It is used to save the library information of the project for use during project installation and to read the online index of the bower.

The following is a typical Bower. JSON file.

{  "name": "app-name",  "version": "0.1.0",   "main": ["path/to/app.html", "path/to/app.css", "path/to/app.js"],  "ignore": [".jshintrc","**/*.txt"],  "dependencies": {    "sass-bootstrap": "~3.0.0",    "modernizr": "~2.6.2",    "jquery": "latests"  },  "devDependencies": {"qunit": ">1.11.0"}}

In the root directory of the project, run the bower init command to automatically generate the bower. JSON file by answering a few questions.

bower init

With the bower. JSON file, you can use the bower install command to install all the libraries at once.

bower install

Based on the bower. JSON file, you can also submit your library to the online index of Bower.

bower register <my-package-name> <git-endpoint>// 比如bower register jquery git://github.com/jquery/jquery

NOTE: If your database has the same name as the existing database, the submission fails.

Go to: Bower client library management tool

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.