vite-plugin-storybook-nextjs 1.0.2--canary.11.e6fc610.0 → 1.0.2--canary.12.6dea25b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@ This is a Vite plugin that allows you to use Next.js features in Vite. It is the
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Next.js Integration**: Seamlessly integrate Next.js features into your Vite project.
|
|
8
|
-
- **Storybook Compatibility**: Acts as the foundation for `@storybook/nextjs-vite`, enabling you to use Storybook with Next.js in a Vite environment.
|
|
8
|
+
- **Storybook Compatibility**: Acts as the foundation for `@storybook/experimental-nextjs-vite`, enabling you to use Storybook with Next.js in a Vite environment.
|
|
9
9
|
- **Portable Stories**: Ideal for running portable stories in Vitest, ensuring your components are tested in an environment that closely mirrors production.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Install the plugin using your preferred package manager:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
npm install vite-plugin-storybook-nextjs
|
|
@@ -22,11 +22,11 @@ pnpm add vite-plugin-storybook-nextjs
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### Set up Vitest
|
|
26
26
|
|
|
27
|
-
To use the plugin, you need to set up Vitest in your project. You can do this by following the instructions in the [Vitest documentation](https://vitest.dev/guide/)
|
|
27
|
+
To use the plugin, you need to set up Vitest in your project. You can do this by following the instructions in the [Vitest documentation](https://vitest.dev/guide/).
|
|
28
28
|
|
|
29
|
-
### Add the plugin to your
|
|
29
|
+
### Add the plugin to your Vitest configuration
|
|
30
30
|
|
|
31
31
|
Add the plugin to your Vitest configuration file. This ensures that Vitest is aware of the Next.js features provided by the plugin.
|
|
32
32
|
|
|
@@ -46,9 +46,9 @@ export default defineConfig({
|
|
|
46
46
|
|
|
47
47
|
This plugin is necessary to run portable stories in Vitest, as it provides the necessary Next.js features to ensure that your components are tested in an environment that closely mirrors production.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
### Experimental @storybook/experimental-vitest-plugin
|
|
50
50
|
|
|
51
|
-
The experimental `@storybook/experimental-
|
|
51
|
+
The experimental `@storybook/experimental-vitest-plugin` can be used to automatically transform your stories at Vitest runtime to in-memory test files. This allows you to run your stories in a Vitest environment without needing to manually transform your stories. Please visit https://github.com/storybookjs/vitest-plugin for more information.
|
|
52
52
|
|
|
53
53
|
## Configuration Options
|
|
54
54
|
|
|
@@ -66,37 +66,51 @@ type VitePluginOptions = {
|
|
|
66
66
|
|
|
67
67
|
## Limitations and differences to the Webpack5-based integration of Next.js in Storybook
|
|
68
68
|
|
|
69
|
-
### next/font staticDir mapping obsolete
|
|
69
|
+
### `next/font` `staticDir` mapping obsolete
|
|
70
70
|
|
|
71
|
-
You don't need to map your custom font directory in Storybook's staticDir configuration. Vite will automatically serve the files in the public directory and provide assets during production
|
|
71
|
+
You don't need to map your custom font directory in Storybook's `staticDir` configuration. Instead, Vite will automatically serve the files in the `public` directory and provide assets during production builds.
|
|
72
72
|
|
|
73
73
|
### CSS/SASS
|
|
74
74
|
|
|
75
|
-
The `sassOptions` in `next.config.js` is not supported. Please use Vite's configuration options to configure the Sass compiler:
|
|
75
|
+
The `sassOptions` property in `next.config.js` is not supported. Please use Vite's configuration options to configure the Sass compiler:
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
css: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
preprocessorOptions: {
|
|
80
|
+
scss: {
|
|
81
|
+
quietDeps: true
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
84
|
},
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
### Next.js: Server Actions
|
|
88
88
|
|
|
89
|
-
When
|
|
89
|
+
When testing components that rely on Next.js Server Actions, you need to ensure that your story files are [set up to use the `jsdom` environment in Vitest](https://vitest.dev/config/#environment). This can be done in two ways:
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
91
|
+
1. To apply it to individual story files, add a special comment at the top of each file:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
// @vitest-environment jsdom
|
|
95
|
+
```
|
|
96
|
+
2. To apply it to all tests, adjust your Vitest configuration:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// vitest.config.ts
|
|
100
|
+
import { defineConfig } from "vite";
|
|
101
|
+
import nextjs from "vite-plugin-storybook-nextjs";
|
|
94
102
|
|
|
95
|
-
|
|
103
|
+
export default defineConfig({
|
|
104
|
+
plugins: [nextjs()],
|
|
105
|
+
vitest: {
|
|
106
|
+
environment: "jsdom", // 👈 Add this
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
96
110
|
|
|
97
111
|
## SWC Mode
|
|
98
112
|
|
|
99
|
-
Only Next.js in SWC mode is supported. If
|
|
113
|
+
Only [Next.js in SWC mode](https://nextjs.org/docs/architecture/nextjs-compiler) is supported. If your project was forced to opt out of Babel for some reason, you will very likely encounter issues with this plugin (e.g., emotion support in SWC is still lacking behind).
|
|
100
114
|
|
|
101
115
|
## License
|
|
102
116
|
|