@rsbuild/plugin-react 1.1.0 → 1.1.1
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 +11 -11
- package/dist/index.cjs +95 -93
- package/dist/index.js +15 -15
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
|
|
3
|
-
</p>
|
|
1
|
+
# @rsbuild/plugin-react
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
An Rsbuild plugin to provide support for React, integrating features such as JSX compilation and React Refresh.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://npmjs.com/package/@rsbuild/plugin-react">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-react?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
|
+
</a>
|
|
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?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-react.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
11
|
+
</p>
|
|
8
12
|
|
|
9
13
|
## Documentation
|
|
10
14
|
|
|
11
|
-
https://rsbuild.dev/
|
|
12
|
-
|
|
13
|
-
## Contributing
|
|
14
|
-
|
|
15
|
-
Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
|
|
15
|
+
See [Documentation](https://rsbuild.dev/plugins/list/plugin-react).
|
|
16
16
|
|
|
17
17
|
## License
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
[MIT](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -37,109 +37,111 @@ __webpack_require__.n = function(module) {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
var __webpack_exports__ = {};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
development
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
pluginReact: ()=>pluginReact,
|
|
43
|
+
PLUGIN_REACT_NAME: ()=>PLUGIN_REACT_NAME
|
|
44
|
+
});
|
|
45
|
+
let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
|
|
46
|
+
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
47
|
+
let react_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), applyBasicReactSupport = (api, options)=>{
|
|
48
|
+
let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
49
|
+
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
50
|
+
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
|
|
51
|
+
return mergeEnvironmentConfig({
|
|
52
|
+
tools: {
|
|
53
|
+
swc: {
|
|
54
|
+
jsc: {
|
|
55
|
+
parser: {
|
|
56
|
+
syntax: "typescript",
|
|
57
|
+
tsx: !0
|
|
58
|
+
},
|
|
59
|
+
transform: {
|
|
60
|
+
react: {
|
|
61
|
+
development: isDev,
|
|
62
|
+
refresh: usingHMR && options.fastRefresh,
|
|
63
|
+
runtime: 'automatic',
|
|
64
|
+
...options.swcReactOptions
|
|
65
|
+
}
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
70
|
+
}, config);
|
|
71
|
+
}), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
72
|
+
let { config } = environment;
|
|
73
|
+
if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
|
|
74
|
+
chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
|
|
75
|
+
let { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh"));
|
|
76
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
|
|
77
|
+
{
|
|
78
|
+
include: [
|
|
79
|
+
/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
|
|
80
|
+
],
|
|
81
|
+
exclude: [
|
|
82
|
+
/[\\/]node_modules[\\/]/
|
|
83
|
+
],
|
|
84
|
+
...options.reactRefreshOptions
|
|
85
|
+
}
|
|
86
|
+
]);
|
|
87
|
+
});
|
|
88
|
+
}, applyReactProfiler = (api)=>{
|
|
89
|
+
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
90
|
+
if ('production' === config.mode) return mergeEnvironmentConfig(config, {
|
|
91
|
+
output: {
|
|
92
|
+
minify: {
|
|
93
|
+
jsOptions: {
|
|
94
|
+
minimizerOptions: {
|
|
95
|
+
mangle: {
|
|
96
|
+
keep_classnames: !0,
|
|
97
|
+
keep_fnames: !0
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
|
-
}
|
|
103
|
+
});
|
|
104
|
+
}), api.modifyBundlerChain((chain, { isProd })=>{
|
|
105
|
+
isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
|
|
102
106
|
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
}, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
|
|
108
|
+
react: !0,
|
|
109
|
+
router: !0
|
|
110
|
+
})=>{
|
|
111
|
+
api.modifyBundlerChain((chain, { environment, isProd })=>{
|
|
112
|
+
let { config } = environment;
|
|
113
|
+
if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
|
|
114
|
+
let currentConfig = chain.optimization.splitChunks.values();
|
|
115
|
+
if (!isPlainObject(currentConfig)) return;
|
|
116
|
+
let extraGroups = {};
|
|
117
|
+
options.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
|
+
}), options.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
|
+
enableProfiler: !1,
|
|
139
|
+
...options
|
|
140
|
+
};
|
|
141
|
+
'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
129
142
|
}
|
|
130
143
|
});
|
|
131
|
-
|
|
132
|
-
}, PLUGIN_REACT_NAME = 'rsbuild:react', pluginReact = (options = {})=>({
|
|
133
|
-
name: PLUGIN_REACT_NAME,
|
|
134
|
-
setup (api) {
|
|
135
|
-
let finalOptions = {
|
|
136
|
-
fastRefresh: !0,
|
|
137
|
-
enableProfiler: !1,
|
|
138
|
-
...options
|
|
139
|
-
};
|
|
140
|
-
'rspack' === api.context.bundlerType && (applyBasicReactSupport(api, finalOptions), finalOptions.enableProfiler && applyReactProfiler(api)), applySplitChunksRule(api, null == finalOptions ? void 0 : finalOptions.splitChunks);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
144
|
+
})();
|
|
143
145
|
var __webpack_export_target__ = exports;
|
|
144
146
|
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
145
147
|
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
let react_require = (0,
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
3
|
+
let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), applyBasicReactSupport = (api, options)=>{
|
|
4
4
|
let REACT_REFRESH_PATH = options.fastRefresh ? react_require.resolve('react-refresh') : '';
|
|
5
5
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
6
|
-
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target
|
|
7
|
-
development: isDev,
|
|
8
|
-
refresh: usingHMR && options.fastRefresh,
|
|
9
|
-
runtime: 'automatic',
|
|
10
|
-
...options.swcReactOptions
|
|
11
|
-
};
|
|
6
|
+
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
|
|
12
7
|
return mergeEnvironmentConfig({
|
|
13
8
|
tools: {
|
|
14
9
|
swc: {
|
|
15
10
|
jsc: {
|
|
16
11
|
parser: {
|
|
17
|
-
syntax:
|
|
12
|
+
syntax: "typescript",
|
|
18
13
|
tsx: !0
|
|
19
14
|
},
|
|
20
15
|
transform: {
|
|
21
|
-
react:
|
|
16
|
+
react: {
|
|
17
|
+
development: isDev,
|
|
18
|
+
refresh: usingHMR && options.fastRefresh,
|
|
19
|
+
runtime: 'automatic',
|
|
20
|
+
...options.swcReactOptions
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
|
|
|
27
27
|
}), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
28
28
|
let { config } = environment;
|
|
29
29
|
if (!(isDev && config.dev.hmr && 'web' === target) || !options.fastRefresh) return;
|
|
30
|
-
chain.resolve.alias.set('react-refresh',
|
|
30
|
+
chain.resolve.alias.set('react-refresh', __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(REACT_REFRESH_PATH));
|
|
31
31
|
let { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
32
32
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
|
|
33
33
|
{
|
|
@@ -58,7 +58,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}), api.modifyBundlerChain((chain, { isProd })=>{
|
|
61
|
-
|
|
61
|
+
isProd && (chain.resolve.alias.set('react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
|
|
62
62
|
});
|
|
63
63
|
}, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj), applySplitChunksRule = (api, options = {
|
|
64
64
|
react: !0,
|
|
@@ -70,7 +70,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
|
|
|
70
70
|
let currentConfig = chain.optimization.splitChunks.values();
|
|
71
71
|
if (!isPlainObject(currentConfig)) return;
|
|
72
72
|
let extraGroups = {};
|
|
73
|
-
|
|
73
|
+
options.react && (extraGroups.react = {
|
|
74
74
|
name: 'lib-react',
|
|
75
75
|
test: isProd ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
|
|
76
76
|
priority: 0
|
|
@@ -78,7 +78,7 @@ let react_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(i
|
|
|
78
78
|
name: 'lib-router',
|
|
79
79
|
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
80
80
|
priority: 0
|
|
81
|
-
}),
|
|
81
|
+
}), Object.keys(extraGroups).length && chain.optimization.splitChunks({
|
|
82
82
|
...currentConfig,
|
|
83
83
|
cacheGroups: {
|
|
84
84
|
...extraGroups,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rspack/plugin-react-refresh": "~1.0.
|
|
25
|
+
"@rspack/plugin-react-refresh": "~1.0.1",
|
|
26
26
|
"react-refresh": "^0.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rslib/core": "0.1
|
|
30
|
-
"@types/node": "^22.
|
|
31
|
-
"typescript": "^5.7.
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
29
|
+
"@rslib/core": "0.4.1",
|
|
30
|
+
"@types/node": "^22.13.4",
|
|
31
|
+
"typescript": "^5.7.3",
|
|
32
|
+
"@scripts/test-helper": "1.0.1",
|
|
33
|
+
"@rsbuild/core": "1.2.9"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@rsbuild/core": "1.x"
|