Vue CLI Plugin for Storybook

2.1.0 · maintenance · verified Sun Apr 19

The `vue-cli-plugin-storybook` package provides a streamlined integration of Storybook into existing or new Vue CLI projects. It automates much of the initial setup, including configuring webpack, generating boilerplate files for Storybook, and integrating Storybook commands (like `storybook:serve` and `storybook:build`) directly into the `vue-cli-service`. The latest stable version, 2.1.0, supports Vue 3 and Storybook 6.x. While a 3.x release candidate exists for Vue CLI 5 and Storybook 6.5+, the plugin's overall release cadence has slowed. This is largely due to Vue CLI itself being in maintenance mode, with `create-vue` (Vite-based projects) now recommended for new Vue applications. The plugin's key differentiator is its ability to abstract away complex Storybook configurations, leveraging the Vue CLI's webpack setup to minimize manual intervention for developers working within the Vue CLI ecosystem. For new Storybook setups, the general `npm create storybook@latest` CLI is increasingly the recommended installation method across frameworks, including Vue.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to add the plugin to a Vue CLI project, defines a sample Vue component, and creates a basic Storybook story using modern Component Story Format (CSF) 3, concluding with instructions to launch Storybook.

npx @vue/cli create my-storybook-app --default
cd my-storybook-app

# Add the Storybook plugin (choose Vue 3 preset if prompted, for this example)
vue add storybook

# The plugin adds Storybook commands and configuration.
# Example `src/components/MyButton.vue`:
// <template>
//   <button :style="{ backgroundColor }" @click="$emit('click')">
//     {{ label }}
//   </button>
// </template>
//
// <script lang="ts">
// import { defineComponent } from 'vue';
// export default defineComponent({
//   name: 'MyButton',
//   props: {
//     label: { type: String, required: true },
//     backgroundColor: { type: String, default: '#42b983' },
//   },
// });
// </script>
//
// <style scoped>
// button {
//   font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
//   font-weight: 700;
//   border: 0;
//   border-radius: 3em;
//   cursor: pointer;
//   display: inline-block;
//   line-height: 1;
//   font-size: 14px;
//   padding: 10px 16px;
//   color: white;
// }
// </style>

# Example Story file `src/stories/MyButton.stories.ts` (using CSF 3, compatible with Storybook 7+)
import type { Meta, StoryObj } from '@storybook/vue3';
import MyButton from '../components/MyButton.vue';

const meta: Meta<typeof MyButton> = {
  title: 'Example/MyButton',
  component: MyButton,
  tags: ['autodocs'],
  argTypes: {
    backgroundColor: { control: 'color' },
    onClick: { action: 'clicked' },
  },
};

export default meta;

type Story = StoryObj<typeof MyButton>;

export const Primary: Story = {
  args: {
    label: 'Button',
    backgroundColor: '#3f51b5',
  },
};

export const Secondary: Story = {
  args: {
    label: 'Secondary Button',
    backgroundColor: '#f50057',
  },
};

# To run Storybook after installation:
npm run storybook:serve
# or
yarn storybook:serve

view raw JSON →