vite-plugin-storybook-nextjs 3.0.3 → 3.1.0--canary.69.ab50e19.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 CHANGED
@@ -62,15 +62,77 @@ export default defineConfig({
62
62
  You can configure the plugin using the following options:
63
63
 
64
64
  ```ts
65
+ type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null
66
+
65
67
  type VitePluginOptions = {
66
68
  /**
67
69
  * Provide the path to your Next.js project directory
68
70
  * @default process.cwd()
69
71
  */
70
- dir?: string;
71
- };
72
+ dir?: string
73
+ /**
74
+ * Control which image files are handled by the Next Image plugin
75
+ * (Rollup-style include/exclude patterns)
76
+ */
77
+ image?: {
78
+ include?: FilterPattern
79
+ exclude?: FilterPattern
80
+ }
81
+ }
72
82
  ```
73
83
 
84
+ ### FAQ: Including/Excluding images
85
+
86
+ When you also use the SVG-to-React plugin [vite-plugin-svgr](https://github.com/pd4d10/vite-plugin-svgr), you may want SVGs imported with the `?react` query to be handled by SVGR, while all other images (including plain SVGs) are handled by this plugin's Next Image processing. By default, the plugin already handles the `**/*.svg?react` case. But if you have custom configuration, you must configure the filters yourself.
87
+
88
+ You can achieve this by adding include/exclude patterns as plugin options. The patterns follow Rollup's FilterPattern semantics (micromatch).
89
+
90
+ #### 1. When using Storybook
91
+
92
+ ```ts
93
+ // .storybook/main.ts
94
+ export default {
95
+ framework: {
96
+ name: '@storybook/nextjs-vite',
97
+ options: {
98
+ image: {
99
+ // Default image glob patterns are already applied; this is optional
100
+ // include: ['**/*.{png,jpg,jpeg,gif,webp,avif,ico,bmp,svg}'],
101
+ // Ensure SVGR takes precedence for React components from SVGs
102
+ exclude: ['**/*.svg?icon'],
103
+ },
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ #### 2. When not using Storybook
110
+
111
+ ```ts
112
+ // vite.config.ts or vitest.config.ts
113
+ import { defineConfig } from 'vite'
114
+ import nextjs from 'vite-plugin-storybook-nextjs'
115
+ import svgr from 'vite-plugin-svgr'
116
+
117
+ export default defineConfig({
118
+ plugins: [
119
+ svgr({ include: '**/*.svg?react' }),
120
+ nextjs({
121
+ image: {
122
+ // Default image glob patterns are already applied; this is optional
123
+ // include: ['**/*.{png,jpg,jpeg,gif,webp,avif,ico,bmp,svg}'],
124
+ // Ensure SVGR takes precedence for React components from SVGs
125
+ exclude: ['**/*.svg?react'],
126
+ },
127
+ }),
128
+ ],
129
+ })
130
+ ```
131
+
132
+ Notes:
133
+ - If you do not customize `image.include`, the plugin defaults to common image extensions.
134
+ - Excluding `**/*.svg?react` prevents collisions so that `import Icon from "./icon.svg?react"` is compiled by SVGR, while `import iconUrl from "./icon.svg"` is handled by Next Image.
135
+
74
136
  ## Usage with portable stories
75
137
 
76
138
  [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.