Bower用来管理项目的依赖,版本等问题
- Bower官方站点:
- 使用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
-
- 组件搜索
- 'package-name', OR 'keyword', OR 'keyword owner:jquery'
- Bower 配置项
- power.json ( power init 命令生成)
- Interactively create a
bower.json
with -
The defines several options, including:
name
(required): The name of your package; please see section for how to name your package.version
: A semantic version number (see ).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 discoverdependencies
hash: Packages your package depends upon in production. Note that you can specify 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.
- Interactively create a
- .powerrc ()
- 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 (/
)
- 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
60000
ms.
- 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():
- bower home <package> : Opens a package homepage into your favorite browser.
bower init: Interactively create a bower.json file
bower 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.commands
object. - Using local cache: Bower supports installing packages from its local cache – without internet connection – if the packages were installed before. (bower install <package> --offline)