You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can then get started [writing stories](/docs/get-started/whats-a-story/), [running tests](/docs/writing-tests/) and [documenting your components](/docs/writing-docs/). For more control over the installation process, refer to the [installation guide](/docs/install/).
17
+
You can then get started [writing stories](../whats-a-story.mdx), [running tests](../../writing-tests/index.mdx) and [documenting your components](../../writing-docs/index.mdx). For more control over the installation process, refer to the [installation guide](../install.mdx).
18
18
19
19
### Requirements
20
20
@@ -46,7 +46,7 @@ You will find the output in the configured `outputDir` (default is `dist/storybo
46
46
47
47
## Configure
48
48
49
-
To make the most out of Storybook in your Angular project, you can set up Compodoc integration and Storybook [decorators](/docs/writing-stories/decorators/) based on your project needs.
49
+
To make the most out of Storybook in your Angular project, you can set up Compodoc integration and Storybook [decorators](../../writing-stories/decorators.mdx) based on your project needs.
50
50
51
51
### Compodoc
52
52
@@ -122,7 +122,7 @@ export default preview;
122
122
123
123
### Application-wide providers
124
124
125
-
If your component relies on application-wide providers, like the ones defined by [`BrowserAnimationsModule`](https://angular.dev/api/platform-browser/animations/BrowserAnimationsModule) or any other modules that use the forRoot pattern to provide a [`ModuleWithProviders`](https://angular.dev/api/core/ModuleWithProviders), you can apply the `applicationConfig`[decorator](../../writing-stories/decorators.mdx) to all stories for that component. This will provide them with the [bootstrapApplication function](https://angular.io/guide/standalone-components#configuring-dependency-injection), used to bootstrap the component in Storybook.
125
+
If your component relies on application-wide providers, like the ones defined by [`BrowserAnimationsModule`](https://angular.dev/api/platform-browser/animations/BrowserAnimationsModule) or any other modules that use the forRoot pattern to provide a [`ModuleWithProviders`](https://angular.dev/api/core/ModuleWithProviders), you can apply the `applicationConfig`[decorator](../../writing-stories/decorators.mdx) to all stories for that component. This will provide them with the [bootstrapApplication function](https://angular.dev/api/platform-browser/bootstrapApplication), used to bootstrap the component in Storybook.
Copy file name to clipboardExpand all lines: docs/get-started/frameworks/nextjs-vite.mdx
+44-45Lines changed: 44 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,15 @@ sidebar:
6
6
title: Next.js (Vite)
7
7
---
8
8
9
-
Storybook for Next.js (Vite) is the **recommended**[framework](../../contribute/framework.mdx) for developing and testing UI components in isolation for [Next.js](https://nextjs.org/) applications. It uses [Vite](https://vitejs.dev/) for faster builds, better performance and [Storybook Testing](https://storybook.js.org/docs/writing-tests) support.
9
+
Storybook for Next.js (Vite) is the **recommended**[framework](../../contribute/framework.mdx) for developing and testing UI components in isolation for [Next.js](https://nextjs.org/) applications. It uses [Vite](https://vitejs.dev/) for faster builds, better performance and [Storybook Testing](../../writing-tests/index.mdx) support.
10
10
11
11
## Install
12
12
13
13
To install Storybook in an existing Next.js project, run this command in your project's root directory:
You can then get started [writing stories](/docs/get-started/whats-a-story/), [running tests](/docs/writing-tests/) and [documenting your components](/docs/writing-docs/). For more control over the installation process, refer to the [installation guide](/docs/install/).
18
-
17
+
You can then get started [writing stories](../whats-a-story.mdx), [running tests](../../writing-tests/index.mdx) and [documenting your components](../../writing-docs/index.mdx). For more control over the installation process, refer to the [installation guide](../install.mdx).
19
18
20
19
### Requirements
21
20
@@ -56,9 +55,6 @@ To build Storybook, run:
56
55
57
56
You will find the output in the configured `outputDir` (default is `storybook-static`).
58
57
59
-
60
-
61
-
62
58
## Configure
63
59
64
60
Storybook for Next.js with Vite supports many Next.js features including:
@@ -410,54 +406,60 @@ const preview: Preview = {
410
406
411
407
[`next/head`](https://nextjs.org/docs/pages/api-reference/components/head) is supported out of the box. You can use it in your stories like you would in your Next.js application. Please keep in mind, that the Head `children` are placed into the head element of the iframe that Storybook uses to render your stories.
412
408
413
-
### Styling
414
409
415
-
#### Sass/Scss
410
+
##Next.js styling
416
411
417
-
[Global Sass/Scss stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are supported without any additional configuration as well. Just import them into [`.storybook/preview.js|ts`](../../configure/index.mdx#configure-story-rendering)
412
+
###Sass/Scss
418
413
419
-
```js title=".storybook/preview.js|ts"
420
-
import'../styles/globals.scss';
421
-
```
414
+
[Global Sass/SCSS stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are also supported without any additional configuration. Just import them into [the preview config file](../../configure/index.mdx#configure-story-rendering).
422
415
423
-
This will automatically include any of your [custom Sass configurations](https://nextjs.org/docs/pages/building-your-application/styling/sass#customizing-sass-options) in your `next.config.js` file.
This will automatically include any of your [custom Sass configurations](https://nextjs.org/docs/pages/building-your-application/styling/sass#customizing-sass-options) in your Next.js config file.
Next.js lets you [customize PostCSS config](https://nextjs.org/docs/pages/building-your-application/configuring/post-css). Thus this framework will automatically handle your PostCSS config for you.
442
+
The built-in CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/pages/building-your-application/styling/css-in-js), and this framework supports that out of the box, too, with zero config.
This allows for cool things like zero-config Tailwind! (See [Next.js' example](https://github.com/vercel/next.js/tree/canary/packages/create-next-app/templates/default-tw))
452
+
Tailwind in Next.js [is supported via PostCSS](https://nextjs.org/docs/app/getting-started/css#tailwind-css). Storybook will automatically handle the PostCSS config for you, including any custom PostCSS configuration, so that you can import your global CSS directly into [the preview config file](../../configure/index.mdx#configure-story-rendering):
453
+
454
+
{/* prettier-ignore-start */}
455
+
456
+
<CodeSnippetspath="nextjs-styling-tailwind.md" />
457
+
458
+
{/* prettier-ignore-end */}
459
+
460
+
### PostCSS
461
+
462
+
Next.js lets you [customize PostCSS config](https://nextjs.org/docs/pages/building-your-application/configuring/post-css). Thus this framework will automatically handle your PostCSS config for you.
461
463
462
464
### Imports
463
465
#### Absolute imports
@@ -638,7 +640,7 @@ To enable this set the `experimentalRSC` feature flag in your `.storybook/main.j
638
640
639
641
Setting this flag automatically wraps your story in a [Suspense](https://react.dev/reference/react/Suspense) wrapper, which is able to render asynchronous components in NextJS's version of React.
640
642
641
-
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc`[parameter](https://storybook.js.org/docs/writing-stories/parameters) at the global/component/story level:
643
+
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc`[parameter](../../writing-stories/parameters.mdx) at the global/component/story level:
642
644
643
645
{/* prettier-ignore-start */}
644
646
@@ -654,7 +656,6 @@ In the future we will provide better mocking support in Storybook and support fo
654
656
655
657
## FAQ
656
658
657
-
658
659
### How do I migrate from the `nextjs` (Webpack 5) addon?
659
660
660
661
#### Automatic migration
@@ -673,7 +674,7 @@ This automigration tool performs the following actions:
673
674
674
675
<Calloutvariant="info">
675
676
676
-
If your project has custom Webpack configurations in `.storybook/main.js|ts` (via `webpackFinal`), you'll need to migrate those to Vite configuration (via `viteFinal`) after running this automigration. See the [Vite builder documentation](../builders/vite.mdx#migrating-from-webpack) for more information.
677
+
If your project has custom Webpack configurations in `.storybook/main.js|ts` (via `webpackFinal`), you'll need to migrate those to Vite configuration (via `viteFinal`) after running this automigration. See the [Vite builder documentation](../../builders/vite.mdx#migrating-from-webpack) for more information.
677
678
678
679
</Callout>
679
680
@@ -711,8 +712,6 @@ Finally, if you were using Storybook plugins to integrate with Next.js, those ar
711
712
712
713
{/* prettier-ignore-end */}
713
714
714
-
715
-
716
715
### Stories for pages/components which fetch data
717
716
718
717
Next.js pages can fetch data directly within server components in the `app` directory, which often include module imports that only run in a node environment. This does not (currently) work within Storybook, because if you import from a Next.js page file containing those node module imports in your stories, your Storybook's Vite build will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that pure component in your stories. Or, if that's not feasible for some reason, you can [configure Vite to handle those modules](https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude) in your Storybook's [`viteFinal` configuration](../../builders/vite.mdx#configuration).
Copy file name to clipboardExpand all lines: docs/get-started/frameworks/nextjs.mdx
+6-22Lines changed: 6 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,6 @@ sidebar:
8
8
9
9
Storybook for Next.js (Webpack) is a [framework](../../contribute/framework.mdx) that makes it easy to develop and test UI components in isolation for [Next.js](https://nextjs.org/) applications using [Webpack 5](https://webpack.js.org/).
10
10
11
-
12
11
<Calloutvariant="info">
13
12
14
13
**We recommend using [`@storybook/nextjs-vite`](./nextjs-vite.mdx)** for most Next.js projects. The Vite-based framework is faster, more modern, and offers better support for testing features.
@@ -27,8 +26,7 @@ To install Storybook in an existing Next.js project, run this command in your pr
27
26
28
27
The command will prompt you to choose between this framework and [`@storybook/nextjs-vite`](./nextjs-vite.mdx). We recommend the Vite-based framework ([learn why](./nextjs-vite.mdx#choose-between-vite-and-webpack)).
29
28
30
-
You can then get started [writing stories](/docs/get-started/whats-a-story/), [running tests](/docs/writing-tests/) and [documenting your components](/docs/writing-docs/). For more control over the installation process, refer to the [installation guide](/docs/install/).
31
-
29
+
You can then get started [writing stories](../whats-a-story.mdx), [running tests](../../writing-tests/index.mdx) and [documenting your components](../../writing-docs/index.mdx). For more control over the installation process, refer to the [installation guide](../install.mdx).
32
30
33
31
### Requirements
34
32
@@ -54,9 +52,6 @@ To build Storybook, run:
54
52
55
53
You will find the output in the configured `outputDir` (default is `storybook-static`).
56
54
57
-
58
-
59
-
60
55
## Configure
61
56
62
57
Storybook for Next.js with Vite supports many Next.js features including:
@@ -70,16 +65,6 @@ Storybook for Next.js with Vite supports many Next.js features including:
70
65
* 🎭 [Module mocking](#mocking-modules)
71
66
* ☁️ [React Server Component (experimental)](#react-server-components-rsc)
72
67
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
68
### Next.js's Image component
84
69
85
70
This framework allows you to use Next.js's [next/image](https://nextjs.org/docs/pages/api-reference/components/image) with no configuration.
@@ -420,7 +405,7 @@ const preview: Preview = {
420
405
421
406
### Sass/Scss
422
407
423
-
[Global Sass/Scss stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are supported without any additional configuration as well. Just import them into [the preview config file](../../configure/index.mdx#configure-story-rendering)
408
+
[Global Sass/SCSS stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are also supported without any additional configuration. Just import them into [the preview config file](../../configure/index.mdx#configure-story-rendering).
424
409
425
410
{/* prettier-ignore-start */}
426
411
@@ -448,15 +433,15 @@ This will automatically include any of your [custom Sass configurations](https:/
448
433
449
434
### Styled JSX
450
435
451
-
The builtin CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/pages/building-your-application/styling/css-in-js), and this framework supports that out of the box too, zero config.
436
+
The built-in CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/pages/building-your-application/styling/css-in-js), and this framework supports that out of the box, too, with zero config.
You can use your own babel config too. This is an example of how you can customize styled-jsx.
444
+
You can use your own Babel config, too. This is an example of how you can customize styled-jsx.
460
445
461
446
```jsonc
462
447
// .babelrc (or whatever config file you use)
@@ -476,8 +461,7 @@ You can use your own babel config too. This is an example of how you can customi
476
461
477
462
### Tailwind
478
463
479
-
Tailwind in Next.js [is supported via PostCSS](https://nextjs.org/docs/app/getting-started/css#tailwind-css). Storybook will automatically handle the PostCSS config for you, including any custom PostCSS configuration,
480
-
so you can just import your global CSS directly into [the preview config file](../../configure/index.mdx#configure-story-rendering):
464
+
Tailwind in Next.js [is supported via PostCSS](https://nextjs.org/docs/app/getting-started/css#tailwind-css). Storybook will automatically handle the PostCSS config for you, including any custom PostCSS configuration, so that you can import your global CSS directly into [the preview config file](../../configure/index.mdx#configure-story-rendering):
481
465
482
466
{/* prettier-ignore-start */}
483
467
@@ -674,7 +658,7 @@ To enable this set the `experimentalRSC` feature flag in your `.storybook/main.j
674
658
675
659
Setting this flag automatically wraps your story in a [Suspense](https://react.dev/reference/react/Suspense) wrapper, which is able to render asynchronous components in NextJS's version of React.
676
660
677
-
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc`[parameter](https://storybook.js.org/docs/writing-stories/parameters) at the global/component/story level:
661
+
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc`[parameter](../../writing-stories/parameters.mdx) at the global/component/story level:
0 commit comments