Storybook framework for Vue 3 applications with Vite build tool integration.
—
Advanced component metadata extraction system supporting both modern and legacy documentation generation approaches for Vue 3 components.
Available documentation generation plugins with different capabilities and use cases.
/** Available docgen plugins for Vue components */
type VueDocgenPlugin = 'vue-docgen-api' | 'vue-component-meta';Type definitions for component documentation information based on the chosen plugin.
/**
* Type of __docgenInfo depending on the used docgenPlugin
*/
type VueDocgenInfo<T extends VueDocgenPlugin> = T extends 'vue-component-meta'
? ComponentMeta
: ComponentDoc;
/**
* Single prop/event/slot/exposed entry of __docgenInfo depending on the used docgenPlugin
*
* @example
* type PropInfo = VueDocgenInfoEntry<'vue-component-meta', 'props'>;
*/
type VueDocgenInfoEntry<
T extends VueDocgenPlugin,
TKey extends 'props' | 'events' | 'slots' | 'exposed' | 'expose' =
| 'props' | 'events' | 'slots' | 'exposed' | 'expose'
> = ArrayElement<
T extends 'vue-component-meta'
? VueDocgenInfo<'vue-component-meta'>[Exclude<TKey, 'expose'>]
: VueDocgenInfo<'vue-docgen-api'>[Exclude<TKey, 'exposed'>]
>;Helper type for extracting single array element types.
/** Gets the type of a single array element */
type ArrayElement<T> = T extends readonly (infer A)[] ? A : never;Modern documentation plugin using Volar's vue-component-meta for advanced TypeScript support.
Features:
Configuration:
docgen: "vue-component-meta"
// OR with custom tsconfig
docgen: {
plugin: "vue-component-meta",
tsconfig: "tsconfig.app.json"
}Legacy documentation plugin using vue-docgen-api for basic component documentation.
Features:
.vue single-file componentsConfiguration:
docgen: "vue-docgen-api"
// OR explicitly
docgen: {
plugin: "vue-docgen-api"
}When using vue-component-meta, components receive detailed metadata:
interface ComponentMeta {
props: PropMeta[];
events: EventMeta[];
slots: SlotMeta[];
exposed: ExposedMeta[];
type: TypeMeta;
}
interface PropMeta {
name: string;
description?: string;
type: string;
schema: PropertyMetaSchema;
required: boolean;
default?: any;
}
interface EventMeta {
name: string;
description?: string;
type: string;
schema: PropertyMetaSchema | PropertyMetaSchema[];
}
interface MetaSource {
exportName: string;
displayName: string;
sourceFiles: string;
props: PropMeta[];
events: EventMeta[];
slots: SlotMeta[];
exposed: ExposedMeta[];
}When using vue-docgen-api, components receive basic documentation:
interface ComponentDoc {
displayName: string;
description?: string;
props?: PropDoc[];
events?: EventDoc[];
slots?: SlotDoc[];
methods?: MethodDoc[];
}
interface PropDoc {
name: string;
type?: Type;
description?: string;
required?: boolean;
defaultValue?: any;
}Components processed by the documentation plugins receive a __docgenInfo property:
// In your component
export default defineComponent({
name: 'MyComponent',
props: {
title: String,
count: Number,
},
emits: ['update', 'change'],
});
// After processing, the component will have:
MyComponent.__docgenInfo = {
props: [
{ name: 'title', type: 'string', required: false },
{ name: 'count', type: 'number', required: false },
],
events: [
{ name: 'update', type: 'void' },
{ name: 'change', type: 'void' },
],
// ... other metadata
};When using TypeScript configurations with references:
// .storybook/main.ts
import type { StorybookConfig } from "@storybook/vue3-vite";
const config: StorybookConfig = {
framework: {
name: "@storybook/vue3-vite",
options: {
docgen: {
plugin: "vue-component-meta",
tsconfig: "tsconfig.app.json", // References your app-specific config
},
},
},
};For improved build performance, documentation generation can be disabled:
// .storybook/main.ts
const config: StorybookConfig = {
framework: {
name: "@storybook/vue3-vite",
options: {
docgen: false, // Disables all documentation generation
},
},
};To migrate to the modern plugin:
// Before (vue-docgen-api)
docgen: "vue-docgen-api"
// After (vue-component-meta)
docgen: "vue-component-meta"
// Or with custom tsconfig
docgen: {
plugin: "vue-component-meta",
tsconfig: "tsconfig.app.json"
}Benefits of Migration:
The vue-component-meta plugin includes automatic schema optimization to prevent memory issues:
/**
* Removes nested schemas from component metadata to prevent memory issues
* @param schema - Property metadata schema to optimize
*/
function removeNestedSchemas(schema: PropertyMetaSchema): void;Optimization Features:
Component analysis is filtered to include only relevant files:
// Included files
const include = /\.(vue|ts|js|tsx|jsx)$/;
// Excluded patterns
const exclude = /\.stories\.(ts|tsx|js|jsx)$|^\0\/virtual:|^\/virtual:|\.storybook\/.*\.(ts|js)$/;Filter Logic:
Install with Tessl CLI
npx tessl i tessl/npm-storybook--vue3-vite