@rsbuild/plugin-react 1.4.1 → 1.4.3
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/README.md +1 -1
- package/dist/index.cjs +123 -136
- package/dist/index.d.ts +4 -2
- package/dist/index.js +26 -26
- package/dist/splitChunks.d.ts +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ An Rsbuild plugin to provide support for React, integrating features such as JSX
|
|
|
7
7
|
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-react?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
8
|
</a>
|
|
9
9
|
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
10
|
-
<a href="https://npmcharts.com/compare/@rsbuild/plugin-react
|
|
10
|
+
<a href="https://npmcharts.com/compare/@rsbuild/plugin-react"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-react.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
## Documentation
|
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ =
|
|
3
|
-
var
|
|
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
|
-
}
|
|
2
|
+
const __rslib_import_meta_url__ = "u" < 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_require__ = {};
|
|
18
4
|
__webpack_require__.n = (module)=>{
|
|
19
5
|
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
20
6
|
return __webpack_require__.d(getter, {
|
|
@@ -26,139 +12,140 @@ __webpack_require__.n = (module)=>{
|
|
|
26
12
|
get: definition[key]
|
|
27
13
|
});
|
|
28
14
|
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
29
|
-
|
|
15
|
+
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
16
|
value: 'Module'
|
|
31
17
|
}), Object.defineProperty(exports1, '__esModule', {
|
|
32
18
|
value: !0
|
|
33
19
|
});
|
|
34
20
|
};
|
|
35
21
|
var __webpack_exports__ = {};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
128
49
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
156
90
|
}
|
|
157
91
|
});
|
|
158
|
-
})
|
|
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 __rspack_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
|
-
].indexOf(
|
|
148
|
+
].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
|
|
162
149
|
Object.defineProperty(exports, '__esModule', {
|
|
163
150
|
value: !0
|
|
164
151
|
});
|
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
|
-
((
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
})
|
|
114
|
+
});
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
117
|
export { PLUGIN_REACT_NAME, pluginReact };
|
package/dist/splitChunks.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rspack/plugin-react-refresh": "^1.5.
|
|
26
|
-
"react-refresh": "^0.
|
|
25
|
+
"@rspack/plugin-react-refresh": "^1.5.3",
|
|
26
|
+
"react-refresh": "^0.18.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rslib/core": "0.
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"typescript": "^5.9.
|
|
32
|
-
"@rsbuild/core": "1.
|
|
29
|
+
"@rslib/core": "0.19.1",
|
|
30
|
+
"@types/node": "^24.10.4",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"@rsbuild/core": "1.7.2",
|
|
33
33
|
"@scripts/test-helper": "1.0.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@rsbuild/core": "1.
|
|
36
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|