@rsbuild/plugin-react 0.0.0-next-20240109105933 → 0.0.0-next-20240131063127

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, type PluginReactOptions, type SplitReactChunkOptions, isBeyondReact17, pluginReact };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ 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
  });
@@ -153,30 +154,27 @@ var import_shared4 = require("@rsbuild/shared");
153
154
  var REACT_REFRESH_PATH = require.resolve("react-refresh");
154
155
  var REACT_REFRESH_DIR_PATH = import_node_path.default.dirname(REACT_REFRESH_PATH);
155
156
  var applyBasicReactSupport = (api, options) => {
156
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
157
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isDev, isProd: isProd2, target }) => {
157
158
  const config = api.getNormalizedConfig();
158
159
  const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd: isProd2, target });
159
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
160
160
  const reactOptions = {
161
- development: !isProd2,
161
+ development: isDev,
162
162
  refresh: usingHMR,
163
163
  runtime: "automatic",
164
164
  ...options.swcReactOptions
165
165
  };
166
- rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
167
- options2.jsc.transform.react = {
168
- ...reactOptions
169
- };
170
- return options2;
166
+ (0, import_shared4.modifySwcLoaderOptions)({
167
+ chain,
168
+ modifier: (options2) => {
169
+ return (0, import_shared4.deepmerge)(options2, {
170
+ jsc: {
171
+ transform: {
172
+ react: reactOptions
173
+ }
174
+ }
175
+ });
176
+ }
171
177
  });
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
178
  if (!usingHMR) {
181
179
  return;
182
180
  }
@@ -187,7 +185,7 @@ var applyBasicReactSupport = (api, options) => {
187
185
  };
188
186
 
189
187
  // src/utils.ts
190
- var import_fs = __toESM(require("fs"));
188
+ var import_node_fs = __toESM(require("fs"));
191
189
  var import_semver = __toESM(require("@rsbuild/shared/semver"));
192
190
  var import_shared5 = require("@rsbuild/shared");
193
191
  var isBeyondReact17 = async (cwd) => {
@@ -195,7 +193,7 @@ var isBeyondReact17 = async (cwd) => {
195
193
  if (!pkgPath) {
196
194
  return false;
197
195
  }
198
- const pkgInfo = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
196
+ const pkgInfo = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
199
197
  const deps = {
200
198
  ...pkgInfo.devDependencies,
201
199
  ...pkgInfo.dependencies
@@ -207,9 +205,9 @@ var isBeyondReact17 = async (cwd) => {
207
205
  };
208
206
 
209
207
  // src/index.ts
208
+ var PLUGIN_REACT_NAME = "rsbuild:react";
210
209
  var pluginReact = (options = {}) => ({
211
- name: "rsbuild:react",
212
- pre: ["rsbuild:swc"],
210
+ name: PLUGIN_REACT_NAME,
213
211
  setup(api) {
214
212
  if (api.context.bundlerType === "rspack") {
215
213
  applyBasicReactSupport(api, options);
@@ -221,6 +219,7 @@ var pluginReact = (options = {}) => ({
221
219
  });
222
220
  // Annotate the CommonJS export names for ESM import in node:
223
221
  0 && (module.exports = {
222
+ PLUGIN_REACT_NAME,
224
223
  isBeyondReact17,
225
224
  pluginReact
226
225
  });
package/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from 'module';
2
+ var require = createRequire(import.meta['url']);
3
+
1
4
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
5
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
6
  }) : x)(function(x) {
@@ -6,14 +9,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
9
  throw Error('Dynamic require of "' + x + '" is not supported');
7
10
  });
8
11
 
9
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.45.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
12
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.46.1_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
10
13
  import { fileURLToPath } from "url";
11
14
  import path from "path";
12
15
 
13
- // ../../scripts/requireShims.js
14
- import { createRequire } from "module";
15
- global.require = createRequire(import.meta.url);
16
-
17
16
  // src/antd.ts
18
17
  import { isServerTarget } from "@rsbuild/shared";
19
18
  var getAntdMajorVersion = (appDirectory) => {
@@ -135,34 +134,35 @@ var applySplitChunksRule = (api, options = {
135
134
 
136
135
  // src/react.ts
137
136
  import path2 from "path";
138
- import { isUsingHMR } from "@rsbuild/shared";
137
+ import {
138
+ deepmerge,
139
+ isUsingHMR,
140
+ modifySwcLoaderOptions
141
+ } from "@rsbuild/shared";
139
142
  var REACT_REFRESH_PATH = __require.resolve("react-refresh");
140
143
  var REACT_REFRESH_DIR_PATH = path2.dirname(REACT_REFRESH_PATH);
141
144
  var applyBasicReactSupport = (api, options) => {
142
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
145
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isDev, isProd: isProd2, target }) => {
143
146
  const config = api.getNormalizedConfig();
144
147
  const usingHMR = isUsingHMR(config, { isProd: isProd2, target });
145
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
146
148
  const reactOptions = {
147
- development: !isProd2,
149
+ development: isDev,
148
150
  refresh: usingHMR,
149
151
  runtime: "automatic",
150
152
  ...options.swcReactOptions
151
153
  };
152
- rule.use(CHAIN_ID.USE.SWC).tap((options2) => {
153
- options2.jsc.transform.react = {
154
- ...reactOptions
155
- };
156
- return options2;
154
+ modifySwcLoaderOptions({
155
+ chain,
156
+ modifier: (options2) => {
157
+ return deepmerge(options2, {
158
+ jsc: {
159
+ transform: {
160
+ react: reactOptions
161
+ }
162
+ }
163
+ });
164
+ }
157
165
  });
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
166
  if (!usingHMR) {
167
167
  return;
168
168
  }
@@ -193,9 +193,9 @@ var isBeyondReact17 = async (cwd) => {
193
193
  };
194
194
 
195
195
  // src/index.ts
196
+ var PLUGIN_REACT_NAME = "rsbuild:react";
196
197
  var pluginReact = (options = {}) => ({
197
- name: "rsbuild:react",
198
- pre: ["rsbuild:swc"],
198
+ name: PLUGIN_REACT_NAME,
199
199
  setup(api) {
200
200
  if (api.context.bundlerType === "rspack") {
201
201
  applyBasicReactSupport(api, options);
@@ -206,6 +206,7 @@ var pluginReact = (options = {}) => ({
206
206
  }
207
207
  });
208
208
  export {
209
+ PLUGIN_REACT_NAME,
209
210
  isBeyondReact17,
210
211
  pluginReact
211
212
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "0.0.0-next-20240109105933",
3
+ "version": "0.0.0-next-20240131063127",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,15 +22,18 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rspack/plugin-react-refresh": "0.4.5-canary-be59383-20240105051840",
25
+ "@rspack/plugin-react-refresh": "0.5.3",
26
26
  "react-refresh": "^0.14.0",
27
- "@rsbuild/shared": "0.0.0-next-20240109105933"
27
+ "@rsbuild/shared": "0.0.0-next-20240131063127"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "16.x",
31
31
  "typescript": "^5.3.0",
32
- "@rsbuild/core": "0.0.0-next-20240109105933",
33
- "@rsbuild/test-helper": "0.0.0-next-20240109105933"
32
+ "@rsbuild/core": "0.0.0-next-20240131063127",
33
+ "@scripts/test-helper": "0.0.0-next-20240131063127"
34
+ },
35
+ "peerDependencies": {
36
+ "@rsbuild/core": "0.0.0-next-20240131063127"
34
37
  },
35
38
  "publishConfig": {
36
39
  "access": "public",