使用Bower管理依赖以及版本控制
Bower用来管理项目的依赖,版本等问题
- Bower官方站点: http://bower.io/
- 使用NodeJS命令安装Bower: npm install -g bower(依赖Git)
- 使用bower install命令安装所需要的依赖,安装后的文件位于bower_components目录下
- 常用的安装方式有:
-
-
- 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.2.3#^1.2.3- #>=1.2.3 <2.0
- 可选的配置项
-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
-
- 组件搜索
- http://bower.io/search/
- 'package-name', OR 'keyword', OR 'keyword owner:jquery'
- Bower 配置项
- power.json ( power init 命令生成)
- Interactively create a
bower.jsonwithbower init -
The
bower.jsonspec 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).mainstring or array: The primary acting files necessary to use your package.ignorearray: An array of paths not needed in production that you want Bower to ignore when installing your package.keywordsarray of string: (recommended) helps make your package easier to discoverdependencieshash: Packages your package depends upon in production. Note that you can specify ranges of versions for your dependencies.devDependencieshash: Development dependencies.privateboolean: Set to true if you want to keep the package private and do not want to register the package in the future.
- Interactively create a
- .powerrc (http://bower.io/docs/config/#bowerrc-specification)
- The config is obtained by merging multiple configurations by this order of importance:
- CLI arguments via
--config - Environment variables
- Local
.bowerrclocated in the current working directory - All
.bowerrcfiles upwards the directory tree .bowerrcfile located in user’s home folder (~).bowerrcfile located in the global folder (/)
- CLI arguments via
- 常用的配置
- directory: The path in which installed components should be saved. If not specified this defaults to
bower_components. -
proxy:The proxy to use for http requests.
- https-proxy: The proxy to use for https requests.
-
timeout: The timeout to be used when making requests in milliseconds, defaults to
60000ms.
- directory: The path in which installed components should be saved. If not specified this defaults to
- The config is obtained by merging multiple configurations by this order of importance:
- power.json ( power init 命令生成)
- API(http://bower.io/docs/api/):
- bower home <package> : Opens a package homepage into your favorite browser.
bower init: Interactively create a bower.json filebower list: List local packages and possible updates.- bower prune: Uninstalls local extraneous packages
- bower update: Updates installed packages to their newest version according to bower.json.
- Programmatic API: Bower provides a powerful, programmatic API. All commands can be accessed through the
bower.commandsobject. - Using local cache: Bower supports installing packages from its local cache – without internet connection – if the packages were installed before. (bower install <package> --offline)
浙公网安备 33010602011771号