Skip to content

Commit

Permalink
Adds compatibility with SVGR in Storybook configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ReihaneB committed Feb 14, 2024
1 parent d13eb87 commit 348761c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ const config: StorybookConfig = {
name: "@storybook/nextjs",
options: {},
},
webpackFinal: (config: any) => {
// this modifies the existing image rule to exclude .svg files
// since we want to handle those files with @svgr/webpack
const svgRules = config.module.rules.filter((rule) =>
rule.test?.test('.svg')
);
svgRules.forEach((rule) => {
rule.exclude = /\.svg$/;
});

// configure .svg files to be loaded with @svgr/webpack and as assets
config.module.rules.push(
{
test: /\.svg$/i,
type: 'asset',
resourceQuery: /url/, // *.svg?url
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: {
not: [/url/],
},
// exclude react component if *.svg?url
use: ['@svgr/webpack'],
}
);
return config;
},
};

export default config;

0 comments on commit 348761c

Please sign in to comment.