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 workspaceYou 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>
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.