使用 bower 管理微信小程序的三方依赖 zanui-weapp

更新日期: 2018-03-27 阅读次数: 9325 分类: 微信小程序

如果微信小程序中使用了三方的组件库,最好还是使用 bower 进行管理。

否则升级三方组件库,是件非常浪费时间的事情。而 bower install 一行命令就能搞定。

安装 bower

cnpm install -g bower

安装最新版本的 zanui-weapp

bower install zanui-weapp

安装指定版本的 zanui-weapp

bower install zanui-weapp#2.4.7 --save

git 管理三方依赖版本

使用 --save 参数之后,会提示

no-json No bower.json file to save to, use bower init to create one

使用 bower init 初始化一个 bower.json 文件。

 % bower init                       
? name jiashun
? description 
? main file 
? keywords 
? authors Zhongwei Sun <zhongwei.sun2008@gmail.com>
? license MIT
? homepage 
? set currently installed components as dependencies? Yes
? add commonly ignored files to ignore list? Yes
? would you like to mark this package as private which prevents it from being accidentally published to the registry? Yes

{
  name: 'jiashun',
  authors: [
    'Zhongwei Sun <zhongwei.sun2008@gmail.com>'
  ],
  description: '',
  main: '',
  license: 'MIT',
  homepage: '',
  private: true,
  ignore: [
    '**/.*',
    'node_modules',
    'bower_components',
    'test',
    'tests'
  ],
  dependencies: {
    'zanui-weapp': '^2.4.7'
  }
}

? Looks good? Yes

看上去类似于 npm 的配置文件 package.json.

这样把 bower.json 添加到 git 管理中即可,其他人就可以同步依赖的版本了。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式