dumi,中文发音嘟米,是一款为组件开发场景而生的文档工具,与 father 一起为开发者提供一站式的组件开发体验,father 负责构建,而 dumi 负责组件开发及组件文档生成。
环境
- 确保 node 版本是 10.13 或以上
脚手架
$ npx @umijs/create-dumi-lib # 初始化一个文档模式的组件库开发脚手架# or$ yarn create @umijs/dumi-lib$ npx @umijs/create-dumi-lib --site # 初始化一个站点模式的组件库开发脚手架## or$ yarn create @umijs/dumi-lib --site
目录结构
- .umirc.ts 链接 dumi 配置文件(也可以是 config/config.ts)
.fatherrc.ts father-build 的配置文件,用于组件库打包
安装与配置相关依赖
安装项目依赖
- 安装 antd 相关依赖
npm i -D antd babel-plugin-import 配置按需加载
/.umirc.ts● extraBabelPlugins: [['babel-plugin-import',{libraryName: 'antd',libraryDirectory: 'es',style: true,},]]
编写
index.ts导出方法或组件
- 约定式生成文档,或者配置 dumi 嗅探的文档目录
有引入第三方依赖需要过滤接口属性
apiParser: {// 自定义属性过滤配置,也可以是一个函数,用法参考:https://github.com/styleguidist/react-docgen-typescript/#propfilterpropFilter: {// 是否忽略从 node_modules 继承的属性,默认值为 falseskipNodeModules: true,}}
demo文件
tsconfig.json文件中添加路径别名,模拟引入
mdx语法编写文档生成demo及路由 基于docz编写
打包
配置.fatherrc.ts 详细请跳转
- 配置环境入口
main:指定包的入口文件,此处指定为 lib/index.js 。module:指定包的基于 ESM 规范的入口文件,此处指定为 es/index.esm.js 。typings:指定包的类型声明文件,此处指定为 lib/index.d.ts 。files:指定需要推送至 npm 的文件,此处指定为 [“es”,“lib”] 。peerDependencies:指定使用包的项目所需要依赖的模块,由于项目是 React 项目,并且存在依赖于 Ant-Design 组件库的组件,因此此处指定为 react、react-dom、antd
发布
- 发布至npm
- 切换镜像源 npm config set registry https://registry.npmjs.org/ (https://registry.npm.taobao.org )
- npm pack =>查看上传pack
- npm login
- npm publish
2.部署至gitpage
