@nrwl/storybook:configuration

Add Storybook configuration to a UI library or an application.


title: Storybook configuration generator examples description: This page contains examples for the @nrwl/storybook:configuration generator.


This is a framework-agnostic generator for setting up Storybook configuration for a project.

nx g @nrwl/storybook:configuration

When running this generator, you will be prompted to provide the following:

  • The name of the project you want to generate the configuration for.
  • The uiFramework you want to use. Supported values are: "@storybook/angular", "@storybook/react", "@storybook/react-native", "@storybook/html", "@storybook/web-components", "@storybook/vue", "@storybook/vue3" and "@storybook/svelte".
  • Whether you want to configureCypress. If you choose yes, a Cypress e2e app will be created (or configured) to run against the project's Storybook instance.
  • Whether you want to configureTestRunner. If you choose yes, a test-storybook target will be generated in your project's project.json, with a command to invoke the Storybook test-runner.

You must provide a name and a uiFramework for the generator to work.

You can read more about how this generator works, in the Storybook package overview page.

If you are using Angular, React, React Native or Next.js in your project, it's best to use the framework specific generator:

Examples

Generate Storybook configuration using TypeScript

nx g @nrwl/storybook:configuration ui --uiFramework=@storybook/web-components --tsConfiguration=true

This will generate a Storybook configuration for the ui project using TypeScript for the Storybook configuration files (the files inside the .storybook directory).

Generate Storybook configuration for Storybook version 7

nx g @nrwl/storybook:configuration ui --uiFramework=@storybook/react --storybook7betaConfiguration=true

OR

nx g @nrwl/storybook:configuration ui --storybook7UiFramework=@storybook/react-vite --storybook7betaConfiguration=true

This will generate a Storybook configuration for the ui project using Storybook version 7. It will install the Storybook version 7 dependencies and configure the Storybook configuration files (the files inside the .storybook directory) to use Storybook version 7. You can read more about Storybook 7 Nx support in the Storybook 7 setup guide.

Usage

nx generate configuration ...

By default, Nx will search for configuration in the default collection provisioned in workspace.json.

You can specify the collection explicitly as follows:

nx g @nrwl/storybook:configuration ...

Show what will be generated without writing to disk:

nx g configuration ... --dry-run

Options

name

Required
string

Project for which to generate Storybook configuration.

bundler

string
Default: webpack
Accepted values: vite, webpack

The Storybook builder to use.

configureCypress

boolean

Run the cypress-configure generator.

tsConfiguration

boolean
Default: false

Configure your project with TypeScript. Generate main.ts and preview.ts files, instead of main.js and preview.js.

uiFramework

string
Accepted values: @storybook/angular, @storybook/react, @storybook/react-native, @storybook/html, @storybook/web-components, @storybook/vue, @storybook/vue3, @storybook/svelte

Storybook UI Framework to use.

cypressDirectory

string

A directory where the Cypress project will be placed. Added at root by default.

configureTestRunner

boolean

Add a Storybook Test-Runner target.

js

boolean
Default: false

Generate JavaScript story files rather than TypeScript story files.

linter

string
Default: eslint
Accepted values: eslint, none

The tool to use for running lint checks.

storybook7betaConfiguration

Hidden
boolean
Default: false

Configure your workspace to use Storybook 7, even though Storybook v7 is still in beta.

storybook7UiFramework

Hidden
string
Accepted values: @storybook/angular, @storybook/html-webpack5, @storybook/nextjs, @storybook/preact-webpack5, @storybook/react-webpack5, @storybook/react-vite, @storybook/server-webpack5, @storybook/svelte-webpack5, @storybook/svelte-vite, @storybook/sveltekit, @storybook/vue-webpack5, @storybook/vue-vite, @storybook/vue3-webpack5, @storybook/vue3-vite, @storybook/web-components-webpack5, @storybook/web-components-vite

Storybook UI Framework to use, for Storybook version 7.

standaloneConfig

Deprecated
boolean
Default: true

Split the project configuration into <projectRoot>/project.json rather than including it inside workspace.json.

Nx only supports standaloneConfig