@rsbuild/plugin-react 0.2.16 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { SwcReactConfig } from '@rsbuild/shared';
2
3
 
3
4
  declare const isBeyondReact17: (cwd: string) => Promise<any>;
4
5
 
@@ -17,6 +18,11 @@ type SplitReactChunkOptions = {
17
18
  router?: boolean;
18
19
  };
19
20
  type PluginReactOptions = {
21
+ /**
22
+ * Configure the behavior of SWC to transform React code,
23
+ * the same as SWC's [jsc.transform.react](https://swc.rs/docs/configuration/compilation#jsctransformreact).
24
+ */
25
+ swcReactOptions?: SwcReactConfig;
20
26
  /**
21
27
  * Configuration for chunk splitting of React-related dependencies.
22
28
  */
package/dist/index.js CHANGED
@@ -170,7 +170,7 @@ var setupCompiler = (compiler) => {
170
170
  name: void 0
171
171
  }).apply(compiler);
172
172
  };
173
- var applyBasicReactSupport = (api) => {
173
+ var applyBasicReactSupport = (api, options) => {
174
174
  api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
175
175
  if ((0, import_shared4.isProd)()) {
176
176
  return;
@@ -188,20 +188,21 @@ var applyBasicReactSupport = (api) => {
188
188
  const reactOptions = {
189
189
  development: !isProd3,
190
190
  refresh: usingHMR,
191
- runtime: "automatic"
191
+ runtime: "automatic",
192
+ ...options.swcReactOptions
192
193
  };
193
- rule.use(CHAIN_ID.USE.SWC).tap((options) => {
194
- options.jsc.transform.react = {
194
+ rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
195
+ options2.jsc.transform.react = {
195
196
  ...reactOptions
196
197
  };
197
- return options;
198
+ return options2;
198
199
  });
199
200
  if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
200
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
201
- options.jsc.transform.react = {
201
+ chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
202
+ options2.jsc.transform.react = {
202
203
  ...reactOptions
203
204
  };
204
- return options;
205
+ return options2;
205
206
  });
206
207
  }
207
208
  if (!usingHMR) {
@@ -238,7 +239,7 @@ var pluginReact = (options = {}) => ({
238
239
  pre: ["rsbuild:swc"],
239
240
  setup(api) {
240
241
  if (api.context.bundlerType === "rspack") {
241
- applyBasicReactSupport(api);
242
+ applyBasicReactSupport(api, options);
242
243
  }
243
244
  applyAntdSupport(api);
244
245
  applyArcoSupport(api);
package/dist/index.mjs CHANGED
@@ -134,7 +134,11 @@ var applySplitChunksRule = (api, options = {
134
134
  };
135
135
 
136
136
  // src/react.ts
137
- import { isUsingHMR, isClientCompiler, isProd as isProd2 } from "@rsbuild/shared";
137
+ import {
138
+ isProd as isProd2,
139
+ isUsingHMR,
140
+ isClientCompiler
141
+ } from "@rsbuild/shared";
138
142
  function getReactRefreshEntry(compiler) {
139
143
  const hot = compiler.options.devServer?.hot ?? true;
140
144
  const refresh = compiler.options.builtins?.react?.refresh ?? true;
@@ -158,7 +162,7 @@ var setupCompiler = (compiler) => {
158
162
  name: void 0
159
163
  }).apply(compiler);
160
164
  };
161
- var applyBasicReactSupport = (api) => {
165
+ var applyBasicReactSupport = (api, options) => {
162
166
  api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
163
167
  if (isProd2()) {
164
168
  return;
@@ -176,20 +180,21 @@ var applyBasicReactSupport = (api) => {
176
180
  const reactOptions = {
177
181
  development: !isProd3,
178
182
  refresh: usingHMR,
179
- runtime: "automatic"
183
+ runtime: "automatic",
184
+ ...options.swcReactOptions
180
185
  };
181
- rule.use(CHAIN_ID.USE.SWC).tap((options) => {
182
- options.jsc.transform.react = {
186
+ rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
187
+ options2.jsc.transform.react = {
183
188
  ...reactOptions
184
189
  };
185
- return options;
190
+ return options2;
186
191
  });
187
192
  if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
188
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
189
- options.jsc.transform.react = {
193
+ chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
194
+ options2.jsc.transform.react = {
190
195
  ...reactOptions
191
196
  };
192
- return options;
197
+ return options2;
193
198
  });
194
199
  }
195
200
  if (!usingHMR) {
@@ -226,7 +231,7 @@ var pluginReact = (options = {}) => ({
226
231
  pre: ["rsbuild:swc"],
227
232
  setup(api) {
228
233
  if (api.context.bundlerType === "rspack") {
229
- applyBasicReactSupport(api);
234
+ applyBasicReactSupport(api, options);
230
235
  }
231
236
  applyAntdSupport(api);
232
237
  applyArcoSupport(api);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,13 +24,13 @@
24
24
  "dependencies": {
25
25
  "@rspack/plugin-react-refresh": "0.4.5",
26
26
  "react-refresh": "^0.14.0",
27
- "@rsbuild/shared": "0.2.16"
27
+ "@rsbuild/shared": "0.2.18"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "16.x",
31
31
  "typescript": "^5.3.0",
32
- "@rsbuild/core": "0.2.16",
33
- "@rsbuild/test-helper": "0.2.16"
32
+ "@rsbuild/core": "0.2.18",
33
+ "@rsbuild/test-helper": "0.2.18"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public",