@rsbuild/plugin-react 0.1.3 → 0.1.4
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.d.ts +9 -2
- package/dist/index.js +22 -10
- package/dist/index.mjs +22 -10
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { RsbuildPlugin } from '@rsbuild/core';
|
|
|
2
2
|
|
|
3
3
|
declare const isBeyondReact17: (cwd: string) => Promise<boolean>;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type splitReactChunkOptions = {
|
|
6
|
+
react?: boolean;
|
|
7
|
+
router?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type PluginReactOptions = {
|
|
10
|
+
splitChunks?: splitReactChunkOptions;
|
|
11
|
+
};
|
|
12
|
+
declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
|
|
6
13
|
|
|
7
|
-
export { isBeyondReact17, pluginReact };
|
|
14
|
+
export { PluginReactOptions, isBeyondReact17, pluginReact, splitReactChunkOptions };
|
package/dist/index.js
CHANGED
|
@@ -104,36 +104,48 @@ var applyArcoSupport = (api) => {
|
|
|
104
104
|
|
|
105
105
|
// src/splitChunks.ts
|
|
106
106
|
var import_shared3 = require("@rsbuild/shared");
|
|
107
|
-
var applySplitChunksRule = (api) => {
|
|
107
|
+
var applySplitChunksRule = (api, options) => {
|
|
108
108
|
api.modifyBundlerChain((chain) => {
|
|
109
109
|
const config = api.getNormalizedConfig();
|
|
110
110
|
const { chunkSplit } = config.performance || {};
|
|
111
111
|
if (chunkSplit?.strategy !== "split-by-experience") {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
|
+
if (!options) {
|
|
115
|
+
options = {
|
|
116
|
+
react: true,
|
|
117
|
+
router: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
114
120
|
const currentConfig = chain.optimization.splitChunks.values();
|
|
115
121
|
if (!(0, import_shared3.isPlainObject)(currentConfig)) {
|
|
116
122
|
return;
|
|
117
123
|
}
|
|
118
|
-
const extraGroups =
|
|
119
|
-
|
|
124
|
+
const extraGroups = {};
|
|
125
|
+
if (options.react !== false) {
|
|
126
|
+
extraGroups.react = [
|
|
120
127
|
"react",
|
|
121
128
|
"react-dom",
|
|
122
129
|
"scheduler",
|
|
123
130
|
...(0, import_shared3.isProd)() ? [] : ["react-refresh", "@pmmmwh/react-refresh-webpack-plugin"]
|
|
124
|
-
]
|
|
125
|
-
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
if (options.router !== false) {
|
|
134
|
+
extraGroups.router = [
|
|
126
135
|
"react-router",
|
|
127
136
|
"react-router-dom",
|
|
128
137
|
"@remix-run/router",
|
|
129
138
|
"history"
|
|
130
|
-
]
|
|
131
|
-
}
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
if (!Object.keys(extraGroups).length) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
132
144
|
chain.optimization.splitChunks({
|
|
133
145
|
...currentConfig,
|
|
134
146
|
cacheGroups: {
|
|
135
147
|
...currentConfig.cacheGroups,
|
|
136
|
-
...extraGroups
|
|
148
|
+
...(0, import_shared3.createCacheGroups)(extraGroups)
|
|
137
149
|
}
|
|
138
150
|
});
|
|
139
151
|
});
|
|
@@ -228,7 +240,7 @@ var isBeyondReact17 = async (cwd) => {
|
|
|
228
240
|
};
|
|
229
241
|
|
|
230
242
|
// src/index.ts
|
|
231
|
-
var pluginReact = () => ({
|
|
243
|
+
var pluginReact = (options = {}) => ({
|
|
232
244
|
name: "rsbuild:react",
|
|
233
245
|
pre: ["rsbuild:swc"],
|
|
234
246
|
setup(api) {
|
|
@@ -237,7 +249,7 @@ var pluginReact = () => ({
|
|
|
237
249
|
}
|
|
238
250
|
applyAntdSupport(api);
|
|
239
251
|
applyArcoSupport(api);
|
|
240
|
-
applySplitChunksRule(api);
|
|
252
|
+
applySplitChunksRule(api, options?.splitChunks);
|
|
241
253
|
}
|
|
242
254
|
});
|
|
243
255
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -90,36 +90,48 @@ import {
|
|
|
90
90
|
isPlainObject,
|
|
91
91
|
createCacheGroups
|
|
92
92
|
} from "@rsbuild/shared";
|
|
93
|
-
var applySplitChunksRule = (api) => {
|
|
93
|
+
var applySplitChunksRule = (api, options) => {
|
|
94
94
|
api.modifyBundlerChain((chain) => {
|
|
95
95
|
const config = api.getNormalizedConfig();
|
|
96
96
|
const { chunkSplit } = config.performance || {};
|
|
97
97
|
if (chunkSplit?.strategy !== "split-by-experience") {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
+
if (!options) {
|
|
101
|
+
options = {
|
|
102
|
+
react: true,
|
|
103
|
+
router: true
|
|
104
|
+
};
|
|
105
|
+
}
|
|
100
106
|
const currentConfig = chain.optimization.splitChunks.values();
|
|
101
107
|
if (!isPlainObject(currentConfig)) {
|
|
102
108
|
return;
|
|
103
109
|
}
|
|
104
|
-
const extraGroups =
|
|
105
|
-
|
|
110
|
+
const extraGroups = {};
|
|
111
|
+
if (options.react !== false) {
|
|
112
|
+
extraGroups.react = [
|
|
106
113
|
"react",
|
|
107
114
|
"react-dom",
|
|
108
115
|
"scheduler",
|
|
109
116
|
...isProd() ? [] : ["react-refresh", "@pmmmwh/react-refresh-webpack-plugin"]
|
|
110
|
-
]
|
|
111
|
-
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
if (options.router !== false) {
|
|
120
|
+
extraGroups.router = [
|
|
112
121
|
"react-router",
|
|
113
122
|
"react-router-dom",
|
|
114
123
|
"@remix-run/router",
|
|
115
124
|
"history"
|
|
116
|
-
]
|
|
117
|
-
}
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
if (!Object.keys(extraGroups).length) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
118
130
|
chain.optimization.splitChunks({
|
|
119
131
|
...currentConfig,
|
|
120
132
|
cacheGroups: {
|
|
121
133
|
...currentConfig.cacheGroups,
|
|
122
|
-
...extraGroups
|
|
134
|
+
...createCacheGroups(extraGroups)
|
|
123
135
|
}
|
|
124
136
|
});
|
|
125
137
|
});
|
|
@@ -216,7 +228,7 @@ var isBeyondReact17 = async (cwd) => {
|
|
|
216
228
|
};
|
|
217
229
|
|
|
218
230
|
// src/index.ts
|
|
219
|
-
var pluginReact = () => ({
|
|
231
|
+
var pluginReact = (options = {}) => ({
|
|
220
232
|
name: "rsbuild:react",
|
|
221
233
|
pre: ["rsbuild:swc"],
|
|
222
234
|
setup(api) {
|
|
@@ -225,7 +237,7 @@ var pluginReact = () => ({
|
|
|
225
237
|
}
|
|
226
238
|
applyAntdSupport(api);
|
|
227
239
|
applyArcoSupport(api);
|
|
228
|
-
applySplitChunksRule(api);
|
|
240
|
+
applySplitChunksRule(api, options?.splitChunks);
|
|
229
241
|
}
|
|
230
242
|
});
|
|
231
243
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@rspack/plugin-react-refresh": "0.4.0",
|
|
24
|
+
"@rspack/plugin-react-refresh": "0.4.0-canary-d45e3e0-20231128075052",
|
|
25
25
|
"react-refresh": "^0.14.0",
|
|
26
26
|
"semver": "^7.5.4",
|
|
27
|
-
"@rsbuild/shared": "0.1.
|
|
27
|
+
"@rsbuild/shared": "0.1.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^16",
|
|
31
31
|
"@types/semver": "^7.5.4",
|
|
32
32
|
"typescript": "^5.3.0",
|
|
33
|
-
"@rsbuild/core": "0.1.
|
|
34
|
-
"@rsbuild/test-helper": "0.1.
|
|
33
|
+
"@rsbuild/core": "0.1.4",
|
|
34
|
+
"@rsbuild/test-helper": "0.1.4"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public",
|