A package manager for the web.
Bower 是 twitter 推出的一款包管理工具。
Web sites are made of lots of things — frameworks, libraries, assets, utilities, and rainbows. Bower manages all these things for you.
Bower 需要 Node and npm
和 Git
.
把 Bower 安装到全局
npm install -g bower
检测 Bower 版本
bower -v
或
bower --version
升级 Bower
sudo npm update -g bower
可以查看 Bower 的使用帮助
bower
或
bower help
信息如下
WeiHeLi:bower weiheli$ bower
Usage:
bower [] []
Commands:
cache Manage bower cache
help Display help information about Bower
home Opens a package homepage into your favorite browser
info Info of a particular package
init Interactively create a bower.json file
install Install a package locally
link Symlink a package folder
list List local packages - and possible updates
login Authenticate with GitHub and store credentials
lookup Look up a package URL by name
prune Removes local extraneous packages
register Register a package
search Search for a package by name
update Update a local package
uninstall Remove a local package
unregister Remove a package from the registry
version Bump a package version
Options:
-f, --force Makes various commands more forceful
-j, --json Output consumable JSON
-l, --log-level What level of logs to report
-o, --offline Do not hit the network
-q, --quiet Only output important information
-s, --silent Do not output anything, besides errors
-V, --verbose Makes output more verbose
--allow-root Allows running commands as root
--version Output Bower version
--no-color Disable colors
See 'bower help ' for more information on a specific command.
# 模块的名称
bower install jquery
# github用户名/项目名
bower install jquery/jquery
# git代码仓库地址
bower install git://github.com/user/package.git
# 模块网址
bower install http://example.com/script.js
默认会在当前目录生成bower_components
文件夹,并安装到这个文件夹下。如果想要改变默认安装路径,可以在当前目录下新建.bowerrc
文件,在其中指定安装路径
{
"directory": "public"
}
使用bower install
默认安装最新版本。
可以使用bower info
查看包的信息(包括版本信息),使用以下命令安装特定版本
bower install #指定版本号
还有~
、^
,参考语义化版本格式
bower.json 可以让包的管理更加方便。使用bower init
来生成 bower.json文件
bower init
生成最简的bower.json
{
"name": "bower",
"version": "0.0.0",
"authors": [
"weiheli <[email protected]>"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"public",
"test",
"tests"
]
}
Using bower install
will add
to your project’s bower.json dependencies
array.
# install package and add it to bower.json dependencies
bower install --save
Similarly, using bower install
will add
to your project’s bower.json devDependencies
array.
# install package and add it to bower.json devDependencies
bower install --save-dev
有了bower.json
后,可以使用bower install
安装dependencies
中的所有包,非常方便,这就是bower.json
的价值所在。
其他命令没有难度或不常用,可以使用bower
查看帮助。
// 指定文件夹
bower install jquery1=jquery#1.11.3
其中的jquery1
是目录
http://bower.io/