Getting Started
Introduction
Nuxt Storybook is made of two packages, a Nuxt module and a Storybook framework.
Nuxt Storybook brings your Nuxt app into Storybook: stories render your components with the plugins, auto-imports, components and runtime config of your app. It is made of two packages, which do different jobs.
@storybook-vue/nuxt | @nuxtjs/storybook | |
|---|---|---|
| Kind | Storybook framework | Nuxt module |
| Configured in | .storybook/main.ts and .storybook/preview.ts | nuxt.config.ts |
| Used by | storybook dev, storybook build and nuxt dev | nuxt dev only |
| Required | Yes | No |
The Storybook framework
@storybook-vue/nuxt is the Storybook framework for Nuxt. You set it as the framework of .storybook/main.ts, and it makes your stories Nuxt-aware:
- It loads your Nuxt config, so stories get the Vite config, plugins, CSS, auto-imports and components of your app.
- Each story renders in its own Nuxt app, which you configure with
parameters.nuxt. - It mocks auto-imports, components and server endpoints in stories with
mockNuxtImport,mockComponentandregisterEndpoint. - It exports
defineMain(from@storybook-vue/nuxt/node) anddefinePreview, to write your configuration with CSF Factories.
The framework works on its own: storybook dev and storybook build only need it.
The Nuxt module
@nuxtjs/storybook is the Nuxt module that makes Storybook available through your Nuxt server.
Add it to the modules of nuxt.config.ts to:
- Serve Storybook from
nuxt dev, on the same host and port as your app, under/_storybook/. - Open Storybook in a Nuxt DevTools tab.
- Include
.storybook/in the TypeScript config Nuxt generates.
It has a few options, such as the route Storybook is served on. The module depends on the framework, and does nothing during nuxt build or storybook build.
Which one do I need?
- Storybook with Nuxt: the framework. Setup installs it with Storybook.
- Storybook in
nuxt devand the Nuxt DevTools: the module as well.
Your project imports
@storybook-vue/nuxt in .storybook/ and in your stories, so install it next to @nuxtjs/storybook even when you use the module.