vite-plugin-storybook-nextjs 0.0.15 → 1.0.0--canary.9.b462d2b.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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Kitiho <https://github.com/kitiho>
3
+ Copyright (c) 2024 Storybook <https://github.com/storybookjs>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,3 +1,99 @@
1
1
  # vite-plugin-storybook-nextjs
2
2
 
3
- This is a Vite plugin that allows you to use Next.js features in Vite. The plugin is still in early development and is not yet ready for production use.
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.
4
+
5
+ ## Features
6
+
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.
9
+ - **Portable Stories**: Ideal for running portable stories in Vitest, ensuring your components are tested in an environment that closely mirrors production.
10
+
11
+ ## Installation
12
+
13
+ To install the plugin, use your package manager of choice:
14
+
15
+ ```sh
16
+ npm install vite-plugin-storybook-nextjs
17
+ # or
18
+ yarn add vite-plugin-storybook-nextjs
19
+ # or
20
+ pnpm add vite-plugin-storybook-nextjs
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Setup Vitest
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/)
28
+
29
+ ### Add the plugin to your vitest configuration
30
+
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
+
33
+ ```ts
34
+ // vitest.config.ts
35
+ import { defineConfig } from "vite";
36
+ import nextjs from "vite-plugin-storybook-nextjs";
37
+
38
+ export default defineConfig({
39
+ plugins: [nextjs()],
40
+ });
41
+ ```
42
+
43
+ ### Usage with portable stories
44
+
45
+ [Portable stories](https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest) are Storybook stories which can be used in external environments, such as Vitest.
46
+
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
+
49
+ #### Experimental @storybook/experimental-vitest-plugin
50
+
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
+
53
+ ## Configuration Options
54
+
55
+ You can configure the plugin using the following options:
56
+
57
+ ```ts
58
+ type VitePluginOptions = {
59
+ /**
60
+ * Provide the path to your Next.js project directory
61
+ * @default process.cwd()
62
+ */
63
+ dir?: string;
64
+ };
65
+ ```
66
+
67
+ ## Limitations and differences to the Webpack5-based integration of Next.js in Storybook
68
+
69
+ ### next/font staticDir mapping obsolete
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 build.
72
+
73
+ ### CSS/SASS
74
+
75
+ The `sassOptions` in `next.config.js` is not supported. Please use Vite's configuration options to configure the Sass compiler:
76
+
77
+ ```js
78
+ css: {
79
+ preprocessorOptions: {
80
+ scss: {
81
+ quietDeps: true
82
+ },
83
+ }
84
+ },
85
+ ```
86
+
87
+ ### Next.js: Server Actions
88
+
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
+
91
+ ```js
92
+ // @vitest-environment jsdom
93
+ ```
94
+
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.
96
+
97
+ ## License
98
+
99
+ This project is licensed under the MIT License.
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "width" | "height" | "loading" | "alt"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}` | undefined;
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "width" | "height" | "loading" | "alt"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}` | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "0.0.15",
3
+ "version": "1.0.0--canary.9.b462d2b.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",