Vue CLI Plugin for Styleguidist
The `vue-cli-plugin-styleguidist` package integrates Vue Styleguidist into projects initialized with Vue CLI 3.0 or higher. It streamlines the setup process, allowing developers to generate live-reloading component documentation and a style guide directly within their Vue CLI workflow. The current stable version is `4.72.4`, with a release cadence that includes regular patch updates addressing compatibility issues and feature enhancements, primarily through its underlying `vue-styleguidist` and `vue-docgen-api` dependencies. Key differentiators include its tight integration with the Vue CLI ecosystem, simplifying initial configuration and command-line execution for component documentation compared to a manual setup of Vue Styleguidist.
Common errors
-
Error: Cannot find module '@vue/cli-service'
cause The `@vue/cli-service` package, a peer dependency, is not installed or incorrectly linked.fixEnsure `@vue/cli-service` is installed in your project: `npm install @vue/cli-service` or `yarn add @vue/cli-service`. -
TypeError: Cannot read properties of undefined (reading 'path') in webpack config
cause Often indicates an issue with `webpack` version compatibility or incorrect configuration within `styleguide.config.js` that interferes with webpack's module resolution.fixUpdate `webpack` to a compatible version as specified by `vue-cli-plugin-styleguidist`'s peer dependencies. Review your `styleguide.config.js` for any custom webpack modifications that might be causing the issue. -
No component found in <path/to/components>
cause Vue Styleguidist could not locate any Vue components at the specified glob path in `styleguide.config.js` or the components are not properly exported.fixDouble-check the `components` glob pattern in your `styleguide.config.js` to ensure it correctly matches your component files. Verify that your components are valid Vue components and are discoverable.
Warnings
- breaking Versions of `vue-cli-plugin-styleguidist` and its underlying `vue-styleguidist` dependency prior to `4.72.4` may experience compatibility issues when used with Vue 3.3.2 due to internal changes in Vue's reactivity system or compiler. Updating to `4.72.4` or newer is crucial for stable operation with Vue 3.3.2.
- gotcha The plugin is specifically designed for Vue CLI 3.0+ projects. While it might function with newer Vue CLI versions (e.g., 4.x or 5.x) or non-CLI setups (like Vite), full compatibility and all features are best guaranteed within the Vue CLI 3.x ecosystem. Using it outside this context may lead to unexpected behavior or require manual configuration adjustments.
- gotcha The documentation generation relies heavily on `vue-docgen-api`. Older versions of this dependency (e.g., prior to `4.79.2`) had known bugs, such as failing to parse interface extensions or type alias references correctly, leading to incomplete or incorrect component documentation. Users might need to explicitly update `vue-docgen-api` if their project's dependency resolution pulls an older version.
- gotcha The plugin relies on peer dependencies `@vue/cli-service` and `webpack`. Mismatched versions of these peer dependencies can cause build errors or runtime issues when generating the style guide. Always ensure these peer dependencies meet the requirements specified by `vue-cli-plugin-styleguidist`.
Install
-
npm install vue-cli-plugin-styleguidist -
yarn add vue-cli-plugin-styleguidist -
pnpm add vue-cli-plugin-styleguidist
Imports
- StyleguidistConfig
import type { StyleguidistConfig } from 'vue-styleguidist'; - parse
import { parse } from 'vue-docgen-api'; - setup
/* No direct programmatic import for 'setup' from this plugin. */
Quickstart
vue create my-project
cd my-project
vue add styleguidist
# The plugin will prompt you for configuration details.
# After installation, generate the styleguide:
yarn styleguide
# This will typically open the style guide in your browser.
# To customize, edit the generated `styleguide.config.js` or `styleguide.config.ts`.
// Example of a basic component in src/components/MyComponent.vue
// <template>
// <button :class="{ primary }" @click="$emit('click')">{{ label }}</button>
// </template>
// <script setup lang="ts">
// import { defineProps, defineEmits } from 'vue';
//
// interface Props {
// label: string;
// primary?: boolean;
// }
//
// const props = defineProps<Props>();
// const emit = defineEmits<{ (e: 'click'): void }>();
// </script>
// <style scoped>
// .primary { background-color: blue; color: white; }
// </style>