Storybook framework

Configuration

Configure Storybook with the @storybook-vue/nuxt framework.

Storybook reads its configuration from .storybook/main.ts and .storybook/preview.ts. Set @storybook-vue/nuxt as the framework of main.ts: it loads your Nuxt app into Storybook. You can learn more about the Storybook configuration.

CSF Factories

CSF Factories are the recommended way to write the configuration and the stories. Import defineMain from @storybook-vue/nuxt/node and definePreview from @storybook-vue/nuxt: the Nuxt preview is added to your addons, and parameters.nuxt is typed in the preview, metas and stories. Hover the code below to see the types.

import { 
defineMain
} from '@storybook-vue/nuxt/node'
export default
defineMain
({
stories
: ['../components/**/*.stories.ts'],
addons
: ['@storybook/addon-docs'],
framework
: '@storybook-vue/nuxt',
})
With definePreview, Storybook only loads the preview annotations listed in addons, so add the addons whose preview you use (such as addonDocs()) there as well as in main.ts.

If your stories use CSF3, Storybook's codemod moves the configuration and the stories to CSF Factories:

npx storybook automigrate csf-factories

CSF3 stories keep working: type them with the Meta and StoryObj types exported by @storybook-vue/nuxt.

Framework options

Pass options to the framework with its object form:

.storybook/main.ts
import { 
defineMain
} from '@storybook-vue/nuxt/node'
export default
defineMain
({
stories
: ['../components/**/*.stories.ts'],
framework
: {
name
: '@storybook-vue/nuxt',
options
: {
docgen
: 'vue-component-meta',
}, }, })

Vite config

The framework merges the Vite config of your Nuxt app into the one of Storybook. You can modify the configuration with Storybook viteFinal preset, which runs after the Nuxt config is applied:

.storybook/main.ts
import { 
defineMain
} from '@storybook-vue/nuxt/node'
export default
defineMain
({
framework
: '@storybook-vue/nuxt',
stories
: ['../components/**/*.stories.ts'],
viteFinal
: (
config
) => ({
...
config
,
optimizeDeps
: {
...
config
.
optimizeDeps
,
include
: [...(
config
.
optimizeDeps
?.
include
?? []), 'my-cjs-dependency'],
}, }), })

Vite dependency discovery is disabled (optimizeDeps.noDiscovery), so add the dependencies that need pre-bundling to optimizeDeps.include.