Set up Storybook for Vue and Nuxt Projects

This guide will walk you through setting up Storybook for Vue and Nuxt projects in your Nx workspace.

Set up Storybook in your workspace

You first need to set up Storybook for your Nx workspace, if you haven't already. You can read the Storybook plugin overview guide to get started.

Generate Storybook Configuration for a Vue or Nuxt project

You can generate Storybook configuration for an individual Vue or Nuxt project by using the @nx/vue:storybook-configuration generator, like this:

โฏ

nx g @nx/vue:storybook-configuration project-name

Auto-generate Stories

The @nx/vue:storybook-configuration generator has the option to automatically generate *.stories.ts files for each component declared in the library.

1<some-folder>/ 2โ”œโ”€โ”€ MyComponent.vue 3โ””โ”€โ”€ MyComponent.stories.ts 4

If you add more components to your project, and want to generate stories for all your (new) components at any point, you can use the @nx/vue:stories generator:

โฏ

nx g @nx/vue:stories --project=<project-name>

Example

Let's take for a example a library in your workspace, under libs/feature/ui, called feature-ui. This library contains a component, called my-button.

The command to generate stories for that library would be:

โฏ

nx g @nx/vue:stories --project=feature-ui

and the result would be the following:

1<workspace name>/ 2โ”œโ”€โ”€ apps/ 3โ”œโ”€โ”€ libs/ 4โ”‚ โ”œโ”€โ”€ feature/ 5โ”‚ โ”‚ โ”œโ”€โ”€ ui/ 6| | | โ”œโ”€โ”€ .storybook/ 7| | | โ”œโ”€โ”€ src/ 8| | | | โ”œโ”€โ”€lib 9| | | | | โ”œโ”€โ”€my-button 10| | | | | | โ”œโ”€โ”€ MyButton.vue 11| | | | | | โ”œโ”€โ”€ MyButton.stories.ts 12| | | | | | โ””โ”€โ”€ etc... 13| | | | | โ””โ”€โ”€ etc... 14| | | โ”œโ”€โ”€ README.md 15| | | โ”œโ”€โ”€ tsconfig.json 16| | | โ””โ”€โ”€ etc... 17| | โ””โ”€โ”€ etc... 18| โ””โ”€โ”€ etc... 19โ”œโ”€โ”€ nx.json 20โ”œโ”€โ”€ package.json 21โ”œโ”€โ”€ README.md 22โ””โ”€โ”€ etc... 23

More Documentation

You can find all Storybook-related Nx topics here.

For more on using Storybook, see the official Storybook documentation.