Skip to content

用 react + lerna + yarn workspace + rollup + storybook 进行包管理

License

Notifications You must be signed in to change notification settings

BaoHaoYu/react-lerna-yarn-workspace

Repository files navigation

用 react + lerna + yarn workspace + rollup + storybook 进行包管理

前奏

  • 如果使用作用域 @lerna-demo ,先要创建 org,具体参考官方文档
  • 在根目录创建.npmrc,内容为 //registry.npmjs.org/:_authToken=<token>,方便提交到 npm

命令

yarn 开启工作空间

yarn config set workspaces-experimental true

安装依赖

yarn

添加新的包到依赖,注意加入-W

yarn add *any_pack* -W

编译所有包

npm run build:all

编译发生改变的包

npm run build:changed

编译所有包同时监视

npm run build:w

启动 storybook

npm run storybook 打开6006

启动 jest 监视,结果输出到.jest-test-results.json

如果 storybook 需要显示 jest 结果,则要执行该命令
npm run test:generate-output

格式化 ts

npm run tslint

发布到 npm

npm run release

特性

  • lerna
  • tslint
  • stylelint
  • storybook
  • push to npm
  • jest
  • husky
  • lint-staged

发布

要打上标签,lerna diff对比的是上个打上标签的提交,和最后提交这俩个提交进行对比的 所以,建议每次发布都打上标签如 v0.0.1,v0.0.2 之类的,Annotated Tags 语句

.npmrc

填写token.npmrc中,内容如下 //registry.npmjs.org/:_authToken=.................

Annotated Tags

git tag -a v0.0.1 -m "my version 0.0.1"

如果没有上 Annotated Tags,lerna changed会无法找到改变的包,因为本质是使用git describe命令

  • 没有加入 Annotated Tags
fatal: No annotated tags can describe 'f87c255432d4fa4656ef37f9f28bdd94f6b55fa5'
.
However, there were unannotated tags: try --tags.
  • 加入 tag
D:\project-demo\yarn-workspaces-demo>git describe
v0.0.1

--no-git-tag-version

  • lerna publish --no-git-tag-version:取消自动打标签,lerna不会自动更新包的版本了 pack1版本是0.0.1,推送到npm后,本地依旧是0.0.1
  • lerna publish:自动更新包的版本,为最后的提交打上每个包的版本标签,然后再推送

lerna 只会找当前的分支进行标签对比,然后判断是否要发布,如果标签打在其他分支上面,lerna 会忽略

--no-git-reset

  • lerna publish --no-git-reset:lerna自动更新包的版本了
  • lerna publish:lerna根据上个标签的更新包的版本

其他

如何让 jest 快速运行

About

用 react + lerna + yarn workspace + rollup + storybook 进行包管理

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published