Skip to content

Commit

Permalink
fix(plugin-svgr): failed to reuse SWC react options (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 12, 2024
1 parent 3161152 commit b0a48d4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/plugin-svgr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@rsbuild/plugin-react": "workspace:*",
"@scripts/test-helper": "workspace:*",
"@types/node": "16.x",
"typescript": "^5.3.0"
Expand Down
8 changes: 7 additions & 1 deletion packages/plugin-svgr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ function getSvgoDefaultConfig() {
export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
name: 'rsbuild:svgr',

pre: ['rsbuild:babel', 'uni-builder:babel', 'rsbuild-webpack:swc'],
pre: [
// SVGR needs to reuse the SWC loader options with react config
'rsbuild:react',
'rsbuild:babel',
'uni-builder:babel',
'rsbuild-webpack:swc',
],

setup(api) {
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ exports[`svgr > 'configure SVGR options' 1`] = `
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"development": true,
"refresh": true,
"runtime": "automatic",
},
},
},
"sourceMaps": true,
Expand Down Expand Up @@ -205,6 +210,11 @@ exports[`svgr > 'export default Component' 1`] = `
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"development": true,
"refresh": true,
"runtime": "automatic",
},
},
},
"sourceMaps": true,
Expand Down Expand Up @@ -319,6 +329,11 @@ exports[`svgr > 'export default url' 1`] = `
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"development": true,
"refresh": true,
"runtime": "automatic",
},
},
},
"sourceMaps": true,
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-svgr/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, describe, it, test } from 'vitest';
import { expect, describe, it } from 'vitest';
import { type PluginSvgrOptions, pluginSvgr } from '../src';
import { createStubRsbuild } from '@scripts/test-helper';
import { pluginReact } from '@rsbuild/plugin-react';
import { SVG_REGEX } from '@rsbuild/shared';

describe('svgr', () => {
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('svgr', () => {
rsbuildConfig: {},
});

rsbuild.addPlugins([pluginSvgr(item.pluginConfig)]);
rsbuild.addPlugins([pluginSvgr(item.pluginConfig), pluginReact()]);

const config = await rsbuild.unwrapConfig();

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b0a48d4

Please sign in to comment.