Skip to content

Commit

Permalink
perf(plugin-react): reduce deepmerge overhead (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 31, 2024
1 parent b467588 commit 0a166ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
22 changes: 9 additions & 13 deletions packages/plugin-preact/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import {
deepmerge,
modifySwcLoaderOptions,
type SwcReactConfig,
} from '@rsbuild/shared';
import { modifySwcLoaderOptions, type SwcReactConfig } from '@rsbuild/shared';

export type PluginPreactOptions = {
/**
Expand Down Expand Up @@ -39,14 +35,14 @@ export const pluginPreact = (

modifySwcLoaderOptions({
chain,
modifier: (options) => {
return deepmerge(options, {
jsc: {
transform: {
react: reactOptions,
},
},
});
modifier: (opts) => {
opts.jsc ??= {};
opts.jsc.transform ??= {};
opts.jsc.transform.react = {
...opts.jsc.transform.react,
...reactOptions,
};
return opts;
},
});
});
Expand Down
17 changes: 8 additions & 9 deletions packages/plugin-react/src/react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import {
deepmerge,
isUsingHMR,
modifySwcLoaderOptions,
type SwcReactConfig,
Expand All @@ -27,14 +26,14 @@ export const applyBasicReactSupport = (

modifySwcLoaderOptions({
chain,
modifier: (options) => {
return deepmerge(options, {
jsc: {
transform: {
react: reactOptions,
},
},
});
modifier: (opts) => {
opts.jsc ??= {};
opts.jsc.transform ??= {};
opts.jsc.transform.react = {
...opts.jsc.transform.react,
...reactOptions,
};
return opts;
},
});

Expand Down

0 comments on commit 0a166ba

Please sign in to comment.