Manual Setup

@nuxtjs/storybook provides a clean and simple way to integrate Storybook with NuxtJS. If you want to config Storybook by yourself or do things that is beyond the scope of this module follow these steps.

Before starting, take a look at Storybook's official documentation about Configuration

User eject command

Using eject command is the easiest way to create and customize Storybook config.

Yarn
yarn nuxt storybook eject
NPM
npx nuxt storybook eject

After running eject command you'll see .storybook directory in your project's root dirctory.

Manual

Create storybook directory

In root directory of your project create .storybook directory. This directory will become your storybook's entry point.

Create main.js

Create a new file inside .storybook directory called main.js, This is where you can import your stories. A sample main.js files could be like this:

main.js
const { nuxifyStorybook } = require('../.nuxt-storybook/storybook/main.js')

module.exports = nuxifyStorybook({
  webpackFinal (config, options) {

    // extend config here
    
    return config
  },
  stories: [
    // Add your stories here
  ],
  addons: [
    // Add your addons here
  ]
})

Note that if you want to use Nuxt features in your storybook (like store or axios module and ...) you need to use nuxifyStorybook function in main.js.

Create preview.js

Create another file called preview.js inside .storybook directory and import Nuxt helpers in it.

preview.js
export * from '~~/.nuxt-storybook/storybook/preview.js'

Create middleware.js

Having this file is completely optional and you can skip this step if you don't use any server middleware in your project.

If you want to use middlewares inside the storybook, you need to create another file called middleware.js inside .storybook directory and import Nuxt helpers in it.

preview.js
module.exports = require('../.nuxt-storybook/storybook/middleware.js')

All done, just start storybook and make your changes.

Yarn
yarn nuxt-storybook
NPM
npx nuxt-storybook
Edit this page on GitHub Updated at Mon, Sep 11, 2023