前端工具bower wiredep

来源:互联网 发布:cad画网络拓扑结构图 编辑:程序博客网 时间:2024/06/06 01:23

Bower是一个客户端技术的软件包管理器,它可用于搜索、安装和卸载如JavaScript、HTML、CSS之类的网络资源。

详细信息请参考bower官网。

几个例子:

1.当前项目需要引入jquery

bower install jquery  

只需上面简单一条命令就可以将jquery库已经其依赖的库下载下来。直接就可以在项目中引用相关的文件就可以了。

2.使用bower.json

{  "name": "bower demo",  "version": "2.9.0",  "homepage": "",  "authors": [    "xiaopeng <lost1q84@gmail.com>"  ],  "description": "bower.json test project",  "keywords": [    "test"  ],  "license": "MIT",  "ignore": [    "node_modules",    "bower_components",    "test",    "tests"  ],  "dependencies": {    "jquery": "~2.1.0",    "angular": "~1.3.15",    "angular-animate": "~1.3.15",    "angular-ui-router": "~0.2.12",    "ui-router-extras": "~0.0.13",    "angular-bootstrap": "~0.13.0",    "ngInfiniteScroll": "~1.2.0"  }}

将bower.json文件放入项目的根目录中,在项目根目录中运行bower install就可以直接将项目所需要的前端库,直接下载下来。

bower解决了前端库及其依赖安装的问题。至于怎么把真正所需要的文件引入到html文件中,就需要wiredep来帮忙啦。

详情参考wiredep项目主页

html文件(index.html)

<html>  <head>    <!-- bower:css -->  <!-- endbower --></head>  <body>    <!-- bower:js -->  <!-- endbower --></body>  </html>  

gulp.js

var wiredep = require('wiredep').stream;gulp.task('bower', function () {    gulp.src('./index.html')    .pipe(wiredep({      optional: 'configuration',      goes: 'here'    }))    .pipe(gulp.dest('./'));});

在命令行运行gulp bower就可以将所需库的js、css文件直接引入到html文件中。

bower解决了前端库依赖管理的痛点,而wiredep解决了bower前端库引入进html的问题。

0 0