grunt+bower依赖管理

时间:2023-03-09 19:42:47
grunt+bower依赖管理

安装bower(必须安装git)

npm install bower -g

bower按照插件命令

初始化配置

bower init 生成bower.json
//如果有bower.json 直接输入bower install下载依赖组件,这个和grunt一样。
bower install jquery --save(save 保存到bower.json) {
"name": "grunt_bower",
"description": "lib bower",
"main": "index.js",
"authors": [
"cjw"
],
"license": "ISC",
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"jquery": "^1.11.3",
"requirejs": "^2.2.0",
"text": "^2.0.15",
"underscore": "^1.8.3",
"backbone": "https://github.com/marionettejs/backbone.wreqr/"
}
}

为了把bower按照的插件拷贝到lib下面、

为了实现这样的功能,我们还需要另一个插件的帮助:

npm install grunt-bower-task --save-dev

然后打开其文档,按照上面的提示进行配置。首先在 Gruntfile 中合适位置添加:

grunt.loadNpmTasks('grunt-bower-task');

然后在 grunt.initConfig({...}) 参数中,添加相应的配置项,把bower下载的js库拷贝到 public/js/lib 下:

{
"bower": {
"install": {
"options": {
"targetDir": "./public/js/lib",
"layout": "byComponent",
"install": true,
"verbose": false,
"cleanTargetDir": false
}
}
}
}

然后直接输入 grunt bower

也可以直接写到watch里面