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

Bower用來管理項目的依賴,版本等問題node

  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:jquery

        • 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)
相關文章
相關標籤/搜索