vite-plugin-storybook-nextjs 1.0.2--canary.12.6dea25b.0 → 1.0.2--canary.8683acb.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 +20 -34
- package/dist/index.cjs +13 -0
- package/dist/index.js +13 -0
- package/dist/mocks/storybook.global.cjs +13 -0
- package/dist/mocks/storybook.global.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# vite-plugin-storybook-nextjs
|
|
2
2
|
|
|
3
|
-
This is a Vite plugin that allows you to use Next.js features in Vite. It is the basis for `@storybook/nextjs-vite` and should be used when running portable stories in Vitest.
|
|
3
|
+
This is a Vite plugin that allows you to use Next.js features in Vite. It is the basis for `@storybook/experimental-nextjs-vite` and should be used when running portable stories in Vitest.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ This is a Vite plugin that allows you to use Next.js features in Vite. It is the
|
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
To install the plugin, use your package manager of choice:
|
|
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
|
+
### Setup 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,7 +46,7 @@ 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
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
|
|
|
@@ -66,51 +66,37 @@ type VitePluginOptions = {
|
|
|
66
66
|
|
|
67
67
|
## Limitations and differences to the Webpack5-based integration of Next.js in Storybook
|
|
68
68
|
|
|
69
|
-
###
|
|
69
|
+
### next/font staticDir mapping obsolete
|
|
70
70
|
|
|
71
|
-
You don't need to map your custom font directory in Storybook's
|
|
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 build.
|
|
72
72
|
|
|
73
73
|
### CSS/SASS
|
|
74
74
|
|
|
75
|
-
The `sassOptions`
|
|
75
|
+
The `sassOptions` 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 using components that rely on Next.js Server Actions, there are some limitations to be aware of. Specifically, you need to ensure that your story files are set up to use the jsdom environment in Vitest for the case that your default Virtual DOM environment is set to happy-dom. This can be done by adding a special comment at the top of your story files:
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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";
|
|
91
|
+
```js
|
|
92
|
+
// @vitest-environment jsdom
|
|
93
|
+
```
|
|
102
94
|
|
|
103
|
-
|
|
104
|
-
plugins: [nextjs()],
|
|
105
|
-
vitest: {
|
|
106
|
-
environment: "jsdom", // 👈 Add this
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
```
|
|
95
|
+
This comment ensures that the components using Next.js Server Actions are properly handled in a jsdom environment, which is necessary for them to function correctly in Vitest.
|
|
110
96
|
|
|
111
97
|
## SWC Mode
|
|
112
98
|
|
|
113
|
-
Only
|
|
99
|
+
Only Next.js in SWC mode is supported. If you were 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).
|
|
114
100
|
|
|
115
101
|
## License
|
|
116
102
|
|
package/dist/index.cjs
CHANGED
|
@@ -878,15 +878,28 @@ var getAlias2 = (env) => ({
|
|
|
878
878
|
"next/headers": getEntryPoint2("headers", env),
|
|
879
879
|
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
880
880
|
"@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
|
|
881
|
+
"@storybook/experimental-nextjs-vite/headers.mock": getEntryPoint2(
|
|
882
|
+
"headers",
|
|
883
|
+
env
|
|
884
|
+
),
|
|
881
885
|
"next/navigation": getEntryPoint2("navigation", env),
|
|
882
886
|
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
883
887
|
"@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
|
|
888
|
+
"@storybook/experimental-nextjs-vite/navigation.mock": getEntryPoint2(
|
|
889
|
+
"navigation",
|
|
890
|
+
env
|
|
891
|
+
),
|
|
884
892
|
"next/router": getEntryPoint2("router", env),
|
|
885
893
|
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
886
894
|
"@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
|
|
895
|
+
"@storybook/experimental-nextjs-vite/router.mock": getEntryPoint2(
|
|
896
|
+
"router",
|
|
897
|
+
env
|
|
898
|
+
),
|
|
887
899
|
"next/cache": getEntryPoint2("cache", env),
|
|
888
900
|
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
889
901
|
"@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
902
|
+
"@storybook/experimental-nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
890
903
|
"server-only": getEntryPoint2("server-only", env),
|
|
891
904
|
"@opentelemetry/api": require4.resolve(
|
|
892
905
|
"next/dist/compiled/@opentelemetry/api"
|
package/dist/index.js
CHANGED
|
@@ -863,15 +863,28 @@ var getAlias2 = (env) => ({
|
|
|
863
863
|
"next/headers": getEntryPoint2("headers", env),
|
|
864
864
|
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
865
865
|
"@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
|
|
866
|
+
"@storybook/experimental-nextjs-vite/headers.mock": getEntryPoint2(
|
|
867
|
+
"headers",
|
|
868
|
+
env
|
|
869
|
+
),
|
|
866
870
|
"next/navigation": getEntryPoint2("navigation", env),
|
|
867
871
|
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
868
872
|
"@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
|
|
873
|
+
"@storybook/experimental-nextjs-vite/navigation.mock": getEntryPoint2(
|
|
874
|
+
"navigation",
|
|
875
|
+
env
|
|
876
|
+
),
|
|
869
877
|
"next/router": getEntryPoint2("router", env),
|
|
870
878
|
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
871
879
|
"@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
|
|
880
|
+
"@storybook/experimental-nextjs-vite/router.mock": getEntryPoint2(
|
|
881
|
+
"router",
|
|
882
|
+
env
|
|
883
|
+
),
|
|
872
884
|
"next/cache": getEntryPoint2("cache", env),
|
|
873
885
|
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
874
886
|
"@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
887
|
+
"@storybook/experimental-nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
875
888
|
"server-only": getEntryPoint2("server-only", env),
|
|
876
889
|
"@opentelemetry/api": require4.resolve(
|
|
877
890
|
"next/dist/compiled/@opentelemetry/api"
|
|
@@ -31,15 +31,28 @@ var getAlias2 = (env) => ({
|
|
|
31
31
|
"next/headers": getEntryPoint2("headers", env),
|
|
32
32
|
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
33
33
|
"@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
|
|
34
|
+
"@storybook/experimental-nextjs-vite/headers.mock": getEntryPoint2(
|
|
35
|
+
"headers",
|
|
36
|
+
env
|
|
37
|
+
),
|
|
34
38
|
"next/navigation": getEntryPoint2("navigation", env),
|
|
35
39
|
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
36
40
|
"@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
|
|
41
|
+
"@storybook/experimental-nextjs-vite/navigation.mock": getEntryPoint2(
|
|
42
|
+
"navigation",
|
|
43
|
+
env
|
|
44
|
+
),
|
|
37
45
|
"next/router": getEntryPoint2("router", env),
|
|
38
46
|
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
39
47
|
"@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
|
|
48
|
+
"@storybook/experimental-nextjs-vite/router.mock": getEntryPoint2(
|
|
49
|
+
"router",
|
|
50
|
+
env
|
|
51
|
+
),
|
|
40
52
|
"next/cache": getEntryPoint2("cache", env),
|
|
41
53
|
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
42
54
|
"@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
55
|
+
"@storybook/experimental-nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
43
56
|
"server-only": getEntryPoint2("server-only", env),
|
|
44
57
|
"@opentelemetry/api": require2.resolve(
|
|
45
58
|
"next/dist/compiled/@opentelemetry/api"
|
|
@@ -24,15 +24,28 @@ var getAlias2 = (env) => ({
|
|
|
24
24
|
"next/headers": getEntryPoint2("headers", env),
|
|
25
25
|
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
26
26
|
"@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
|
|
27
|
+
"@storybook/experimental-nextjs-vite/headers.mock": getEntryPoint2(
|
|
28
|
+
"headers",
|
|
29
|
+
env
|
|
30
|
+
),
|
|
27
31
|
"next/navigation": getEntryPoint2("navigation", env),
|
|
28
32
|
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
29
33
|
"@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
|
|
34
|
+
"@storybook/experimental-nextjs-vite/navigation.mock": getEntryPoint2(
|
|
35
|
+
"navigation",
|
|
36
|
+
env
|
|
37
|
+
),
|
|
30
38
|
"next/router": getEntryPoint2("router", env),
|
|
31
39
|
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
32
40
|
"@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
|
|
41
|
+
"@storybook/experimental-nextjs-vite/router.mock": getEntryPoint2(
|
|
42
|
+
"router",
|
|
43
|
+
env
|
|
44
|
+
),
|
|
33
45
|
"next/cache": getEntryPoint2("cache", env),
|
|
34
46
|
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
35
47
|
"@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
48
|
+
"@storybook/experimental-nextjs-vite/cache.mock": getEntryPoint2("cache", env),
|
|
36
49
|
"server-only": getEntryPoint2("server-only", env),
|
|
37
50
|
"@opentelemetry/api": require2.resolve(
|
|
38
51
|
"next/dist/compiled/@opentelemetry/api"
|