bower 前端依赖包管理

前端之家收集整理的这篇文章主要介绍了bower 前端依赖包管理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前端开发圈越来越热闹,第三方js库层出不穷,版本更迭日新月异;且许多库又对其他库有着依赖关系。而我们的页面需要的库也越来越多样化。以往需要引入第三方库,需要搜索寻找所需库的特定版本下载,还需要搜索寻找下载特定版本的依赖库,十分麻烦;库的更新也是件十分繁琐的事情。是否有一个工具:搜索自动安装/卸载、检查更新、确保依赖关系……

Bower 是 twitter 推出的一款包管理工具,基于nodejs的模块化思想,把功能分散到各个模块中,让模块和模块之间存在联系,通过 Bower 来管理模块间的这种联系。npm是专门管理node模块的管理工具,而bower是node的模块,因为bower是依赖node,npm和git。正如前面所言,npm是擅长的是管理node模块,而bower管理的范围更大,涉及html,css,js和图片等媒体资源。或许,这也是人们喜欢在服务器端使用npm,而在客户端使用bower。

bower可以管理包含HTML,CSS,JavaScript的,字体甚至是图像文件的组成部分。bower并没有串联或运行如下代码或做别的事,它仅仅安装你需要的包及其依赖的正确版本。

@H_404_10@

1、安装

npm install -g bower
bower -v

2、配置 .bowerrc

{

  "directory": "public/assets/","timeout": 120000,"registry": { "search": [ "http://localhost:8000","https://bower.herokuapp.com","https://github.com" ] } }

放在项目目录下

@H_404_10@

3、映射表查询

如果我们想下载jquery-cookie,但不知道bower内置的映射表对应的名称,可以通过以下指令查询

bower search jquery-cookie

4、类库安装/卸载,储存到bower.json

//创建bower.json文件
bower init  //下载安装bower.json内的类库
bower install

 //将类库下载并写入bower.json
bower install jquery --save  //直接用bower下载特定版本类库
bower install jquery#1.12.4 --save
 //用GitHub简写下载类库 
bower install desandro/masonry  --save //用git端点下载类库
bower install git://github.com/user/package.git  --save //使用url下载类库
bower install http://example.com/script.js  --save //卸载类库
bower uninstall jquery  --save 

5、查询类库历史版本

bower info jquery
$ bower help
Usage:

    bower <command> [<args>] [<options>]

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
    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

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
原文链接:https://www.f2er.com/javaschema/283094.html

猜你在找的设计模式相关文章