Set up Storybook for Vue and Nuxt Projects
This guide will walk you through setting upStorybook for Vue and Nuxt projects in your Nx workspace.
You first need to set up Storybook for your Nx workspace, if you haven't already. You can read theStorybook plugin overview guide to get started.
Generate Storybook Configuration for a Vue or Nuxt project
Section titled “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:
nxg@nx/vue:storybook-configurationproject-name
nxg@nx/nuxt:storybook-configurationmy-nuxt-app
Auto-generate Stories
Section titled “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.
<some-folder>/├── MyComponent.vue└── MyComponent.stories.ts
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:
nxg@nx/vue:stories--project=<project-name>
nxg@nx/nuxt:stories--project=<project-name>
Example library
Section titled “Example library”Let's take for a example a library in your workspace, underlibs/feature/ui
, calledfeature-ui
. This library contains a component, calledmy-button
.
The command to generate stories for that library would be:
nxg@nx/vue:stories--project=feature-ui
and the result would be the following:
Directoryworkspacename/
Directoryapps/
- …
Directorylibs/
Directoryfeature/
Directoryui/
Directory.storybook/
- …
Directorysrc/
Directorylib/
Directorymy-button/
- MyButton.vue
- MyButton.stories.ts
- etc...
- etc...
- README.md
- tsconfig.json
- etc...
- etc...
- nx.json
- package.json
- README.md
- etc...
More Documentation
Section titled “More Documentation”You can find all Storybook-related Nx topicshere.
For more on using Storybook, see theofficial Storybook documentation.