使用Bower管理依赖以及版本控制

Bower用来管理项目的依赖,版本等问题

  1. Bower官方站点: http://bower.io/
  2. 使用NodeJS命令安装Bower: npm install -g bower(依赖Git)
  3. 使用bower install命令安装所需要的依赖,安装后的文件位于bower_components目录下
    1. 常用的安装方式有:
      • bower install jquery (在bower组件库注册)
      • bower install jquery/jquery (GitHub上的短语名)
      • bower install http://example.com/script.js (通过URL安装)
      • bower install git://github.com/user/package.git(Endpoint方式)
      • bower install my/local/folder(本地文件)
      • 更多方式查看:http://bower.io/docs/api/#install 
    1. 安装时可指定版本号:
      • #~1.2.3
      • #^1.2.3
      • #>=1.2.3 <2.0
    2. 可选的配置项
      • -F--force-latest: Force latest version on conflict
      • -p--production: Do not install project devDependencies
      • -S--save: Save installed packages into the project’s bower.json dependencies
      • -D--save-dev: Save installed packages into the project’s bower.json devDependencies
  1. 组件搜索
    1. http://bower.io/search/
    2. 'package-name', OR 'keyword', OR 'keyword owner:jquery'
  2. Bower 配置项
    1. power.json ( power init 命令生成)
      1. Interactively create a bower.json with bower init
      2. The bower.json spec defines several options, including:

        • name (required): The name of your package; please see Register section for how to name your package.
        • version: A semantic version number (see semver).
        • main string or array: The primary acting files necessary to use your package.
        • ignore array: An array of paths not needed in production that you want Bower to ignore when installing your package.
        • keywords array of string: (recommended) helps make your package easier to discover
        • dependencies hash: Packages your package depends upon in production. Note that you can specify ranges of versions for your dependencies.
        • devDependencies hash: Development dependencies.
        • private boolean: Set to true if you want to keep the package private and do not want to register the package in the future.
    2. .powerrc (http://bower.io/docs/config/#bowerrc-specification)
      1. The config is obtained by merging multiple configurations by this order of importance:
        • CLI arguments via --config
        • Environment variables
        • Local .bowerrc located in the current working directory
        • All .bowerrc files upwards the directory tree
        • .bowerrc file located in user’s home folder (~)
        • .bowerrc file located in the global folder (/)
      2. 常用的配置
        1. directory: The path in which installed components should be saved. If not specified this defaults tobower_components.
        2. proxy:The proxy to use for http requests.

        3. https-proxy: The proxy to use for https requests.
        4. timeout: The timeout to be used when making requests in milliseconds, defaults to 60000 ms.

  3. API(http://bower.io/docs/api/):
    1. bower home <package> :  Opens a package homepage into your favorite browser.
    2. bower init: Interactively create a bower.json file
    3. bower list: List local packages and possible updates.
    4. bower prune: Uninstalls local extraneous packages
    5. bower update: Updates installed packages to their newest version according to bower.json.
    6. Programmatic API: Bower provides a powerful, programmatic API. All commands can be accessed through thebower.commands object.
    7. Using local cache: Bower supports installing packages from its local cache – without internet connection – if the packages were installed before. (bower install <package> --offline)
posted @ 2014-12-25 18:34  Derek_Hu  阅读(828)  评论(0编辑  收藏  举报