bower和npm的依赖管理

npm 是Node.js 模块管理的标准工具, 同时也可以结合诸如Browserify等其他工具, 用以管理前端.
Bower 是用于前端依赖管理的工具, 并为前端做了不少的优化.
两者的本质区别, npm 支持nested dependency tree.

project root
[node_modules] // default directory for dependencies
 -> dependency A
 -> dependency B
    [node_modules]
    -> dependency A

 -> dependency C
    [node_modules]
    -> dependency B
      [node_modules]
       -> dependency A 
    -> dependency D 

而bower 只支持flat dependency tree.

project root
[bower_components] // default directory for dependencies
 -> dependency A
 -> dependency B // needs A
 -> dependency C // needs B and D
 -> dependency D

nested dependency tree 避免了依赖冲突, 但耗费了更多的空间和时间. 这在前端项目中是不可接受的, 例如它很可能会下载多个jquery 的copy.
而bower 为最小的资源加载而优化. 同一个包, 只会在依赖关系中出现一次. 所以可能会有潜在的依赖冲突问题的产生. 例如A 和B 都依赖于C, 但A 依赖的是C 的V1 版本, 而B 依赖的是V2 版本, 这在bower 中会参数冲突, 同一资源(包) 不能有多个副本!

通常, Bower 会在webpage 发布时使用, 因为此时必须避免duplication. 而npm 会在testing, building, optimizing, checking 等开发阶段中被使用.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值