dumi Documentation
repository·master·Indexed 26 days ago
https://github.com/umijs/dumiA specialized static site generator optimized for building documentation websites for component libraries. It includes tools for extracting Vue component metadata via @dumijs/vue-meta, Vue 3 support through @dumijs/preset-vue, and a theme development workflow using create-dumi and father-plugin-dumi-theme.
What's inside dumi
- dumi is a static site framework specifically designed for component development scenarios. It works in tandem with father to provide a one-stop component development experience: father handles the building of component source code, while dumi handles component development and component documentation generation.
Use the Mobile Component Development Theme
masterdumi provides a specialized theme for mobile component development. Key features include:
- Mobile Device Demo Preview: Demos are forced to load in
iframemode to simulate mobile environments. - H5 High-Definition (HD) Support: Built on
umi-hdfor high-density screen scaling. - Full Feature Compatibility: Supports all default theme features, including
compactandbackgrounddemo configurations. - Responsive Fallback: The demo previewer automatically falls back to the default theme mode if responsiveness is required.
- Mobile Device Demo Preview: Demos are forced to load in
Key features of dumi 2.0
masterdumi 2.0 includes several core enhancements:
- Improved Compilation Performance: Utilizes Umi 4 MFSU, esbuild, SWC, and persistent caching for faster build speeds compared to v1.x.
- Built-in Full-text Search: Supports searching through titles, body text, and demos without requiring third-party services or increasing production bundle size.
- New Theme System: Supports plugins and internationalization for theme packages. It also provides local override capabilities (similar to Docusaurus swizzling) for theme users.
- Enhanced Convention-based Routing: Simplifies routing configuration and generation to be more intuitive compared to v1.x.
- Asset Metadata 2.0: Features a redesigned structure for asset attribute definitions based on JSON Schema to support better asset circulation.
- Component R&D Integration: Integrates with father 4 (an NPM package development tool) to provide a complete development workflow.
Configure Tab titles using FrontMatter
masterBy default, the Tab title is derived from the
{key}in the$tab-{key}.mdfilename. To provide a custom, user-friendly title for a Tab, use thetitlefield in the file's FrontMatter.--- title: Tab 示例 ---Understand dumi theme loading priority
masterdumi merges themes from three sources in increasing order of priority. Higher priority sources override lower ones:
- Built-in default theme: Accessed via
dumi/theme-default/. - Installed theme packages: Any package in
package.jsonstarting withdumi-theme-or@org/dumi-theme-. - Local theme packages: Files located in the
.dumi/themedirectory of your project. These are typically used for partial overrides or extensions.
Merging Logic
- Components (
builtins,layouts,slots): Merged and overridden by component name. If a higher-priority theme provides a component with the same name, it replaces the lower-priority one. - Locales: Merged by language type (e.g.,
Object.assign(default, installed, local)). - Plugins:
plugin/index.tsorplugin.tsare not merged. The existence of a plugin file in a higher-priority source will register it as a dumi plugin.
- Built-in default theme: Accessed via
Install @dumijs/vue-meta
masterInstall the
@dumijs/vue-metapackage using pnpm to start extracting Vue component metadata.pnpm i @dumijs/vue-metaUse conventional Page Tabs to organize documentation
masterdumi supports out-of-the-box conventional Page Tabs to group related content (like API, Examples, and Design Specs) under a single route.
To create a tab, use the naming convention
$tab-{key}.mdfor a Markdown file that shares the same base name as the main document. For example, if your main file ispage-tab.md, a file namedpage-tab.$tab-example.mdwill appear as a tab namedexampleon thepage-tabpage.File Structure Example:
. └── docs └── guide ├── page-tab.md └── page-tab.$tab-example.md # This becomes the 'example' tab. └── docs └── guide ├── page-tab.md └── page-tab.$tab-example.mdUse convention-based file naming for multi-language Markdown
masterWhen using the
localesconfiguration, create multi-language versions of your Markdown files by appending the localeidto the filename before the.mdextension.Example structure:
. └── docs ├── index.md # Default language (e.g., Chinese) └── index.en-US.md # English version. └── docs ├── index.md # 已有的中文版首页 └── index.en-US.md # 新创建的英文版首页Customize homepage with features and hero
masterYou can transform a Markdown page into a homepage using Frontmatter configuration.
- features: Displays a grid of component features (typically 3 per row). Each feature can have an
emoji,title,link, anddescription(supports HTML). - hero: Configures the hero section at the top of the page.
title: Large heading.description: Subtext (supports HTML).actions: An array of buttons. The last button in the array is rendered as the primary button.
- sidebar: A boolean to show or hide the sidebar on that specific page.
- features: Displays a grid of component features (typically 3 per row). Each feature can have an
Customize loading, 404, and favicon in dumi
masterCustomize the user experience of your documentation site using these file conventions:
- Loading Component: Create
.dumi/loading.(js|jsx|ts|tsx)to define a global loading component. This is useful for showing custom animations while asynchronous chunks are loading during route transitions. - 404 Page: Create
.dumi/pages/404.(js|jsx|ts|tsx)to define a custom 404 error page. - Favicon: Place a favicon file at
.dumi/favicon.(ico|gif|png|jpg|jpeg|svg|avif|webp). dumi will automatically insert the corresponding<link>tag. Alternatively, you can manually specify the favicon via thefaviconsconfiguration option.
- Loading Component: Create
Use `<Badge>` components in Markdown
masterdumi provides a built-in
<Badge>component to add labels or tags to Markdown content (such as headings).Available types via the
typeprop:- Default:
<Badge>text</Badge> - Warning:
<Badge type="warning">text</Badge> - Error:
<Badge type="error">text</Badge> - Success:
<Badge type="success">text</Badge>
### Info Badge <Badge>info</Badge> ### Warning Badge <Badge type="warning">warning</Badge> ### Error Badge <Badge type="error">error</Badge> ### Success Badge <Badge type="success">success</Badge>- Default:
Use Vue SFC with Script Setup and Scoped Styles in dumi
masterdumi supports Vue Single File Components (SFC). You can use the
<script setup>syntax with TypeScript and scoped styles. To apply specific background colors to a demo block, use a comment directive like<!-- background: '#f6f7f9' -->at the top of the file.<!-- background: '#f6f7f9' --> <script setup lang="ts"> import { ref } from 'vue'; defineProps<{ foo?: string; bar?: number; }>(); const msg = ref('Hello World!'); const color = ref('chartreuse'); </script> <template> <h1 class="msg">{{ msg }}</h1> <div> <input v-model="msg" /> </div> </template> <style scoped> .msg { color: v-bind('color'); } </style>