From 6ec50cfbf1ee5e53e693391d3e34050a68e30b46 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 5 Nov 2025 16:13:17 +0100 Subject: [PATCH] Nextjs Vite: Update internal plugin to support svgr use cases --- code/frameworks/nextjs-vite/package.json | 2 +- code/frameworks/nextjs-vite/src/preset.ts | 10 ++++++++-- code/frameworks/nextjs-vite/src/types.ts | 4 ++++ code/yarn.lock | 10 +++++----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/code/frameworks/nextjs-vite/package.json b/code/frameworks/nextjs-vite/package.json index e93fca798bc6..ad8f168917dc 100644 --- a/code/frameworks/nextjs-vite/package.json +++ b/code/frameworks/nextjs-vite/package.json @@ -83,7 +83,7 @@ "@storybook/react": "workspace:*", "@storybook/react-vite": "workspace:*", "styled-jsx": "5.1.6", - "vite-plugin-storybook-nextjs": "^3.0.1" + "vite-plugin-storybook-nextjs": "^3.1.0" }, "devDependencies": { "@types/node": "^22.0.0", diff --git a/code/frameworks/nextjs-vite/src/preset.ts b/code/frameworks/nextjs-vite/src/preset.ts index cc1ed65d4b65..e99f379437a5 100644 --- a/code/frameworks/nextjs-vite/src/preset.ts +++ b/code/frameworks/nextjs-vite/src/preset.ts @@ -68,10 +68,16 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, option await normalizePostCssConfig(searchPath); } - const { nextConfigPath } = await options.presets.apply('frameworkOptions'); + const { nextConfigPath, image = {} } = + await options.presets.apply('frameworkOptions'); const nextDir = nextConfigPath ? dirname(nextConfigPath) : undefined; + const vitePluginOptions = { + image, + dir: nextDir, + }; + return { ...reactConfig, resolve: { @@ -83,6 +89,6 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, option 'styled-jsx/style.js': fileURLToPath(import.meta.resolve('styled-jsx/style')), }, }, - plugins: [...(reactConfig?.plugins ?? []), vitePluginStorybookNextjs({ dir: nextDir })], + plugins: [...(reactConfig?.plugins ?? []), vitePluginStorybookNextjs(vitePluginOptions)], }; }; diff --git a/code/frameworks/nextjs-vite/src/types.ts b/code/frameworks/nextjs-vite/src/types.ts index dcd8136fe5b9..cf5cb8e1a524 100644 --- a/code/frameworks/nextjs-vite/src/types.ts +++ b/code/frameworks/nextjs-vite/src/types.ts @@ -11,6 +11,10 @@ type BuilderName = CompatibleString<'@storybook/builder-vite'>; export type FrameworkOptions = { /** The path to the Next.js configuration file. */ nextConfigPath?: string; + image?: { + includeFiles?: string[]; + excludeFiles?: string[]; + }; builder?: BuilderOptions; }; diff --git a/code/yarn.lock b/code/yarn.lock index d324b60ab7ad..04808c099b33 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6553,7 +6553,7 @@ __metadata: semver: "npm:^7.3.5" styled-jsx: "npm:5.1.6" typescript: "npm:^5.8.3" - vite-plugin-storybook-nextjs: "npm:^3.0.1" + vite-plugin-storybook-nextjs: "npm:^3.1.0" peerDependencies: next: ^14.1.0 || ^15.0.0 || ^16.0.0 react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 @@ -26439,9 +26439,9 @@ __metadata: languageName: node linkType: hard -"vite-plugin-storybook-nextjs@npm:^3.0.1": - version: 3.0.1 - resolution: "vite-plugin-storybook-nextjs@npm:3.0.1" +"vite-plugin-storybook-nextjs@npm:^3.1.0": + version: 3.1.0 + resolution: "vite-plugin-storybook-nextjs@npm:3.1.0" dependencies: "@next/env": "npm:16.0.0" image-size: "npm:^2.0.0" @@ -26453,7 +26453,7 @@ __metadata: next: ^14.1.0 || ^15.0.0 || ^16.0.0 storybook: ^0.0.0-0 || ^9.0.0 || ^10.0.0 || ^10.0.0-0 vite: ^5.0.0 || ^6.0.0 || ^7.0.0 - checksum: 10c0/f3962c8bd403afdcf8d1b1f02f32388733008e9cae35f94e1fdb47a658a4cef622e11e4f86bb66ab99a484a8ce89b519bc432782e0f965a0fd82b223354e6ac0 + checksum: 10c0/a3c87a91eca84bda3b96eb8d66afa654542ed1ee3dbd3ec1a43dace4b53611e552a44d7ba8436888e965dbc6f099ddfa9c4ab91f691a19357ddc2f2cc940f9c5 languageName: node linkType: hard