dumi Documentation

repository·master·Indexed 26 days ago

https://github.com/umijs/dumi

A 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.

Tokens
36.1K
Snippets
134
Records
240
Agent score
86%

What's inside dumi

  1. Overview of dumi

    master
    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.
  2. Use the Mobile Component Development Theme

    master

    dumi provides a specialized theme for mobile component development. Key features include:

    1. Mobile Device Demo Preview: Demos are forced to load in iframe mode to simulate mobile environments.
    2. H5 High-Definition (HD) Support: Built on umi-hd for high-density screen scaling.
    3. Full Feature Compatibility: Supports all default theme features, including compact and background demo configurations.
    4. Responsive Fallback: The demo previewer automatically falls back to the default theme mode if responsiveness is required.
  3. Key features of dumi 2.0

    master

    dumi 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.
  4. Understand dumi theme loading priority

    master

    dumi merges themes from three sources in increasing order of priority. Higher priority sources override lower ones:

    1. Built-in default theme: Accessed via dumi/theme-default/.
    2. Installed theme packages: Any package in package.json starting with dumi-theme- or @org/dumi-theme-.
    3. Local theme packages: Files located in the .dumi/theme directory 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.ts or plugin.ts are not merged. The existence of a plugin file in a higher-priority source will register it as a dumi plugin.
  5. Use conventional Page Tabs to organize documentation

    master

    dumi 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}.md for a Markdown file that shares the same base name as the main document. For example, if your main file is page-tab.md, a file named page-tab.$tab-example.md will appear as a tab named example on the page-tab page.

    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.md
  6. Use convention-based file naming for multi-language Markdown

    master

    When using the locales configuration, create multi-language versions of your Markdown files by appending the locale id to the filename before the .md extension.

    Example structure:

    .
    └── docs
        ├── index.md        # Default language (e.g., Chinese)
        └── index.en-US.md  # English version
    .
    └── docs
        ├── index.md        # 已有的中文版首页
        └── index.en-US.md  # 新创建的英文版首页
  7. Customize homepage with features and hero

    master

    You 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, and description (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.
  8. Customize loading, 404, and favicon in dumi

    master

    Customize 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 the favicons configuration option.
  9. Use `<Badge>` components in Markdown

    master

    dumi provides a built-in <Badge> component to add labels or tags to Markdown content (such as headings).

    Available types via the type prop:

    • 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>
  10. Use Vue SFC with Script Setup and Scoped Styles in dumi

    master

    dumi 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>