mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
54 lines
1.4 KiB
Markdown
54 lines
1.4 KiB
Markdown
```js filename=".storybook/main.js" renderer="react" language="js"
|
|
export default {
|
|
// ...
|
|
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;
|
|
},
|
|
};
|
|
```
|
|
|
|
```ts filename=".storybook/main.ts" renderer="react" language="ts"
|
|
import { StorybookConfig } from '@storybook/nextjs';
|
|
|
|
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;
|
|
},
|
|
};
|
|
|
|
export default config;
|
|
```
|