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

发布时间: 2018-03-27 17:02:10 作者: 大象笔记

如果微信小程序中使用了三方的组件库,最好还是使用 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 管理中即可,其他人就可以同步依赖的版本了。

我是一名山东烟台的开发者,联系作者