Setting Up Storybook for Vue 3
npx storybook@latest init, .storybook/config, main.js, stories directory, running.
Setting Up Storybook for Vue 3 is a free Vue Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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 initWhat 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 configThe 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 previewGlobal 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 6006Building 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 initscaffolds config and examples..storybook/main.tssets thestoriesglob, addons, and the@storybook/vue3-viteframework..storybook/preview.tshandles global setup (CSS, decorators, plugins like Pinia).- Run with
storybook dev -p 6006; build a static site withstorybook build.
Frequently asked questions
Is the “Setting Up Storybook for Vue 3” lesson free?
Yes — the full text of “Setting Up Storybook for Vue 3” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.
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; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
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
- Setting Up Storybook for Vue 3
- Writing Component Stories
- Controls, Actions, and Args
- Storybook Addons and Accessibility Testing