安装
安装bower需要先安装nodejs
安装命令 $ npm install -g bower

安装包
通过$ bower install [<options>]安装软件包,默认会安装到 bower_components/目录.
另外,可以通过配置文件bower.json一次安装所有软件包
通过$ bower init一路回车, 创建bower.json文件,bower.json内容如下

{
  "name": "bower-tuition",
  "authors": [
    "aoping <1216791584@qq.com>"
  ],
  "description": "",
  "main": "",
  "license": "MIT",
  "homepage": "",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ]
}

添加

"dependencies": {
  }

到上述文件,如

{
  "name": "bower-tuition",
  "authors": [
    "aoping <1216791584@qq.com>"
  ],
  "description": "",
  "main": "",
  "license": "MIT",
  "homepage": "",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "bootstrap": "^3.3.7"
  }
}

执行bower install就可以下载dependencies里的软件包了

bower常用命令

$ bower help <command> 显示关于Bower的帮助信息
$ bower init 创建bower.json文件
$ bower install [<options>] 安装包
$ bower update <name> [<name> ..] [<options>] 更新包
$ bower uninstall <name> [<name> ..] [<options>] 卸载包

.bowerrc

.bowerrc是bower的配置文件

{
  "analytics": true,
  "cwd": "~/.my-project",//当前目录
  "directory": "bower_components",//软件包安装的目录,默认是bower_components
  "registry": "https://bower.herokuapp.com",
  "shorthand-resolver": "git://github.com//.git",
  "proxy": "http://proxy.local",
  "https-proxy": "https://proxy.local",
  "ca": "/var/certificate.pem",
  "color": true,
  "timeout": 60000,
  "strict-ssl": true,
  "storage": {
    "packages" : "~/.bower/packages",
    "registry" : "~/.bower/registry",
    "links" : "~/.bower/links"
  },
  "interactive": true,
  "resolvers": [
    "mercurial-bower-resolver"
  ],
  "shallowCloneHosts": [
    "myGitHost.example.com"
  ],
  "scripts": {//三个钩子
    "preinstall": "",
    "postinstall": "",
    "preuninstall": ""
  },
  "ignoredDependencies": [
    "jquery"   
  ]
}

常见问题

  1. bower ENOINT Register requires an interactive shell

如果您使用的是windows,请换用WINDOW的cmd来输入命令试试

普通程序员
4k 声望811 粉丝

分享IT干货,内推大厂