全部包是統一的版本號,每次升級,全部包版本統一更新,無論這個包內容改變與否vue
具體體如今,lerna
的配置文件 lerna.json
中永遠會存在一個肯定版本號:node
{ "version": "0.0.1" }
典型例子: babel
、vue
git
每一個包是單獨的版本號,每次lerna 觸發發佈命令,每一個包的版本都會單獨變化shell
具體體如今,lerna
的配置文件 lerna.json
中沒有一個肯定版本號,而是:npm
{ "version": "independent" }
npm install lerna -g lerna -v
代碼規範採用lerna
提供的規範結構的話:json
# 默認固定模式 lerna init # 要採用獨立模式的話 lerna init -i # lerna init --independent
└── lerna/ ├── packages/ ├── lerna.json └── package.json
若是代碼已經存在,則只須要在項目下建立lerna.json
並補充相關字段bootstrap
{ "useWorkspaces": true, // 使用 workspaces 配置。此項爲 true 的話,將使用 package.json 的 "workspaces",下面的 "packages" 字段將不生效 "version": "0.1.0", // 全部包版本號,獨立模式-"independent" "npmClient": "cnpm", // npm client,可設置爲 cnpm、yarn 等 "packages": [ // 包所在目錄,可指定多個 "packages/*" ], "command": { // lerna 命令相關配置 "publish": { // 發佈相關 "ignoreChanges": [ // 指定文件或目錄的變動,不觸發 publish ".gitignore", "*.log", "*.md" ] }, "bootstrap": { // bootstrap 相關 "ignore": "npm-*", // 不受 bootstrap 影響的包 "npmClientArgs": [ // bootstr 執行參數 "--no-package-lock" ] } } }
lerna官方文檔https://lerna.js.org/babel
建立一個新的
lerna
倉庫或者將現有的倉庫使用lerna
管理spa
lerna init # -i/--independent
發佈包代碼規範
lerna publish
把全部包安裝到根
node_modules
lerna bootstrap
運行每一個包中的
script
命令
lerna run <script> --[...args]
單獨運行某個包下的
script
命令
lerna exec -- <command> [...args] # example $ lerna exec -- rm -rf ./node_modules $ lerna exec -- protractor conf.js
安裝本地或者遠程的包
lerna add <package>[@version] [--dev] [--exact] [--peer] #--dev 將新包添加到devDependencies而不是dependencies. #--exact 添加具備確切版本(例如1.0.1)而不是默認^semver 範圍(例如^1.0.1)的新包。 #--peer 將新包添加到peerDependencies而不是dependencies. #將 module-1 包添加到 'prefix-' 前綴文件夾中的包中 lerna add module-1 packages/prefix-* #將模塊 1 安裝到模塊 2 lerna add module-1 --scope=module-2 #在 devDependencies 中將 module-1 安裝到 module-2 lerna add module-1 --scope=module-2 --dev #在 peerDependencies 中安裝 module-1 到 module-2 lerna add module-1 --scope=module-2 --peer #在除module-1以外的全部模塊中安裝module-1 lerna add module-1 #在全部模塊中安裝 babel-core lerna add babel-core