@rsbuild/plugin-react 1.4.1 → 1.4.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.cjs CHANGED
@@ -1,20 +1,6 @@
1
1
  "use strict";
2
2
  const __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
- var __webpack_modules__ = {
4
- "@rspack/plugin-react-refresh": function(module) {
5
- module.exports = import("@rspack/plugin-react-refresh").then(function(module) {
6
- return module;
7
- });
8
- }
9
- }, __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- exports: {}
15
- };
16
- return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
17
- }
3
+ var __webpack_require__ = {};
18
4
  __webpack_require__.n = (module)=>{
19
5
  var getter = module && module.__esModule ? ()=>module.default : ()=>module;
20
6
  return __webpack_require__.d(getter, {
@@ -33,129 +19,130 @@ __webpack_require__.n = (module)=>{
33
19
  });
34
20
  };
35
21
  var __webpack_exports__ = {};
36
- for(var __webpack_i__ in (()=>{
37
- __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
38
- PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME,
39
- pluginReact: ()=>pluginReact
40
- });
41
- let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
42
- var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
43
- let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
44
- name: PLUGIN_REACT_NAME,
45
- setup (api) {
46
- let finalOptions = {
47
- fastRefresh: !0,
48
- enableProfiler: !1,
49
- ...options
50
- };
51
- if ('rspack' === api.context.bundlerType) {
52
- var api1, options1, api2;
53
- let REACT_REFRESH_PATH, hasReactDomClientCache;
54
- api1 = api, REACT_REFRESH_PATH = (options1 = finalOptions).fastRefresh ? react_require.resolve('react-refresh') : '', api1.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
55
- let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
56
- return mergeEnvironmentConfig({
57
- tools: {
58
- swc: {
59
- jsc: {
60
- parser: {
61
- syntax: "typescript",
62
- tsx: !0
63
- },
64
- transform: {
65
- react: {
66
- development: isDev,
67
- refresh: usingHMR && options1.fastRefresh,
68
- runtime: 'automatic',
69
- ...options1.swcReactOptions
70
- }
71
- }
72
- }
73
- }
74
- }
75
- }, config);
76
- }), options1.swcReactOptions?.runtime === 'preserve' && api1.modifyBundlerChain((chain)=>{
77
- chain.module.parser.merge({
78
- javascript: {
79
- jsx: !0
80
- }
81
- });
82
- }), api1.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
83
- let { config } = environment;
84
- if (!(isDev && config.dev.hmr && 'web' === target) || !options1.fastRefresh) return;
85
- chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
86
- let { ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh")), jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
87
- chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
88
- {
89
- test: jsRule.get('test'),
90
- include: jsRule.include.values(),
91
- exclude: jsRule.exclude.values(),
92
- resourceQuery: {
93
- not: /^\?raw$/
94
- },
95
- ...options1.reactRefreshOptions
96
- }
97
- ]);
98
- }), finalOptions.enableProfiler && ((api2 = api).modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
99
- if ('production' === config.mode) return mergeEnvironmentConfig(config, {
100
- output: {
101
- minify: {
102
- jsOptions: {
103
- minimizerOptions: {
104
- mangle: {
105
- keep_classnames: !0,
106
- keep_fnames: !0
107
- }
108
- }
109
- }
110
- }
111
- }
112
- });
113
- }), api2.modifyBundlerChain((chain, { isProd })=>{
114
- isProd && (chain.resolve.alias.set((()=>{
115
- if (void 0 !== hasReactDomClientCache) return hasReactDomClientCache;
116
- try {
117
- react_require.resolve('react-dom/client', {
118
- paths: [
119
- api2.context.rootPath
120
- ]
121
- }), hasReactDomClientCache = !0;
122
- } catch {
123
- hasReactDomClientCache = !1;
22
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
23
+ PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME,
24
+ pluginReact: ()=>pluginReact
25
+ });
26
+ const external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
27
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
28
+ const react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
29
+ let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
30
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
31
+ let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
32
+ return mergeEnvironmentConfig({
33
+ tools: {
34
+ swc: {
35
+ jsc: {
36
+ parser: {
37
+ syntax: "typescript",
38
+ tsx: !0
39
+ },
40
+ transform: {
41
+ react: {
42
+ development: isDev,
43
+ refresh: usingHMR && options.fastRefresh,
44
+ runtime: 'automatic',
45
+ ...options.swcReactOptions
124
46
  }
125
- return hasReactDomClientCache;
126
- })() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
127
- }));
47
+ }
48
+ }
128
49
  }
129
- ((api, options = {
130
- react: !0,
131
- router: !0
132
- })=>{
133
- api.modifyBundlerChain((chain, { environment, isProd })=>{
134
- let obj, { config } = environment;
135
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
136
- let currentConfig = chain.optimization.splitChunks.values();
137
- if (null === (obj = currentConfig) || 'object' != typeof obj || '[object Object]' !== Object.prototype.toString.call(obj)) return;
138
- let extraGroups = {};
139
- options.react && (extraGroups.react = {
140
- name: 'lib-react',
141
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
142
- priority: 0
143
- }), options.router && (extraGroups.router = {
144
- name: 'lib-router',
145
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
146
- priority: 0
147
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
148
- ...currentConfig,
149
- cacheGroups: {
150
- ...extraGroups,
151
- ...currentConfig.cacheGroups
50
+ }
51
+ }, config);
52
+ }), options.swcReactOptions?.runtime === 'preserve' && api.modifyBundlerChain((chain)=>{
53
+ chain.module.parser.merge({
54
+ javascript: {
55
+ jsx: !0
56
+ }
57
+ });
58
+ }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
59
+ let { config } = environment;
60
+ if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
61
+ chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
62
+ let { ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh"), jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
63
+ chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
64
+ {
65
+ test: jsRule.get('test'),
66
+ include: jsRule.include.values(),
67
+ exclude: jsRule.exclude.values(),
68
+ resourceQuery: {
69
+ not: /^\?raw$/
70
+ },
71
+ ...options.reactRefreshOptions
72
+ }
73
+ ]);
74
+ });
75
+ }, applyReactProfiler = (api)=>{
76
+ let hasReactDomClientCache;
77
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
78
+ if ('production' === config.mode) return mergeEnvironmentConfig(config, {
79
+ output: {
80
+ minify: {
81
+ jsOptions: {
82
+ minimizerOptions: {
83
+ mangle: {
84
+ keep_classnames: !0,
85
+ keep_fnames: !0
152
86
  }
153
- });
154
- });
155
- })(api, finalOptions?.splitChunks);
87
+ }
88
+ }
89
+ }
156
90
  }
157
91
  });
158
- })(), exports.PLUGIN_REACT_NAME = __webpack_exports__.PLUGIN_REACT_NAME, exports.pluginReact = __webpack_exports__.pluginReact, __webpack_exports__)-1 === [
92
+ }), api.modifyBundlerChain((chain, { isProd })=>{
93
+ isProd && (chain.resolve.alias.set((()=>{
94
+ if (void 0 !== hasReactDomClientCache) return hasReactDomClientCache;
95
+ try {
96
+ react_require.resolve('react-dom/client', {
97
+ paths: [
98
+ api.context.rootPath
99
+ ]
100
+ }), hasReactDomClientCache = !0;
101
+ } catch {
102
+ hasReactDomClientCache = !1;
103
+ }
104
+ return hasReactDomClientCache;
105
+ })() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
106
+ });
107
+ }, applySplitChunksRule = (api, options)=>{
108
+ api.modifyBundlerChain((chain, { environment, isProd })=>{
109
+ let { config } = environment;
110
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy || !1 === options) return;
111
+ let normalizedOptions = !0 === options ? {
112
+ react: !0,
113
+ router: !0
114
+ } : options, currentConfig = chain.optimization.splitChunks.values();
115
+ if ('object' != typeof currentConfig) return;
116
+ let extraGroups = {};
117
+ normalizedOptions.react && (extraGroups.react = {
118
+ name: 'lib-react',
119
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
120
+ priority: 0
121
+ }), normalizedOptions.router && (extraGroups.router = {
122
+ name: 'lib-router',
123
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
124
+ priority: 0
125
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
126
+ ...currentConfig,
127
+ cacheGroups: {
128
+ ...extraGroups,
129
+ ...currentConfig.cacheGroups
130
+ }
131
+ });
132
+ });
133
+ }, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
134
+ name: PLUGIN_REACT_NAME,
135
+ setup (api) {
136
+ let finalOptions = {
137
+ fastRefresh: !0,
138
+ splitChunks: !0,
139
+ enableProfiler: !1,
140
+ ...options
141
+ };
142
+ 'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, finalOptions.splitChunks);
143
+ }
144
+ });
145
+ for(var __webpack_i__ in exports.PLUGIN_REACT_NAME = __webpack_exports__.PLUGIN_REACT_NAME, exports.pluginReact = __webpack_exports__.pluginReact, __webpack_exports__)-1 === [
159
146
  "PLUGIN_REACT_NAME",
160
147
  "pluginReact"
161
148
  ].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
package/dist/index.d.ts CHANGED
@@ -21,9 +21,11 @@ export type PluginReactOptions = {
21
21
  */
22
22
  swcReactOptions?: Rspack.SwcLoaderTransformConfig['react'];
23
23
  /**
24
- * Configuration for chunk splitting of React-related dependencies.
24
+ * Configuration for chunk splitting of React-related dependencies when `chunkSplit.strategy`
25
+ * is set to `split-by-experience`.
26
+ * @default true
25
27
  */
26
- splitChunks?: SplitReactChunkOptions;
28
+ splitChunks?: boolean | SplitReactChunkOptions;
27
29
  /**
28
30
  * When set to `true`, enables the React Profiler for performance analysis in production builds.
29
31
  * @default false
package/dist/index.js CHANGED
@@ -3,8 +3,10 @@ import node_path from "node:path";
3
3
  let react_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
4
4
  name: PLUGIN_REACT_NAME,
5
5
  setup (api) {
6
+ var options1;
6
7
  let finalOptions = {
7
8
  fastRefresh: !0,
9
+ splitChunks: !0,
8
10
  enableProfiler: !1,
9
11
  ...options
10
12
  };
@@ -85,33 +87,31 @@ let react_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild
85
87
  })() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
86
88
  }));
87
89
  }
88
- ((api, options = {
89
- react: !0,
90
- router: !0
91
- })=>{
92
- api.modifyBundlerChain((chain, { environment, isProd })=>{
93
- let { config } = environment;
94
- if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
95
- let currentConfig = chain.optimization.splitChunks.values();
96
- if (null === currentConfig || 'object' != typeof currentConfig || '[object Object]' !== Object.prototype.toString.call(currentConfig)) return;
97
- let extraGroups = {};
98
- options.react && (extraGroups.react = {
99
- name: 'lib-react',
100
- test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
101
- priority: 0
102
- }), options.router && (extraGroups.router = {
103
- name: 'lib-router',
104
- test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
105
- priority: 0
106
- }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
107
- ...currentConfig,
108
- cacheGroups: {
109
- ...extraGroups,
110
- ...currentConfig.cacheGroups
111
- }
112
- });
90
+ options1 = finalOptions.splitChunks, api.modifyBundlerChain((chain, { environment, isProd })=>{
91
+ let { config } = environment;
92
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy || !1 === options1) return;
93
+ let normalizedOptions = !0 === options1 ? {
94
+ react: !0,
95
+ router: !0
96
+ } : options1, currentConfig = chain.optimization.splitChunks.values();
97
+ if ('object' != typeof currentConfig) return;
98
+ let extraGroups = {};
99
+ normalizedOptions.react && (extraGroups.react = {
100
+ name: 'lib-react',
101
+ test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
102
+ priority: 0
103
+ }), normalizedOptions.router && (extraGroups.router = {
104
+ name: 'lib-router',
105
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
106
+ priority: 0
107
+ }), Object.keys(extraGroups).length && chain.optimization.splitChunks({
108
+ ...currentConfig,
109
+ cacheGroups: {
110
+ ...extraGroups,
111
+ ...currentConfig.cacheGroups
112
+ }
113
113
  });
114
- })(api, finalOptions?.splitChunks);
114
+ });
115
115
  }
116
116
  });
117
117
  export { PLUGIN_REACT_NAME, pluginReact };
@@ -1,3 +1,3 @@
1
1
  import type { RsbuildPluginAPI } from '@rsbuild/core';
2
2
  import type { SplitReactChunkOptions } from './index.js';
3
- export declare const applySplitChunksRule: (api: RsbuildPluginAPI, options?: SplitReactChunkOptions) => void;
3
+ export declare const applySplitChunksRule: (api: RsbuildPluginAPI, options: SplitReactChunkOptions | boolean) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,14 +22,14 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rspack/plugin-react-refresh": "^1.5.1",
26
- "react-refresh": "^0.17.0"
25
+ "@rspack/plugin-react-refresh": "^1.5.2",
26
+ "react-refresh": "^0.18.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@rslib/core": "0.14.0",
30
- "@types/node": "^22.18.6",
31
- "typescript": "^5.9.2",
32
- "@rsbuild/core": "1.5.12",
29
+ "@rslib/core": "0.17.1",
30
+ "@types/node": "^24.9.2",
31
+ "typescript": "^5.9.3",
32
+ "@rsbuild/core": "1.6.2",
33
33
  "@scripts/test-helper": "1.0.1"
34
34
  },
35
35
  "peerDependencies": {