为了账号安全,请及时绑定邮箱和手机立即绑定

前端包管理工具 Bower

标签:
JavaScript

Bower 是由 Twitter 推出的前端包管理工具,它类似于 Java 中的 Maven 对 jar 包的管理一样,Bower 是来管理 js、css 等前端包之间的依赖关系。

安装

因为是基于 Node,所以需要先安装 Node 以及 Npm。然后全局安装 Bower:

$ npm install bower -g

使用

初始化

$ bower init
? name (bower) bower-demo
? description a demo of bower
? main file
? what types of modules does this package expose?
? keywords bower
? authors (Jay <jay.li@baichanghui.com>)
? license (MIT)
? homepage index.html
? set currently installed components as dependencies? (Y/n)
...

这样它会自动生成一个 bower.json 的文件,里面描述了相关的项目信息和依赖信息:

{  "name": "bower-demo",  "authors": [    "Jay <jay.li@baichanghui.com>"
  ],  "description": "a demo of bower",  "main": "",  "moduleType": [],  "keywords": [    "bower"
  ],  "license": "MIT",  "homepage": "index.html",  "ignore": [    "**/.*",    "node_modules",    "bower_components",    "test",    "tests"
  ]
}

安装依赖

$ bower install jquery
bower not-cached    https://github.com/jquery/jquery-dist.git#*bower resolve       https://github.com/jquery/jquery-dist.git#*bower checkout      jquery#3.0.0bower progress      jquery#* Receiving objects:  19% (27/140)bower progress      jquery#* Receiving objects:  74% (104/140), 332.00 KiB | 12.00 KiB/sbower resolved      https://github.com/jquery/jquery-dist.git#3.0.0bower install       jquery#3.0.0jquery#3.0.0 bower_components/jquery

删除依赖

$ bower uninstall jquery

安装不同的版本

$ bower install jquery#1.7.2

更新依赖

$ bower update jquery

查看依赖

$ bower list
bower check-new     Checking for new versions of the project dependencies...
bower-demo /Users/lijia/Desktop/bower
└── jquery#3.0.0 extraneous

查看本地 bower 已经缓存的类库

$ bower cache list
angular=git://github.com/angular/bower-angular.git#1.2.28angular=git://github.com/angular/bower-angular.git#1.3.6angular=git://github.com/angular/bower-angular.git#1.4.4angular=git://github.com/angular/bower-angular.git#1.4.7

查看某一类库的信息

$ bower info jquery
bower jquery#*                  cached https://github.com/jquery/jquery-dist.git#3.0.0bower jquery#*                validate 3.0.0 against https://github.com/jquery/jquery-dist.git#*{
  name: 'jquery',
  main: 'dist/jquery.js',
  license: 'MIT',
  ignore: [    'package.json'
  ],
  keywords: [    'jquery',    'javascript',    'browser',    'library'
  ],
  homepage: 'https://github.com/jquery/jquery-dist',
  version: '3.0.0'}

Available versions:
  - 3.0.0
  - 2.2.4
  - 2.2.3
  - 2.2.2
  - 2.2.1

查看类库地址

$ bower lookup jquery
jquery https://github.com/jquery/jquery-dist.git

搜索类库

$ bower search jqu
jquip https://github.com/mythz/jquip.gitjq https://github.com/jquery/jquery.gitjQuery https://github.com/jquery/jquery.gitjqurey https://github.com/components/jquery.gitjquery https://github.com/jquery/jquery-dist.gitjQueue https://github.com/raincious/jQueue.git





点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
12
获赞与收藏
135

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消