Vue Academy · Lesson

Setting Up Storybook for Vue 3

npx storybook@latest init, .storybook/config, main.js, stories directory, running.

Lesson 1 of 413 steps

Setting Up Storybook for Vue 3 is a free Vue Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.

What Is Storybook?

Storybook is a workshop for building UI components in isolation. You render each component in every state outside your app, document it, and test it visually — all in a dedicated browser sandbox.

Why Use It with Vue?

Developing a button or modal inside a deep page is slow. Storybook lets you see a component on its own, flip its props live, and catch visual regressions before they reach the app.

Installing with One Command

Run the init command in your existing Vue 3 project. It detects Vite, installs dependencies, and scaffolds config and example stories.

// terminal
// npx storybook@latest init

What init Creates

The initializer adds a .storybook/ config folder, sample *.stories.* files, and npm scripts. It auto-detects the Vue 3 + Vite setup.

// .storybook/main.ts
// .storybook/preview.ts
// src/stories/*.stories.ts (examples)

The main.ts Config

.storybook/main.ts is the core config: where stories live, which addons load, and which framework to use. For Vue 3 + Vite the framework is @storybook/vue3-vite.

// .storybook/main.ts
import type { StorybookConfig } from "@storybook/vue3-vite"

const config: StorybookConfig = {
  stories: ["../src/**/*.stories.@(js|ts)"],
  addons: ["@storybook/addon-essentials"],
  framework: { name: "@storybook/vue3-vite", options: {} },
}
export default config

The stories Glob

The stories array tells Storybook where to find story files using glob patterns. Adjust it to match your folder layout.

stories: [
  "../src/**/*.stories.@(js|jsx|ts|tsx)",
]

The vue3-vite Framework

The framework package wires Storybook into your existing Vite config, so aliases, plugins, and CSS handling match your real app build.

framework: {
  name: "@storybook/vue3-vite",
  options: {},
}

The preview.ts File

.storybook/preview.ts configures global setup that applies to every story: global decorators, parameters, and importing global CSS.

// .storybook/preview.ts
import type { Preview } from "@storybook/vue3"
import "../src/assets/main.css"

const preview: Preview = {
  parameters: {
    controls: { matchers: { color: /color/i } },
  },
}
export default preview

Global Decorators and Plugins

If components need a router or Pinia, register them once in preview.ts via setup so every story has access — no per-story boilerplate.

// .storybook/preview.ts
import { setup } from "@storybook/vue3"
import { createPinia } from "pinia"

setup((app) => {
  app.use(createPinia())
})

Running the Dev Server

Start Storybook locally with the dev command. The convention is port 6006.

// terminal
// npm run storybook
// or directly:
// storybook dev -p 6006

Building a Static Storybook

For deployment, build a static site you can host anywhere. CI commonly publishes this for design review.

// terminal
// storybook build
// outputs to storybook-static/

Quick Check

Check your understanding of Storybook setup for Vue 3.

Recap

You set up Storybook for Vue 3:

  • Storybook builds and documents components in isolation.
  • npx storybook@latest init scaffolds config and examples.
  • .storybook/main.ts sets the stories glob, addons, and the @storybook/vue3-vite framework.
  • .storybook/preview.ts handles global setup (CSS, decorators, plugins like Pinia).
  • Run with storybook dev -p 6006; build a static site with storybook build.
Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “Setting Up Storybook for Vue 3” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “Setting Up Storybook for Vue 3”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.

What will I learn in “Setting Up Storybook for Vue 3”?

npx storybook@latest init, .storybook/config, main.js, stories directory, running. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Setting Up Storybook for Vue 3” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Setting Up Storybook for Vue 3
  2. Writing Component Stories
  3. Controls, Actions, and Args
  4. Storybook Addons and Accessibility Testing
← Back to Vue Academy