Skip to content

Commit 084eaf9

Browse files
authored
chore(plugin-svgr): improve SVGR options type (#5541)
1 parent c4fb34b commit 084eaf9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/plugin-svgr/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
33
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
44
import { PLUGIN_REACT_NAME } from '@rsbuild/plugin-react';
5-
import type { Config as SvgrOptions } from '@svgr/core';
5+
import type { Config as BaseSvgrOptions } from '@svgr/core';
66
import deepmerge from 'deepmerge';
77
import type { Config as SvgoConfig } from 'svgo';
88

9+
// @svgr/core does not have the svgo dependency, so we need to
10+
// manually specify the svgoConfig type
11+
type SvgrOptions = Omit<BaseSvgrOptions, 'svgoConfig'> & {
12+
svgoConfig?: SvgoConfig;
13+
};
14+
915
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1016

1117
type SvgoPluginConfig = NonNullable<SvgoConfig['plugins']>[0];
@@ -156,7 +162,9 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
156162

157163
const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX);
158164

159-
const svgrOptions = deepmerge<SvgrOptions>(
165+
const svgrOptions = deepmerge<
166+
SvgrOptions & Pick<Required<SvgrOptions>, 'svgo' | 'svgoConfig'>
167+
>(
160168
{
161169
svgo: true,
162170
svgoConfig: getSvgoDefaultConfig(),

0 commit comments

Comments
 (0)