Vue Docgen CLI

4.79.0 · active · verified Tue Apr 21

vue-docgen-cli is a command-line interface tool designed to generate comprehensive Markdown documentation files directly from Vue.js component source code. Built upon the powerful vue-docgen-api, it parses Vue 2 and Vue 3 components (including Composition API with script setup, defineProps, defineEmits, and defineSlots) and extracts their props, events, methods, slots, and other metadata into structured Markdown. The current stable version is 4.79.0, with frequent patch and minor releases often synchronized with updates to vue-docgen-api to maintain compatibility with the latest Vue features. Key differentiators include its highly customizable templating system for output Markdown, support for a configurable `docgen.config.js` file, a watch mode for automatic regeneration, and the ability to integrate with existing build configurations (e.g., Webpack aliases) to correctly resolve component dependencies. It provides a static documentation generation alternative to in-browser style guides.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install vue-docgen-cli, define a basic Vue component with JSDoc comments, and then use the CLI via npm scripts to generate Markdown documentation for it.

```javascript
// package.json
{
  "name": "my-vue-project-docs",
  "version": "1.0.0",
  "description": "Generate docs for Vue components",
  "scripts": {
    "docs:generate": "vue-docgen src/components/**/*.vue docs/components",
    "docs:watch": "vue-docgen -w src/components/**/*.vue docs/components"
  },
  "devDependencies": {
    "vue-docgen-cli": "^4.79.0"
  }
}

// src/components/MyButton.vue
<template>
  <button @click="handleClick">{{ label }}</button>
</template>

<script setup lang="ts">
/**
 * A universal button component.
 * @displayName MyButton
 */
import { ref } from 'vue';

/**
 * Props for MyButton.
 */
interface MyButtonProps {
  /**
   * The text label for the button.
   * @type {string}
   * @example 'Click Me'
   */
  label: string;
  /**
   * Determines if the button is disabled.
   */
  disabled?: boolean;
}

const props = withDefaults(defineProps<MyButtonProps>(), {
  disabled: false,
});

const emit = defineEmits<{ (e: 'click', event: MouseEvent): void }>();

const count = ref(0);

/**
 * Handles the click event on the button.
 * @param {MouseEvent} event - The native mouse event.
 * @event click
 */
const handleClick = (event: MouseEvent) => {
  if (!props.disabled) {
    count.value++;
    emit('click', event);
  }
};
</script>

// Terminal commands
$ npm install
$ npm run docs:generate
```

view raw JSON →