
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
create-ui-lib
Advanced tools
基于 storybook 扩展的组件库脚手架,用于快速构建 React 组件库。
在前端开发中,我们经常会遇到以下情景:
构建一个组件库,需要的工具又广又杂,我们考虑到一个成熟的组件库至少应该满足以下最基本的开发要求:
esm 和 cjs 模块的组件代码Eslint + Prettier + Yorkie + Commitlint + Commitizen + Lint-staged 规范前端工程代码规范gitlab-ci 自动部署组件库文档✔︎ 组件库面向的不仅仅是开发者,还有可能是产品、运营、UI 人员
✔︎ storybook 创建的文档交互性强,可以在文档中修改参数实时查看效果,便于产品、运营、UI 人员做参考
✔︎ 可以为组件自动生成文档和属性列表
终端运行以下命令,创建组件库
npx -p create-ui-lib create-library

可根据需要选择是否生成接口请求相关的文件
终端切到需要改造的项目,执行以下命令
# 终端切到需要改造的项目
cd [projectName]
# 初始化项目
npx -p create-ui-lib create-library --move
请确保需要改造的项目中存在基础文件 package.json
├── .storybook
│ ├── mocker # 数据mock
│ │ ├── webapi # mock文件目录
│ │ ├── index # mock数据入口文件
│ │ ├── mockServiceWorker.js # service worker文件
│ ├── main.js # 控制 Storybook 服务器的行为
│ ├── middleware.js # 接口代理
│ ├── preview.js # Storybook 控制渲染
├── dist # 构建目录
│ ├── es # esm构建结果
│ ├── lib # cjs构建结果
├── src
│ ├── components # 组件
│ │ ├── story-button # 示例组件button
│ │ │ ├── demos # 文档目录
│ │ │ │ ├── xx.stories.mdx # 组件文档
│ │ │ │ ├── xx.stories.tsx # 组件示例
│ │ │ │ ├── xx.test.tsx # 组件测试用例
│ │ │ ├── button.less # 组件样式文件
│ │ │ ├── button.tsx # 组件编写文件
│ │ │ ├── index.ts # 组件入口文件
│ ├── services # 接口请求目录
│ ├── index.ts # 组件库入口文件
│ ├── Introduction.stories.mdx # 组件库文档介绍
├── .fatherrc.ts # father-build配置文件
├── .gitignore
├── .gitlab-ci.yml # 文档自动部署脚本
├── .yarnrc # 设置yarn镜像源
├── jest.config.js # jest配置文件
├── jest.setup.ts # jest配置文件
├── CHANGELOG.md # 组件库更新日志
├── package.json
├── README.md
├── tsconfig.json # ts配置文件
请根据需要修改 src 下的文件和内容
yarn start:docs
# 启动mock数据
yarn mock:docs
yarn demo:add
会在 src/components 目录下生成 demo 组件目录
yarn build:library
组件发布前会先进行打包操作,确保发布最新代码
yarn pub
执行后,会自动将组件发布到 xnpm
npm 包包含以下文件
├── dist # 构建目录
│ ├── es # esm构建结果
│ ├── lib # cjs构建结果
├── package.json
├── README.md
yarn upg
# 运行
yarn test
# watch
yarn test:watch
为方便开发者存放代码,提供了专门的 GitLab Group

仓库创建完成后,和项目进行关联即可
将代码 push 到 gitlab 仓库后,会自动部署文档至 gitlab 仓库对应的 pages 地址,查看路径:Seetings - Pages

如果代码没有放在专门提供的 GitLab Group中,请确保当前你的 gitlab 仓库支持 CI/CD。
FAQs
create ui cli
The npm package create-ui-lib receives a total of 1 weekly downloads. As such, create-ui-lib popularity was classified as not popular.
We found that create-ui-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.