SVGR
Next.js
Заголовок раздела «Next.js»https://react-svgr.com/docs/next/
pnpm add -D @svgr/webpack
declare module "*.svg?react" { import * as React from "react";
const ReactComponent: React.FunctionComponent< React.ComponentProps<"svg"> & { title?: string; titleId?: string; desc?: string; descId?: string; } >;
export default ReactComponent;}
{ "include": [ "next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "globals.d.ts" ]}
Storybook Next.js config
Заголовок раздела «Storybook Next.js config»const config: StorybookConfig = { webpackFinal: async (config) => { config.module = config.module || {}; config.module.rules = config.module.rules || [];
// This modifies the existing image rule to exclude .svg files // since you want to handle those files with @svgr/webpack const imageRule = config.module.rules.find((rule) => rule?.["test"]?.test(".svg") ); if (imageRule) { imageRule["exclude"] = /\.svg$/; }
// Configure .svg files to be loaded with @svgr/webpack config.module.rules.push({ test: /\.svg$/, use: ["@svgr/webpack"], });
return config; },};