@rsbuild/plugin-react 1.4.0 → 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 +121 -129
- package/dist/index.d.ts +4 -2
- package/dist/index.js +34 -28
- package/dist/splitChunks.d.ts +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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__ = '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_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,124 +19,130 @@ __webpack_require__.n = (module)=>{
|
|
|
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
|
-
jsc: {
|
|
61
|
-
parser: {
|
|
62
|
-
syntax: "typescript",
|
|
63
|
-
tsx: !0
|
|
64
|
-
},
|
|
65
|
-
transform: {
|
|
66
|
-
react: {
|
|
67
|
-
development: isDev,
|
|
68
|
-
refresh: usingHMR && options1.fastRefresh,
|
|
69
|
-
runtime: 'automatic',
|
|
70
|
-
...options1.swcReactOptions
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, config);
|
|
77
|
-
}), api2.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
78
|
-
let { config } = environment;
|
|
79
|
-
if (!(isDev && config.dev.hmr && 'web' === target) || !options1.fastRefresh) return;
|
|
80
|
-
chain.resolve.alias.set('react-refresh', external_node_path_default().dirname(REACT_REFRESH_PATH));
|
|
81
|
-
let { ReactRefreshRspackPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/plugin-react-refresh")), jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
|
|
82
|
-
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
|
|
83
|
-
{
|
|
84
|
-
test: jsRule.get('test'),
|
|
85
|
-
include: jsRule.include.values(),
|
|
86
|
-
exclude: jsRule.exclude.values(),
|
|
87
|
-
resourceQuery: {
|
|
88
|
-
not: /^\?raw$/
|
|
89
|
-
},
|
|
90
|
-
...options1.reactRefreshOptions
|
|
91
|
-
}
|
|
92
|
-
]);
|
|
93
|
-
}), finalOptions.enableProfiler && ((api1 = api).modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
94
|
-
if ('production' === config.mode) return mergeEnvironmentConfig(config, {
|
|
95
|
-
output: {
|
|
96
|
-
minify: {
|
|
97
|
-
jsOptions: {
|
|
98
|
-
minimizerOptions: {
|
|
99
|
-
mangle: {
|
|
100
|
-
keep_classnames: !0,
|
|
101
|
-
keep_fnames: !0
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}), api1.modifyBundlerChain((chain, { isProd })=>{
|
|
109
|
-
isProd && (chain.resolve.alias.set((()=>{
|
|
110
|
-
if (void 0 !== hasReactDomClientCache) return hasReactDomClientCache;
|
|
111
|
-
try {
|
|
112
|
-
react_require.resolve('react-dom/client', {
|
|
113
|
-
paths: [
|
|
114
|
-
api1.context.rootPath
|
|
115
|
-
]
|
|
116
|
-
}), hasReactDomClientCache = !0;
|
|
117
|
-
} catch {
|
|
118
|
-
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
|
|
119
46
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
123
49
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
|
147
86
|
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
151
90
|
}
|
|
152
91
|
});
|
|
153
|
-
})
|
|
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 === [
|
|
154
146
|
"PLUGIN_REACT_NAME",
|
|
155
147
|
"pluginReact"
|
|
156
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,14 +3,16 @@ 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
|
};
|
|
11
13
|
if ('rspack' === api.context.bundlerType) {
|
|
12
|
-
let
|
|
13
|
-
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
14
|
+
let REACT_REFRESH_PATH, hasReactDomClientCache;
|
|
15
|
+
REACT_REFRESH_PATH = finalOptions.fastRefresh ? react_require.resolve('react-refresh') : '', api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
|
|
14
16
|
let isDev = 'development' === config.mode, usingHMR = isDev && config.dev.hmr && 'web' === config.output.target;
|
|
15
17
|
return mergeEnvironmentConfig({
|
|
16
18
|
tools: {
|
|
@@ -32,6 +34,12 @@ let react_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
}, config);
|
|
37
|
+
}), finalOptions.swcReactOptions?.runtime === 'preserve' && api.modifyBundlerChain((chain)=>{
|
|
38
|
+
chain.module.parser.merge({
|
|
39
|
+
javascript: {
|
|
40
|
+
jsx: !0
|
|
41
|
+
}
|
|
42
|
+
});
|
|
35
43
|
}), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, target })=>{
|
|
36
44
|
let { config } = environment;
|
|
37
45
|
if (!(isDev && config.dev.hmr && 'web' === target) || !finalOptions.fastRefresh) return;
|
|
@@ -79,33 +87,31 @@ let react_require = createRequire(import.meta.url), PLUGIN_REACT_NAME = 'rsbuild
|
|
|
79
87
|
})() ? 'react-dom/client$' : 'react-dom$', 'react-dom/profiling'), chain.resolve.alias.set('scheduler/tracing', 'scheduler/tracing-profiling'));
|
|
80
88
|
}));
|
|
81
89
|
}
|
|
82
|
-
((
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
});
|
|
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
|
+
}
|
|
107
113
|
});
|
|
108
|
-
})
|
|
114
|
+
});
|
|
109
115
|
}
|
|
110
116
|
});
|
|
111
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.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.
|
|
26
|
-
"react-refresh": "^0.
|
|
25
|
+
"@rspack/plugin-react-refresh": "^1.5.2",
|
|
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.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": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rslib build",
|
|
44
|
-
"dev": "rslib build
|
|
44
|
+
"dev": "rslib build -w",
|
|
45
45
|
"bump": "pnpx bumpp --no-tag"
|
|
46
46
|
}
|
|
47
47
|
}
|