@rsbuild/plugin-react 1.0.7 → 1.1.0
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 +70 -177
- package/dist/index.js +34 -67
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -1,142 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
let __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;
|
|
2
3
|
var __webpack_modules__ = {
|
|
3
|
-
"@rspack/plugin-react-refresh": function(
|
|
4
|
-
|
|
4
|
+
"@rspack/plugin-react-refresh": function(module) {
|
|
5
|
+
module.exports = import("@rspack/plugin-react-refresh");
|
|
5
6
|
}
|
|
6
|
-
};
|
|
7
|
-
/************************************************************************/ // The module cache
|
|
8
|
-
var __webpack_module_cache__ = {};
|
|
9
|
-
// The require function
|
|
7
|
+
}, __webpack_module_cache__ = {};
|
|
10
8
|
function __webpack_require__(moduleId) {
|
|
11
|
-
// Check if module is in cache
|
|
12
9
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
10
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
|
|
15
|
-
var module1 = __webpack_module_cache__[moduleId] = {
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
16
12
|
exports: {}
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
__webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
|
|
20
|
-
// Return the exports of the module
|
|
21
|
-
return module1.exports;
|
|
14
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
22
15
|
}
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return module1['default'];
|
|
29
|
-
} : function() {
|
|
30
|
-
return module1;
|
|
31
|
-
};
|
|
32
|
-
__webpack_require__.d(getter, {
|
|
33
|
-
a: getter
|
|
34
|
-
});
|
|
35
|
-
return getter;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
|
-
// webpack/runtime/create_fake_namespace_object
|
|
39
|
-
(()=>{
|
|
40
|
-
var getProto = Object.getPrototypeOf ? function(obj) {
|
|
41
|
-
return Object.getPrototypeOf(obj);
|
|
42
|
-
} : function(obj) {
|
|
43
|
-
return obj.__proto__;
|
|
44
|
-
};
|
|
45
|
-
var leafPrototypes;
|
|
46
|
-
// create a fake namespace object
|
|
47
|
-
// mode & 1: value is a module id, require it
|
|
48
|
-
// mode & 2: merge all properties of value into the ns
|
|
49
|
-
// mode & 4: return value when already ns object
|
|
50
|
-
// mode & 16: return value when it's Promise-like
|
|
51
|
-
// mode & 8|1: behave like require
|
|
52
|
-
__webpack_require__.t = function(value, mode) {
|
|
53
|
-
if (1 & mode) value = this(value);
|
|
54
|
-
if (8 & mode) return value;
|
|
55
|
-
if ('object' == typeof value && value) {
|
|
56
|
-
if (4 & mode && value.__esModule) return value;
|
|
57
|
-
if (16 & mode && 'function' == typeof value.then) return value;
|
|
58
|
-
}
|
|
59
|
-
var ns = Object.create(null);
|
|
60
|
-
__webpack_require__.r(ns);
|
|
61
|
-
var def = {};
|
|
62
|
-
leafPrototypes = leafPrototypes || [
|
|
63
|
-
null,
|
|
64
|
-
getProto({}),
|
|
65
|
-
getProto([]),
|
|
66
|
-
getProto(getProto)
|
|
67
|
-
];
|
|
68
|
-
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
|
|
69
|
-
def[key] = function() {
|
|
70
|
-
return value[key];
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
def['default'] = function() {
|
|
74
|
-
return value;
|
|
75
|
-
};
|
|
76
|
-
__webpack_require__.d(ns, def);
|
|
77
|
-
return ns;
|
|
78
|
-
};
|
|
79
|
-
})();
|
|
80
|
-
// webpack/runtime/define_property_getters
|
|
81
|
-
(()=>{
|
|
82
|
-
__webpack_require__.d = function(exports1, definition) {
|
|
83
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: definition[key]
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
})();
|
|
89
|
-
// webpack/runtime/has_own_property
|
|
90
|
-
(()=>{
|
|
91
|
-
__webpack_require__.o = function(obj, prop) {
|
|
92
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
93
|
-
};
|
|
94
|
-
})();
|
|
95
|
-
// webpack/runtime/make_namespace_object
|
|
96
|
-
(()=>{
|
|
97
|
-
// define __esModule on exports
|
|
98
|
-
__webpack_require__.r = function(exports1) {
|
|
99
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
100
|
-
value: 'Module'
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
103
|
-
value: true
|
|
104
|
-
});
|
|
16
|
+
__webpack_require__.n = function(module) {
|
|
17
|
+
var getter = module && module.__esModule ? function() {
|
|
18
|
+
return module.default;
|
|
19
|
+
} : function() {
|
|
20
|
+
return module;
|
|
105
21
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
__webpack_require__.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
22
|
+
return __webpack_require__.d(getter, {
|
|
23
|
+
a: getter
|
|
24
|
+
}), getter;
|
|
25
|
+
}, __webpack_require__.d = function(exports1, definition) {
|
|
26
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
27
|
+
enumerable: !0,
|
|
28
|
+
get: definition[key]
|
|
29
|
+
});
|
|
30
|
+
}, __webpack_require__.o = function(obj, prop) {
|
|
31
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
32
|
+
}, __webpack_require__.r = function(exports1) {
|
|
33
|
+
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
34
|
+
value: 'Module'
|
|
35
|
+
}), Object.defineProperty(exports1, '__esModule', {
|
|
36
|
+
value: !0
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
41
|
+
PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME,
|
|
42
|
+
pluginReact: ()=>pluginReact
|
|
114
43
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
120
|
-
}());
|
|
121
|
-
const applyBasicReactSupport = (api, options)=>{
|
|
122
|
-
const REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
44
|
+
let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
|
|
45
|
+
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
46
|
+
let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
|
|
47
|
+
let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
123
48
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
124
|
-
|
|
125
|
-
const usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
|
|
126
|
-
const reactOptions = {
|
|
49
|
+
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target, reactOptions = {
|
|
127
50
|
development: isDev,
|
|
128
51
|
refresh: usingHMR && options.fastRefresh,
|
|
129
52
|
runtime: 'automatic',
|
|
130
53
|
...options.swcReactOptions
|
|
131
54
|
};
|
|
132
|
-
|
|
55
|
+
return mergeEnvironmentConfig({
|
|
133
56
|
tools: {
|
|
134
57
|
swc: {
|
|
135
58
|
jsc: {
|
|
136
59
|
parser: {
|
|
137
60
|
syntax: 'typescript',
|
|
138
|
-
|
|
139
|
-
tsx: true
|
|
61
|
+
tsx: !0
|
|
140
62
|
},
|
|
141
63
|
transform: {
|
|
142
64
|
react: reactOptions
|
|
@@ -144,111 +66,82 @@ const applyBasicReactSupport = (api, options)=>{
|
|
|
144
66
|
}
|
|
145
67
|
}
|
|
146
68
|
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const { config } = environment;
|
|
152
|
-
const usingHMR = isDev && config.dev.hmr && 'web' === target;
|
|
153
|
-
if (!usingHMR || !options.fastRefresh) return;
|
|
69
|
+
}, config);
|
|
70
|
+
}), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
71
|
+
let { config } = environment;
|
|
72
|
+
if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
|
|
154
73
|
chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
|
|
155
|
-
|
|
156
|
-
const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
|
|
157
|
-
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
74
|
+
let { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
|
|
158
75
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
|
|
159
76
|
{
|
|
160
77
|
include: [
|
|
161
|
-
|
|
78
|
+
/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
|
|
162
79
|
],
|
|
163
80
|
exclude: [
|
|
164
|
-
|
|
81
|
+
/[\\/]node_modules[\\/]/
|
|
165
82
|
],
|
|
166
83
|
...options.reactRefreshOptions
|
|
167
84
|
}
|
|
168
85
|
]);
|
|
169
86
|
});
|
|
170
|
-
}
|
|
171
|
-
const applyReactProfiler = (api)=>{
|
|
87
|
+
}, applyReactProfiler = (api)=>{
|
|
172
88
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
173
|
-
if ('production'
|
|
174
|
-
const enableProfilerConfig = {
|
|
89
|
+
if ('production' === config.mode) return mergeEnvironmentConfig(config, {
|
|
175
90
|
output: {
|
|
176
91
|
minify: {
|
|
177
92
|
jsOptions: {
|
|
178
93
|
minimizerOptions: {
|
|
179
|
-
// Need to keep classnames and function names like Components for debugging purposes.
|
|
180
94
|
mangle: {
|
|
181
|
-
keep_classnames:
|
|
182
|
-
keep_fnames:
|
|
95
|
+
keep_classnames: !0,
|
|
96
|
+
keep_fnames: !0
|
|
183
97
|
}
|
|
184
98
|
}
|
|
185
99
|
}
|
|
186
100
|
}
|
|
187
101
|
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
api.modifyBundlerChain((chain, { isProd })=>{
|
|
192
|
-
if (!isProd) return;
|
|
193
|
-
// Replace react-dom with the profiling version.
|
|
194
|
-
// Reference: https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
|
|
195
|
-
chain.resolve.alias.set('react-dom$', 'react-dom/profiling');
|
|
196
|
-
chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
|
|
102
|
+
});
|
|
103
|
+
}), api.modifyBundlerChain((chain, { isProd })=>{
|
|
104
|
+
if (!!isProd) chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
|
|
197
105
|
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
react: true,
|
|
202
|
-
router: true
|
|
106
|
+
}, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
|
|
107
|
+
react: !0,
|
|
108
|
+
router: !0
|
|
203
109
|
})=>{
|
|
204
110
|
api.modifyBundlerChain((chain, { environment, isProd })=>{
|
|
205
|
-
|
|
111
|
+
let { config } = environment;
|
|
206
112
|
if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
|
|
207
|
-
|
|
113
|
+
let currentConfig = chain.optimization.splitChunks.values();
|
|
208
114
|
if (!isPlainObject(currentConfig)) return;
|
|
209
|
-
|
|
210
|
-
if (options.react
|
|
115
|
+
let extraGroups = {};
|
|
116
|
+
if (options.react && (extraGroups.react = {
|
|
211
117
|
name: 'lib-react',
|
|
212
118
|
test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
|
|
213
119
|
priority: 0
|
|
214
|
-
}
|
|
215
|
-
if (options.router) extraGroups.router = {
|
|
120
|
+
}), options.router && (extraGroups.router = {
|
|
216
121
|
name: 'lib-router',
|
|
217
122
|
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
218
123
|
priority: 0
|
|
219
|
-
}
|
|
220
|
-
if (!Object.keys(extraGroups).length) return;
|
|
221
|
-
chain.optimization.splitChunks({
|
|
124
|
+
}), !!Object.keys(extraGroups).length) chain.optimization.splitChunks({
|
|
222
125
|
...currentConfig,
|
|
223
126
|
cacheGroups: {
|
|
224
|
-
// user defined cache groups take precedence
|
|
225
127
|
...extraGroups,
|
|
226
128
|
...currentConfig.cacheGroups
|
|
227
129
|
}
|
|
228
130
|
});
|
|
229
131
|
});
|
|
230
|
-
}
|
|
231
|
-
const PLUGIN_REACT_NAME = 'rsbuild:react';
|
|
232
|
-
const pluginReact = (options = {})=>({
|
|
132
|
+
}, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
|
|
233
133
|
name: PLUGIN_REACT_NAME,
|
|
234
134
|
setup (api) {
|
|
235
|
-
|
|
236
|
-
fastRefresh:
|
|
237
|
-
enableProfiler:
|
|
238
|
-
};
|
|
239
|
-
const finalOptions = {
|
|
240
|
-
...defaultOptions,
|
|
135
|
+
let finalOptions = {
|
|
136
|
+
fastRefresh: !0,
|
|
137
|
+
enableProfiler: !1,
|
|
241
138
|
...options
|
|
242
139
|
};
|
|
243
|
-
|
|
244
|
-
applyBasicReactSupport(api, finalOptions);
|
|
245
|
-
if (finalOptions.enableProfiler) applyReactProfiler(api);
|
|
246
|
-
}
|
|
247
|
-
applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
140
|
+
'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
248
141
|
}
|
|
249
142
|
});
|
|
250
143
|
var __webpack_export_target__ = exports;
|
|
251
|
-
for(var
|
|
252
|
-
|
|
253
|
-
value:
|
|
144
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
145
|
+
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
146
|
+
value: !0
|
|
254
147
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
3
|
+
let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url), applyBasicReactSupport = (api, options)=>{
|
|
4
|
+
let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
6
5
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
7
|
-
|
|
8
|
-
const usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
|
|
9
|
-
const reactOptions = {
|
|
6
|
+
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target, reactOptions = {
|
|
10
7
|
development: isDev,
|
|
11
8
|
refresh: usingHMR && options.fastRefresh,
|
|
12
9
|
runtime: 'automatic',
|
|
13
10
|
...options.swcReactOptions
|
|
14
11
|
};
|
|
15
|
-
|
|
12
|
+
return mergeEnvironmentConfig({
|
|
16
13
|
tools: {
|
|
17
14
|
swc: {
|
|
18
15
|
jsc: {
|
|
19
16
|
parser: {
|
|
20
17
|
syntax: 'typescript',
|
|
21
|
-
|
|
22
|
-
tsx: true
|
|
18
|
+
tsx: !0
|
|
23
19
|
},
|
|
24
20
|
transform: {
|
|
25
21
|
react: reactOptions
|
|
@@ -27,107 +23,78 @@ const applyBasicReactSupport = (api, options)=>{
|
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!usingHMR || !options.fastRefresh) return;
|
|
37
|
-
chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(REACT_REFRESH_PATH));
|
|
38
|
-
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
39
|
-
const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
|
|
40
|
-
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
26
|
+
}, config);
|
|
27
|
+
}), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
28
|
+
let { config } = environment;
|
|
29
|
+
if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
|
|
30
|
+
chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path__.default.dirname(REACT_REFRESH_PATH));
|
|
31
|
+
let { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
41
32
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
|
|
42
33
|
{
|
|
43
34
|
include: [
|
|
44
|
-
|
|
35
|
+
/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
|
|
45
36
|
],
|
|
46
37
|
exclude: [
|
|
47
|
-
|
|
38
|
+
/[\\/]node_modules[\\/]/
|
|
48
39
|
],
|
|
49
40
|
...options.reactRefreshOptions
|
|
50
41
|
}
|
|
51
42
|
]);
|
|
52
43
|
});
|
|
53
|
-
}
|
|
54
|
-
const applyReactProfiler = (api)=>{
|
|
44
|
+
}, applyReactProfiler = (api)=>{
|
|
55
45
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
56
|
-
if ('production'
|
|
57
|
-
const enableProfilerConfig = {
|
|
46
|
+
if ('production' === config.mode) return mergeEnvironmentConfig(config, {
|
|
58
47
|
output: {
|
|
59
48
|
minify: {
|
|
60
49
|
jsOptions: {
|
|
61
50
|
minimizerOptions: {
|
|
62
|
-
// Need to keep classnames and function names like Components for debugging purposes.
|
|
63
51
|
mangle: {
|
|
64
|
-
keep_classnames:
|
|
65
|
-
keep_fnames:
|
|
52
|
+
keep_classnames: !0,
|
|
53
|
+
keep_fnames: !0
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
56
|
}
|
|
69
57
|
}
|
|
70
58
|
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
api.modifyBundlerChain((chain, { isProd })=>{
|
|
75
|
-
if (!isProd) return;
|
|
76
|
-
// Replace react-dom with the profiling version.
|
|
77
|
-
// Reference: https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
|
|
78
|
-
chain.resolve.alias.set('react-dom$', 'react-dom/profiling');
|
|
79
|
-
chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
|
|
59
|
+
});
|
|
60
|
+
}), api.modifyBundlerChain((chain, { isProd })=>{
|
|
61
|
+
if (!!isProd) chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling');
|
|
80
62
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
react: true,
|
|
85
|
-
router: true
|
|
63
|
+
}, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
|
|
64
|
+
react: !0,
|
|
65
|
+
router: !0
|
|
86
66
|
})=>{
|
|
87
67
|
api.modifyBundlerChain((chain, { environment, isProd })=>{
|
|
88
|
-
|
|
68
|
+
let { config } = environment;
|
|
89
69
|
if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
|
|
90
|
-
|
|
70
|
+
let currentConfig = chain.optimization.splitChunks.values();
|
|
91
71
|
if (!isPlainObject(currentConfig)) return;
|
|
92
|
-
|
|
93
|
-
if (options.react
|
|
72
|
+
let extraGroups = {};
|
|
73
|
+
if (options.react && (extraGroups.react = {
|
|
94
74
|
name: 'lib-react',
|
|
95
75
|
test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
|
|
96
76
|
priority: 0
|
|
97
|
-
}
|
|
98
|
-
if (options.router) extraGroups.router = {
|
|
77
|
+
}), options.router && (extraGroups.router = {
|
|
99
78
|
name: 'lib-router',
|
|
100
79
|
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
101
80
|
priority: 0
|
|
102
|
-
}
|
|
103
|
-
if (!Object.keys(extraGroups).length) return;
|
|
104
|
-
chain.optimization.splitChunks({
|
|
81
|
+
}), !!Object.keys(extraGroups).length) chain.optimization.splitChunks({
|
|
105
82
|
...currentConfig,
|
|
106
83
|
cacheGroups: {
|
|
107
|
-
// user defined cache groups take precedence
|
|
108
84
|
...extraGroups,
|
|
109
85
|
...currentConfig.cacheGroups
|
|
110
86
|
}
|
|
111
87
|
});
|
|
112
88
|
});
|
|
113
|
-
}
|
|
114
|
-
const PLUGIN_REACT_NAME = 'rsbuild:react';
|
|
115
|
-
const pluginReact = (options = {})=>({
|
|
89
|
+
}, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
|
|
116
90
|
name: PLUGIN_REACT_NAME,
|
|
117
91
|
setup (api) {
|
|
118
|
-
|
|
119
|
-
fastRefresh:
|
|
120
|
-
enableProfiler:
|
|
121
|
-
};
|
|
122
|
-
const finalOptions = {
|
|
123
|
-
...defaultOptions,
|
|
92
|
+
let finalOptions = {
|
|
93
|
+
fastRefresh: !0,
|
|
94
|
+
enableProfiler: !1,
|
|
124
95
|
...options
|
|
125
96
|
};
|
|
126
|
-
|
|
127
|
-
applyBasicReactSupport(api, finalOptions);
|
|
128
|
-
if (finalOptions.enableProfiler) applyReactProfiler(api);
|
|
129
|
-
}
|
|
130
|
-
applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
97
|
+
'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
131
98
|
}
|
|
132
99
|
});
|
|
133
100
|
export { PLUGIN_REACT_NAME, pluginReact };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@rspack/plugin-react-refresh": "~1.0.0",
|
|
26
|
-
"react-refresh": "^0.
|
|
26
|
+
"react-refresh": "^0.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
29
|
+
"@rslib/core": "0.1.3",
|
|
30
|
+
"@types/node": "^22.10.1",
|
|
31
|
+
"typescript": "^5.7.2",
|
|
32
|
+
"@rsbuild/core": "1.1.9",
|
|
32
33
|
"@scripts/test-helper": "1.0.1"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|