vite-plugin-storybook-nextjs 3.0.4--canary.5f06d44.0 → 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 +23 -2
- package/dist/index.cjs +9 -7
- package/dist/index.js +9 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,9 +83,30 @@ type VitePluginOptions = {
|
|
|
83
83
|
|
|
84
84
|
### FAQ: Including/Excluding images
|
|
85
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.
|
|
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
87
|
|
|
88
|
-
You can achieve this by
|
|
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
|
|
89
110
|
|
|
90
111
|
```ts
|
|
91
112
|
// vite.config.ts or vitest.config.ts
|
package/dist/index.cjs
CHANGED
|
@@ -4719,11 +4719,11 @@ var getAlias = (env) => ({
|
|
|
4719
4719
|
});
|
|
4720
4720
|
|
|
4721
4721
|
// src/plugins/next-image/plugin.ts
|
|
4722
|
-
var
|
|
4722
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
4723
4723
|
var warnOnce = (message) => {
|
|
4724
|
-
if (!
|
|
4724
|
+
if (!warnedMessages.has(message)) {
|
|
4725
4725
|
console.warn(`[vite-plugin-storybook-nextjs] ${message}`);
|
|
4726
|
-
|
|
4726
|
+
warnedMessages.add(message);
|
|
4727
4727
|
}
|
|
4728
4728
|
};
|
|
4729
4729
|
var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
|
|
@@ -4747,13 +4747,15 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
|
|
|
4747
4747
|
return {
|
|
4748
4748
|
name: "vite-plugin-storybook-nextjs-image",
|
|
4749
4749
|
enforce: "pre",
|
|
4750
|
+
async configResolved(config) {
|
|
4751
|
+
hasVitePluginSvgr = !!config.plugins?.some(
|
|
4752
|
+
(plugin) => plugin && typeof plugin === "object" && "name" in plugin && (plugin.name === "vite-plugin-svgr" || plugin.name.includes("svgr"))
|
|
4753
|
+
);
|
|
4754
|
+
},
|
|
4750
4755
|
async config(config, env) {
|
|
4751
4756
|
if (config.test?.browser?.enabled === true) {
|
|
4752
4757
|
isBrowser = true;
|
|
4753
4758
|
}
|
|
4754
|
-
hasVitePluginSvgr = !!config.plugins?.some(
|
|
4755
|
-
(plugin) => plugin && typeof plugin === "object" && "name" in plugin && (plugin.name === "vite-plugin-svgr" || plugin.name.includes("svgr"))
|
|
4756
|
-
);
|
|
4757
4759
|
return {
|
|
4758
4760
|
resolve: {
|
|
4759
4761
|
alias: getAlias(isBrowser ? "browser" : "node")
|
|
@@ -4769,7 +4771,7 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
|
|
|
4769
4771
|
if (isSvg && hasVitePluginSvgr && queryA === "react") {
|
|
4770
4772
|
return null;
|
|
4771
4773
|
}
|
|
4772
|
-
if (isSvg && hasVitePluginSvgr && !options.includeFiles && !options.excludeFiles) {
|
|
4774
|
+
if (isSvg && hasVitePluginSvgr && !options.includeFiles && !options.excludeFiles && queryA !== void 0) {
|
|
4773
4775
|
warnOnce(
|
|
4774
4776
|
tsDedent.dedent`Detected vite-plugin-svgr but you are not passing image include or exclude patterns to the nextjs-vite plugin. This may cause a conflict between the two plugins and issues with SVG files.
|
|
4775
4777
|
|
package/dist/index.js
CHANGED
|
@@ -4686,11 +4686,11 @@ var getAlias = (env) => ({
|
|
|
4686
4686
|
});
|
|
4687
4687
|
|
|
4688
4688
|
// src/plugins/next-image/plugin.ts
|
|
4689
|
-
var
|
|
4689
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
4690
4690
|
var warnOnce = (message) => {
|
|
4691
|
-
if (!
|
|
4691
|
+
if (!warnedMessages.has(message)) {
|
|
4692
4692
|
console.warn(`[vite-plugin-storybook-nextjs] ${message}`);
|
|
4693
|
-
|
|
4693
|
+
warnedMessages.add(message);
|
|
4694
4694
|
}
|
|
4695
4695
|
};
|
|
4696
4696
|
var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
|
|
@@ -4714,13 +4714,15 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
|
|
|
4714
4714
|
return {
|
|
4715
4715
|
name: "vite-plugin-storybook-nextjs-image",
|
|
4716
4716
|
enforce: "pre",
|
|
4717
|
+
async configResolved(config) {
|
|
4718
|
+
hasVitePluginSvgr = !!config.plugins?.some(
|
|
4719
|
+
(plugin) => plugin && typeof plugin === "object" && "name" in plugin && (plugin.name === "vite-plugin-svgr" || plugin.name.includes("svgr"))
|
|
4720
|
+
);
|
|
4721
|
+
},
|
|
4717
4722
|
async config(config, env) {
|
|
4718
4723
|
if (config.test?.browser?.enabled === true) {
|
|
4719
4724
|
isBrowser = true;
|
|
4720
4725
|
}
|
|
4721
|
-
hasVitePluginSvgr = !!config.plugins?.some(
|
|
4722
|
-
(plugin) => plugin && typeof plugin === "object" && "name" in plugin && (plugin.name === "vite-plugin-svgr" || plugin.name.includes("svgr"))
|
|
4723
|
-
);
|
|
4724
4726
|
return {
|
|
4725
4727
|
resolve: {
|
|
4726
4728
|
alias: getAlias(isBrowser ? "browser" : "node")
|
|
@@ -4736,7 +4738,7 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
|
|
|
4736
4738
|
if (isSvg && hasVitePluginSvgr && queryA === "react") {
|
|
4737
4739
|
return null;
|
|
4738
4740
|
}
|
|
4739
|
-
if (isSvg && hasVitePluginSvgr && !options.includeFiles && !options.excludeFiles) {
|
|
4741
|
+
if (isSvg && hasVitePluginSvgr && !options.includeFiles && !options.excludeFiles && queryA !== void 0) {
|
|
4740
4742
|
warnOnce(
|
|
4741
4743
|
dedent`Detected vite-plugin-svgr but you are not passing image include or exclude patterns to the nextjs-vite plugin. This may cause a conflict between the two plugins and issues with SVG files.
|
|
4742
4744
|
|