This PR removes the `/nx-api` pages from `nx-dev`. They are already redirected from `/nx-api` to either `/technologies` or `/reference/core-api` URLs. e.g. `/nx-api/nx` goes to `/reference/core-api/nx` and `/nx-api/react` goes to `/technologies/react/api` **Changes**: - Remove old `nx-api.json` from being generated in `scripts/documentation/generators/generate-manifests.ts` -- this was used to generate the sitemap - Remove `pages/nx-api` from Next.js app since we don't need them - Remove workaround from link checker `scripts/documentation/internal-link-checker.ts` -- the angular rspack/rsbuild and other workarounds are gone now that they are proper docs in `map.json` - Update Powerpack/Remote Cache reference docs to exclude API documents (since they are duplicated in the Intro page) -- `nx-dev/models-document/src/lib/mappings.ts` - All content in `docs` have been updated with new URL structure **Note:** Redirects are already handled, and Claude Code was used to verify the updated `docs/` URLs (see report below). The twelve 404s links were updated by hand. ## Verification Report https://gist.github.com/jaysoo/c7863fe7e091cb77929d1976165c357a
8.7 KiB
| title | description |
|---|---|
| Nx Storybook Plugin Overview | This is an overview page for the Storybook plugin in Nx. It explains what Storybook is and how to set it up in your Nx workspace. |
Storybook is a development environment for UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components.
This guide will briefly walk you through using Storybook within an Nx workspace.
Setting Up Storybook
Installation
{% callout type="note" title="Keep Nx Package Versions In Sync" %}
Make sure to install the @nx/storybook version that matches the version of nx in your repository. If the version numbers get out of sync, you can encounter some difficult to debug errors. You can fix Nx version mismatches with this recipe.
{% /callout %}
In any Nx workspace, you can install @nx/storybook by running the following command:
nx add @nx/storybook
This will install the correct version of @nx/storybook.
How @nx/storybook Infers Tasks
The @nx/storybook plugin will create a task for any project that has a Storybook configuration file present. Any of the following files will be recognized as a Storybook configuration file:
.storybook/main.js.storybook/main.ts.storybook/main.cjs.storybook/main.cts.storybook/main.mjs.storybook/main.mts
View Inferred Tasks
To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project --web in the command line.
@nx/storybook Configuration
The @nx/storybook/plugin is configured in the plugins array in nx.json.
{
"plugins": [
{
"plugin": "@nx/storybook/plugin",
"options": {
"buildStorybookTargetName": "build-storybook",
"serveStorybookTargetName": "storybook",
"testStorybookTargetName": "test-storybook",
"staticStorybookTargetName": "static-storybook"
}
}
]
}
The builtStorybookTargetName, serveStorybookTargetName, testStorybookTargetName and staticStorybookTargetName options control the names of the inferred Storybook tasks. The default names are build-storybook, storybook, test-storybook and static-storybook.
Using Storybook
Generating Storybook Configuration
You can generate Storybook configuration for an individual project with this command:
nx g @nx/storybook:configuration project-name
or
{% tabs %} {% tab label="Angular" %}
nx g @nx/angular:storybook-configuration my-angular-project
{% /tab %} {% tab label="React" %}
nx g @nx/react:storybook-configuration my-react-project
{% /tab %} {% tab label="Vue" %}
nx g @nx/vue:storybook-configuration my-vue-project
{% /tab %} {% tab label="React Native" %}
nx g @nx/react-native:storybook-configuration my-react-native-project
{% /tab %} {% /tabs %}
These framework-specific generators will also generate stories and interaction tests for you.
If you are NOT using a framework-specific generator (for Angular, React, React Native, Vue), in the field uiFramework you must choose one of the following Storybook frameworks:
@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
Choosing one of these frameworks will have the following effects on your workspace:
-
Nx will install all the required Storybook packages that go with it.
-
Nx will generate a project-level
.storybookfolder (located underlibs/your-project/.storybookorapps/your-project/.storybook) containing the essential configuration files for Storybook. -
Nx will create new
targetsin your project'sproject.json, calledstorybook,test-storybookandbuild-storybook, containing all the necessary configuration to serve, test and build Storybook.
Make sure to use the framework-specific generators if your project is using Angular, React, Next.js, Vue, Nuxt, or React Native: @nx/angular:storybook-configuration, @nx/react:storybook-configuration, @nx/react-native:storybook-configuration, @nx/vue:storybook-configuration as shown above.
Running Storybook
Serve Storybook using this command:
nx run project-name:storybook
or
nx storybook project-name
Building Storybook
Build Storybook using this command:
nx run project-name:build-storybook
or
nx build-storybook project-name
Testing Storybook
With the Storybook server running, you can test Storybook (run all the interaction tests) using this command:
nx run project-name:test-storybook
or
nx test-storybook project-name
Anatomy of the Storybook setup
When running the Nx Storybook generator, it'll configure the Nx workspace to be able to run Storybook seamlessly. It'll create a project specific Storybook configuration.
The project-specific Storybook configuration is pretty much similar to what you would have for a non-Nx setup of Storybook. There's a .storybook folder within the project root folder.
<project root>/
├── .storybook/
│ ├── main.ts
│ └── preview.ts
├── src/
├── README.md
├── tsconfig.json
├── tsconfig.storybook.json
└── etc...
Using Addons
To register a Storybook addon for all Storybook instances in your workspace:
- In your project's
.storybook/main.tsfile, in theaddonsarray of themodule.exportsobject, add the new addon:
import type { StorybookConfig } from '@storybook/react-vite';
const config: StorybookConfig = {
...
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions', ...],
...
};
export default config;
-
If a decorator is required, in each project's
<project-path>/.storybook/preview.ts, you can export an array calleddecorators.import someDecorator from 'some-storybook-addon'; export const decorators = [someDecorator];
Setting up documentation
To set up documentation, you can use Storybook Autodocs. For Angular, you can use compodoc to infer argTypes. You can read more about argTypes in the official Storybook argTypes documentation.
You can read more about how to best set up documentation using Storybook for your project in the official Storybook documentation.
More Documentation
You can find dedicated information for React and Angular:
- Set up Storybook for Angular Projects
- Set up Storybook for React Projects
- Set up Storybook for Vue Projects
You can find all Storybook-related Nx documentation in the Storybook recipes section.
For more on using Storybook, see the official Storybook documentation.
Migration Scenarios
Here's more information on common migration scenarios for Storybook with Nx. For Storybook specific migrations that are not automatically handled by Nx please refer to the official Storybook page