安装
yarn global add lernaor npm install -g lerna
基本项目
- 初始化
git init platformcd platformlerna init效果如下:├── lerna.json├── package.json└── packages
- 创建包common && server
mkdir common server common├── index.js└── package.jsonindex.jsmodule.exports={name:"dalong-common 1.0.0",type:"common"}package.json{"name": "common","version": "1.0.0","main": "index.js","license": "MIT"}server├── index.js├── package-lock.json└── package.jsonindex.jsconst common =require("common");console.log(common);package.json{"name": "server","version": "1.0.0","main": "index.js","license": "MIT","dependencies": {"common": "1.0.0","shortid": "^2.2.8"}}
处理依赖
lerna bootstrap
效果如下:
测试
node packages/server{ name: 'dalong-common 1.0.0', type: 'common' }
说明
这个只是简单的使用,实际可以做的事情的很多,比如changelog issue 。。。类似的yarn 也是一个不错的工具
参考资料