@rsbuild/plugin-react 0.3.0 → 0.3.2

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
@@ -28,6 +28,7 @@ type PluginReactOptions = {
28
28
  */
29
29
  splitChunks?: SplitReactChunkOptions;
30
30
  };
31
+ declare const PLUGIN_REACT_NAME = "rsbuild:react";
31
32
  declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
32
33
 
33
- export { PluginReactOptions, SplitReactChunkOptions, isBeyondReact17, pluginReact };
34
+ export { PLUGIN_REACT_NAME, PluginReactOptions, SplitReactChunkOptions, isBeyondReact17, pluginReact };
package/dist/index.js CHANGED
@@ -30,10 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ PLUGIN_REACT_NAME: () => PLUGIN_REACT_NAME,
33
34
  isBeyondReact17: () => isBeyondReact17,
34
35
  pluginReact: () => pluginReact
35
36
  });
36
37
  module.exports = __toCommonJS(src_exports);
38
+ var import_core = require("@rsbuild/core");
37
39
 
38
40
  // src/antd.ts
39
41
  var import_shared = require("@rsbuild/shared");
@@ -156,27 +158,24 @@ var applyBasicReactSupport = (api, options) => {
156
158
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
157
159
  const config = api.getNormalizedConfig();
158
160
  const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd: isProd2, target });
159
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
160
161
  const reactOptions = {
161
162
  development: !isProd2,
162
163
  refresh: usingHMR,
163
164
  runtime: "automatic",
164
165
  ...options.swcReactOptions
165
166
  };
166
- rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
167
- options2.jsc.transform.react = {
168
- ...reactOptions
169
- };
170
- return options2;
167
+ (0, import_shared4.modifySwcLoaderOptions)({
168
+ chain,
169
+ modifier: (options2) => {
170
+ return (0, import_shared4.deepmerge)(options2, {
171
+ jsc: {
172
+ transform: {
173
+ react: reactOptions
174
+ }
175
+ }
176
+ });
177
+ }
171
178
  });
172
- if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
173
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
174
- options2.jsc.transform.react = {
175
- ...reactOptions
176
- };
177
- return options2;
178
- });
179
- }
180
179
  if (!usingHMR) {
181
180
  return;
182
181
  }
@@ -207,9 +206,10 @@ var isBeyondReact17 = async (cwd) => {
207
206
  };
208
207
 
209
208
  // src/index.ts
209
+ var PLUGIN_REACT_NAME = "rsbuild:react";
210
210
  var pluginReact = (options = {}) => ({
211
- name: "rsbuild:react",
212
- pre: ["rsbuild:swc"],
211
+ name: PLUGIN_REACT_NAME,
212
+ pre: [import_core.PLUGIN_SWC_NAME],
213
213
  setup(api) {
214
214
  if (api.context.bundlerType === "rspack") {
215
215
  applyBasicReactSupport(api, options);
@@ -221,6 +221,7 @@ var pluginReact = (options = {}) => ({
221
221
  });
222
222
  // Annotate the CommonJS export names for ESM import in node:
223
223
  0 && (module.exports = {
224
+ PLUGIN_REACT_NAME,
224
225
  isBeyondReact17,
225
226
  pluginReact
226
227
  });
package/dist/index.mjs CHANGED
@@ -14,6 +14,9 @@ import path from "path";
14
14
  import { createRequire } from "module";
15
15
  global.require = createRequire(import.meta.url);
16
16
 
17
+ // src/index.ts
18
+ import { PLUGIN_SWC_NAME } from "@rsbuild/core";
19
+
17
20
  // src/antd.ts
18
21
  import { isServerTarget } from "@rsbuild/shared";
19
22
  var getAntdMajorVersion = (appDirectory) => {
@@ -135,34 +138,35 @@ var applySplitChunksRule = (api, options = {
135
138
 
136
139
  // src/react.ts
137
140
  import path2 from "path";
138
- import { isUsingHMR } from "@rsbuild/shared";
141
+ import {
142
+ deepmerge,
143
+ isUsingHMR,
144
+ modifySwcLoaderOptions
145
+ } from "@rsbuild/shared";
139
146
  var REACT_REFRESH_PATH = __require.resolve("react-refresh");
140
147
  var REACT_REFRESH_DIR_PATH = path2.dirname(REACT_REFRESH_PATH);
141
148
  var applyBasicReactSupport = (api, options) => {
142
149
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
143
150
  const config = api.getNormalizedConfig();
144
151
  const usingHMR = isUsingHMR(config, { isProd: isProd2, target });
145
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
146
152
  const reactOptions = {
147
153
  development: !isProd2,
148
154
  refresh: usingHMR,
149
155
  runtime: "automatic",
150
156
  ...options.swcReactOptions
151
157
  };
152
- rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
153
- options2.jsc.transform.react = {
154
- ...reactOptions
155
- };
156
- return options2;
158
+ modifySwcLoaderOptions({
159
+ chain,
160
+ modifier: (options2) => {
161
+ return deepmerge(options2, {
162
+ jsc: {
163
+ transform: {
164
+ react: reactOptions
165
+ }
166
+ }
167
+ });
168
+ }
157
169
  });
158
- if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
159
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options2) => {
160
- options2.jsc.transform.react = {
161
- ...reactOptions
162
- };
163
- return options2;
164
- });
165
- }
166
170
  if (!usingHMR) {
167
171
  return;
168
172
  }
@@ -193,9 +197,10 @@ var isBeyondReact17 = async (cwd) => {
193
197
  };
194
198
 
195
199
  // src/index.ts
200
+ var PLUGIN_REACT_NAME = "rsbuild:react";
196
201
  var pluginReact = (options = {}) => ({
197
- name: "rsbuild:react",
198
- pre: ["rsbuild:swc"],
202
+ name: PLUGIN_REACT_NAME,
203
+ pre: [PLUGIN_SWC_NAME],
199
204
  setup(api) {
200
205
  if (api.context.bundlerType === "rspack") {
201
206
  applyBasicReactSupport(api, options);
@@ -206,6 +211,7 @@ var pluginReact = (options = {}) => ({
206
211
  }
207
212
  });
208
213
  export {
214
+ PLUGIN_REACT_NAME,
209
215
  isBeyondReact17,
210
216
  pluginReact
211
217
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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.5.0",
26
26
  "react-refresh": "^0.14.0",
27
- "@rsbuild/shared": "0.3.0"
27
+ "@rsbuild/shared": "0.3.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "16.x",
31
31
  "typescript": "^5.3.0",
32
- "@rsbuild/core": "0.3.0",
33
- "@rsbuild/test-helper": "0.3.0"
32
+ "@rsbuild/core": "0.3.2",
33
+ "@scripts/test-helper": "1.0.0"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public",