@rsbuild/plugin-react 0.0.0-next-20231108034054 → 0.0.0-next-20231207110454
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 +14 -2
- package/dist/index.js +223 -11
- package/dist/index.mjs +242 -0
- package/package.json +10 -6
- package/dist/antd.d.ts +0 -2
- package/dist/antd.js +0 -62
- package/dist/arco.d.ts +0 -2
- package/dist/arco.js +0 -56
- package/dist/react.d.ts +0 -2
- package/dist/react.js +0 -107
- package/dist/splitChunks.d.ts +0 -3
- package/dist/splitChunks.js +0 -81
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
declare const isBeyondReact17: (cwd: string) => Promise<boolean>;
|
|
4
|
+
|
|
5
|
+
type SplitReactChunkOptions = {
|
|
6
|
+
react?: boolean;
|
|
7
|
+
router?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type PluginReactOptions = {
|
|
10
|
+
splitChunks?: SplitReactChunkOptions;
|
|
11
|
+
};
|
|
12
|
+
declare const pluginReact: (options?: PluginReactOptions) => RsbuildPlugin;
|
|
13
|
+
|
|
14
|
+
export { PluginReactOptions, SplitReactChunkOptions, isBeyondReact17, pluginReact };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,29 +17,239 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
19
31
|
var src_exports = {};
|
|
20
32
|
__export(src_exports, {
|
|
33
|
+
isBeyondReact17: () => isBeyondReact17,
|
|
21
34
|
pluginReact: () => pluginReact
|
|
22
35
|
});
|
|
23
36
|
module.exports = __toCommonJS(src_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
|
|
38
|
+
// src/antd.ts
|
|
39
|
+
var import_shared = require("@rsbuild/shared");
|
|
40
|
+
var getAntdMajorVersion = (appDirectory) => {
|
|
41
|
+
try {
|
|
42
|
+
const pkgJsonPath = require.resolve("antd/package.json", {
|
|
43
|
+
paths: [appDirectory]
|
|
44
|
+
});
|
|
45
|
+
const { version } = require(pkgJsonPath);
|
|
46
|
+
return Number(version.split(".")[0]);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var applyAntdSupport = (api) => {
|
|
52
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
53
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
54
|
+
if (rsbuildConfig.source.transformImport === false || rsbuildConfig.source.transformImport?.some(
|
|
55
|
+
(item) => item.libraryName === "antd"
|
|
56
|
+
)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
|
|
60
|
+
if (antdMajorVersion && antdMajorVersion < 5) {
|
|
61
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
62
|
+
rsbuildConfig.source.transformImport = [
|
|
63
|
+
...rsbuildConfig.source.transformImport || [],
|
|
64
|
+
{
|
|
65
|
+
libraryName: "antd",
|
|
66
|
+
libraryDirectory: (0, import_shared.isServerTarget)(api.context.target) ? "lib" : "es",
|
|
67
|
+
style: true
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/arco.ts
|
|
75
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
76
|
+
var applyArcoSupport = (api) => {
|
|
77
|
+
const ARCO_NAME = "@arco-design/web-react";
|
|
78
|
+
const ARCO_ICON = `${ARCO_NAME}/icon`;
|
|
79
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
80
|
+
const { transformImport = [] } = rsbuildConfig.source || {};
|
|
81
|
+
if (transformImport === false || !(0, import_shared2.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const isUseSSR = (0, import_shared2.isServerTarget)(api.context.target);
|
|
85
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_NAME)) {
|
|
86
|
+
transformImport.push({
|
|
87
|
+
libraryName: ARCO_NAME,
|
|
88
|
+
libraryDirectory: isUseSSR ? "lib" : "es",
|
|
89
|
+
camelToDashComponentName: false,
|
|
90
|
+
style: true
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_ICON)) {
|
|
94
|
+
transformImport.push({
|
|
95
|
+
libraryName: ARCO_ICON,
|
|
96
|
+
libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
|
|
97
|
+
camelToDashComponentName: false
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
rsbuildConfig.source || (rsbuildConfig.source = {});
|
|
101
|
+
rsbuildConfig.source.transformImport = transformImport;
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/splitChunks.ts
|
|
106
|
+
var import_shared3 = require("@rsbuild/shared");
|
|
107
|
+
var applySplitChunksRule = (api, options = {
|
|
108
|
+
react: true,
|
|
109
|
+
router: true
|
|
110
|
+
}) => {
|
|
111
|
+
api.modifyBundlerChain((chain) => {
|
|
112
|
+
const config = api.getNormalizedConfig();
|
|
113
|
+
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const currentConfig = chain.optimization.splitChunks.values();
|
|
117
|
+
if (!(0, import_shared3.isPlainObject)(currentConfig)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const extraGroups = {};
|
|
121
|
+
if (options.react) {
|
|
122
|
+
extraGroups.react = [
|
|
123
|
+
"react",
|
|
124
|
+
"react-dom",
|
|
125
|
+
"scheduler",
|
|
126
|
+
...(0, import_shared3.isProd)() ? [] : ["react-refresh", "@rspack/plugin-react-refresh"]
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
if (options.router) {
|
|
130
|
+
extraGroups.router = [
|
|
131
|
+
"react-router",
|
|
132
|
+
"react-router-dom",
|
|
133
|
+
"@remix-run/router",
|
|
134
|
+
"history"
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
if (!Object.keys(extraGroups).length) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
chain.optimization.splitChunks({
|
|
141
|
+
...currentConfig,
|
|
142
|
+
cacheGroups: {
|
|
143
|
+
...currentConfig.cacheGroups,
|
|
144
|
+
...(0, import_shared3.createCacheGroups)(extraGroups)
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/react.ts
|
|
151
|
+
var import_shared4 = require("@rsbuild/shared");
|
|
152
|
+
function getReactRefreshEntry(compiler) {
|
|
153
|
+
const hot = compiler.options.devServer?.hot ?? true;
|
|
154
|
+
const refresh = compiler.options.builtins?.react?.refresh ?? true;
|
|
155
|
+
if (hot && refresh) {
|
|
156
|
+
const reactRefreshEntryPath = require.resolve("@rspack/plugin-react-refresh/react-refresh-entry");
|
|
157
|
+
return reactRefreshEntryPath;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
var setupCompiler = (compiler) => {
|
|
162
|
+
if (!(0, import_shared4.isClientCompiler)(compiler)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
166
|
+
if (!reactRefreshEntry) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
for (const key in compiler.options.entry) {
|
|
170
|
+
compiler.options.entry[key].import = [
|
|
171
|
+
reactRefreshEntry,
|
|
172
|
+
...compiler.options.entry[key].import || []
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var applyBasicReactSupport = (api) => {
|
|
177
|
+
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
178
|
+
if ((0, import_shared4.isProd)()) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (multiCompiler.compilers) {
|
|
182
|
+
multiCompiler.compilers.forEach(setupCompiler);
|
|
183
|
+
} else {
|
|
184
|
+
setupCompiler(multiCompiler);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
188
|
+
const config = api.getNormalizedConfig();
|
|
189
|
+
const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd: isProd3, target });
|
|
190
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
191
|
+
const reactOptions = {
|
|
192
|
+
development: !isProd3,
|
|
193
|
+
refresh: usingHMR,
|
|
194
|
+
runtime: "automatic"
|
|
195
|
+
};
|
|
196
|
+
rule.use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
197
|
+
options.jsc.transform.react = {
|
|
198
|
+
...reactOptions
|
|
199
|
+
};
|
|
200
|
+
return options;
|
|
201
|
+
});
|
|
202
|
+
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
203
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
204
|
+
options.jsc.transform.react = {
|
|
205
|
+
...reactOptions
|
|
206
|
+
};
|
|
207
|
+
return options;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (!usingHMR) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
214
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/utils.ts
|
|
219
|
+
var import_fs = __toESM(require("fs"));
|
|
220
|
+
var import_semver = __toESM(require("semver"));
|
|
221
|
+
var import_shared5 = require("@rsbuild/shared");
|
|
222
|
+
var isBeyondReact17 = async (cwd) => {
|
|
223
|
+
const pkgPath = await (0, import_shared5.findUp)({ cwd, filename: "package.json" });
|
|
224
|
+
if (!pkgPath) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const pkgInfo = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
|
|
228
|
+
const deps = {
|
|
229
|
+
...pkgInfo.devDependencies,
|
|
230
|
+
...pkgInfo.dependencies
|
|
231
|
+
};
|
|
232
|
+
if (typeof deps.react !== "string") {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return import_semver.default.satisfies(import_semver.default.minVersion(deps.react), ">=17.0.0");
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/index.ts
|
|
239
|
+
var pluginReact = (options = {}) => ({
|
|
240
|
+
name: "rsbuild:react",
|
|
241
|
+
pre: ["rsbuild:swc"],
|
|
31
242
|
setup(api) {
|
|
32
243
|
if (api.context.bundlerType === "rspack") {
|
|
33
|
-
|
|
244
|
+
applyBasicReactSupport(api);
|
|
34
245
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(
|
|
246
|
+
applyAntdSupport(api);
|
|
247
|
+
applyArcoSupport(api);
|
|
248
|
+
applySplitChunksRule(api, options?.splitChunks);
|
|
38
249
|
}
|
|
39
250
|
});
|
|
40
251
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
252
|
0 && (module.exports = {
|
|
253
|
+
isBeyondReact17,
|
|
42
254
|
pluginReact
|
|
43
255
|
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.41.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import path from "path";
|
|
12
|
+
|
|
13
|
+
// ../../scripts/requireShims.js
|
|
14
|
+
import { createRequire } from "module";
|
|
15
|
+
global.require = createRequire(import.meta.url);
|
|
16
|
+
|
|
17
|
+
// src/antd.ts
|
|
18
|
+
import { isServerTarget } from "@rsbuild/shared";
|
|
19
|
+
var getAntdMajorVersion = (appDirectory) => {
|
|
20
|
+
try {
|
|
21
|
+
const pkgJsonPath = __require.resolve("antd/package.json", {
|
|
22
|
+
paths: [appDirectory]
|
|
23
|
+
});
|
|
24
|
+
const { version } = __require(pkgJsonPath);
|
|
25
|
+
return Number(version.split(".")[0]);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var applyAntdSupport = (api) => {
|
|
31
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
32
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
33
|
+
if (rsbuildConfig.source.transformImport === false || rsbuildConfig.source.transformImport?.some(
|
|
34
|
+
(item) => item.libraryName === "antd"
|
|
35
|
+
)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
|
|
39
|
+
if (antdMajorVersion && antdMajorVersion < 5) {
|
|
40
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
41
|
+
rsbuildConfig.source.transformImport = [
|
|
42
|
+
...rsbuildConfig.source.transformImport || [],
|
|
43
|
+
{
|
|
44
|
+
libraryName: "antd",
|
|
45
|
+
libraryDirectory: isServerTarget(api.context.target) ? "lib" : "es",
|
|
46
|
+
style: true
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/arco.ts
|
|
54
|
+
import {
|
|
55
|
+
isServerTarget as isServerTarget2,
|
|
56
|
+
isPackageInstalled
|
|
57
|
+
} from "@rsbuild/shared";
|
|
58
|
+
var applyArcoSupport = (api) => {
|
|
59
|
+
const ARCO_NAME = "@arco-design/web-react";
|
|
60
|
+
const ARCO_ICON = `${ARCO_NAME}/icon`;
|
|
61
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
62
|
+
const { transformImport = [] } = rsbuildConfig.source || {};
|
|
63
|
+
if (transformImport === false || !isPackageInstalled(ARCO_NAME, api.context.rootPath)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const isUseSSR = isServerTarget2(api.context.target);
|
|
67
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_NAME)) {
|
|
68
|
+
transformImport.push({
|
|
69
|
+
libraryName: ARCO_NAME,
|
|
70
|
+
libraryDirectory: isUseSSR ? "lib" : "es",
|
|
71
|
+
camelToDashComponentName: false,
|
|
72
|
+
style: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_ICON)) {
|
|
76
|
+
transformImport.push({
|
|
77
|
+
libraryName: ARCO_ICON,
|
|
78
|
+
libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
|
|
79
|
+
camelToDashComponentName: false
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
rsbuildConfig.source || (rsbuildConfig.source = {});
|
|
83
|
+
rsbuildConfig.source.transformImport = transformImport;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/splitChunks.ts
|
|
88
|
+
import {
|
|
89
|
+
isProd,
|
|
90
|
+
isPlainObject,
|
|
91
|
+
createCacheGroups
|
|
92
|
+
} from "@rsbuild/shared";
|
|
93
|
+
var applySplitChunksRule = (api, options = {
|
|
94
|
+
react: true,
|
|
95
|
+
router: true
|
|
96
|
+
}) => {
|
|
97
|
+
api.modifyBundlerChain((chain) => {
|
|
98
|
+
const config = api.getNormalizedConfig();
|
|
99
|
+
if (config.performance.chunkSplit.strategy !== "split-by-experience") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const currentConfig = chain.optimization.splitChunks.values();
|
|
103
|
+
if (!isPlainObject(currentConfig)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const extraGroups = {};
|
|
107
|
+
if (options.react) {
|
|
108
|
+
extraGroups.react = [
|
|
109
|
+
"react",
|
|
110
|
+
"react-dom",
|
|
111
|
+
"scheduler",
|
|
112
|
+
...isProd() ? [] : ["react-refresh", "@rspack/plugin-react-refresh"]
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
if (options.router) {
|
|
116
|
+
extraGroups.router = [
|
|
117
|
+
"react-router",
|
|
118
|
+
"react-router-dom",
|
|
119
|
+
"@remix-run/router",
|
|
120
|
+
"history"
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
if (!Object.keys(extraGroups).length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
chain.optimization.splitChunks({
|
|
127
|
+
...currentConfig,
|
|
128
|
+
cacheGroups: {
|
|
129
|
+
...currentConfig.cacheGroups,
|
|
130
|
+
...createCacheGroups(extraGroups)
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/react.ts
|
|
137
|
+
import { isUsingHMR, isClientCompiler, isProd as isProd2 } from "@rsbuild/shared";
|
|
138
|
+
function getReactRefreshEntry(compiler) {
|
|
139
|
+
const hot = compiler.options.devServer?.hot ?? true;
|
|
140
|
+
const refresh = compiler.options.builtins?.react?.refresh ?? true;
|
|
141
|
+
if (hot && refresh) {
|
|
142
|
+
const reactRefreshEntryPath = __require.resolve(
|
|
143
|
+
"@rspack/plugin-react-refresh/react-refresh-entry"
|
|
144
|
+
);
|
|
145
|
+
return reactRefreshEntryPath;
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
var setupCompiler = (compiler) => {
|
|
150
|
+
if (!isClientCompiler(compiler)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
154
|
+
if (!reactRefreshEntry) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
for (const key in compiler.options.entry) {
|
|
158
|
+
compiler.options.entry[key].import = [
|
|
159
|
+
reactRefreshEntry,
|
|
160
|
+
...compiler.options.entry[key].import || []
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var applyBasicReactSupport = (api) => {
|
|
165
|
+
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
166
|
+
if (isProd2()) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (multiCompiler.compilers) {
|
|
170
|
+
multiCompiler.compilers.forEach(setupCompiler);
|
|
171
|
+
} else {
|
|
172
|
+
setupCompiler(multiCompiler);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
176
|
+
const config = api.getNormalizedConfig();
|
|
177
|
+
const usingHMR = isUsingHMR(config, { isProd: isProd3, target });
|
|
178
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
179
|
+
const reactOptions = {
|
|
180
|
+
development: !isProd3,
|
|
181
|
+
refresh: usingHMR,
|
|
182
|
+
runtime: "automatic"
|
|
183
|
+
};
|
|
184
|
+
rule.use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
185
|
+
options.jsc.transform.react = {
|
|
186
|
+
...reactOptions
|
|
187
|
+
};
|
|
188
|
+
return options;
|
|
189
|
+
});
|
|
190
|
+
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
191
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
192
|
+
options.jsc.transform.react = {
|
|
193
|
+
...reactOptions
|
|
194
|
+
};
|
|
195
|
+
return options;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (!usingHMR) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
202
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/utils.ts
|
|
207
|
+
import fs from "fs";
|
|
208
|
+
import semver from "semver";
|
|
209
|
+
import { findUp } from "@rsbuild/shared";
|
|
210
|
+
var isBeyondReact17 = async (cwd) => {
|
|
211
|
+
const pkgPath = await findUp({ cwd, filename: "package.json" });
|
|
212
|
+
if (!pkgPath) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
216
|
+
const deps = {
|
|
217
|
+
...pkgInfo.devDependencies,
|
|
218
|
+
...pkgInfo.dependencies
|
|
219
|
+
};
|
|
220
|
+
if (typeof deps.react !== "string") {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/index.ts
|
|
227
|
+
var pluginReact = (options = {}) => ({
|
|
228
|
+
name: "rsbuild:react",
|
|
229
|
+
pre: ["rsbuild:swc"],
|
|
230
|
+
setup(api) {
|
|
231
|
+
if (api.context.bundlerType === "rspack") {
|
|
232
|
+
applyBasicReactSupport(api);
|
|
233
|
+
}
|
|
234
|
+
applyAntdSupport(api);
|
|
235
|
+
applyArcoSupport(api);
|
|
236
|
+
applySplitChunksRule(api, options?.splitChunks);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
export {
|
|
240
|
+
isBeyondReact17,
|
|
241
|
+
pluginReact
|
|
242
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20231207110454",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
"directory": "packages/plugin-react"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"type": "commonjs",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
14
16
|
"default": "./dist/index.js"
|
|
15
17
|
}
|
|
16
18
|
},
|
|
@@ -20,15 +22,17 @@
|
|
|
20
22
|
"dist"
|
|
21
23
|
],
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"@rspack/plugin-react-refresh": "0.
|
|
25
|
+
"@rspack/plugin-react-refresh": "0.4.2",
|
|
24
26
|
"react-refresh": "^0.14.0",
|
|
25
|
-
"
|
|
27
|
+
"semver": "^7.5.4",
|
|
28
|
+
"@rsbuild/shared": "0.0.0-next-20231207110454"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@types/node": "^16",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"@rsbuild/
|
|
32
|
+
"@types/semver": "^7.5.4",
|
|
33
|
+
"typescript": "^5.3.0",
|
|
34
|
+
"@rsbuild/core": "0.0.0-next-20231207110454",
|
|
35
|
+
"@rsbuild/test-helper": "0.0.0-next-20231207110454"
|
|
32
36
|
},
|
|
33
37
|
"publishConfig": {
|
|
34
38
|
"access": "public",
|
package/dist/antd.d.ts
DELETED
package/dist/antd.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var antd_exports = {};
|
|
20
|
-
__export(antd_exports, {
|
|
21
|
-
applyAntdSupport: () => applyAntdSupport
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(antd_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
|
-
const getAntdMajorVersion = (appDirectory) => {
|
|
26
|
-
try {
|
|
27
|
-
const pkgJsonPath = require.resolve("antd/package.json", {
|
|
28
|
-
paths: [appDirectory]
|
|
29
|
-
});
|
|
30
|
-
const { version } = require(pkgJsonPath);
|
|
31
|
-
return Number(version.split(".")[0]);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const applyAntdSupport = (api) => {
|
|
37
|
-
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
-
(_a = rsbuildConfig.source) != null ? _a : rsbuildConfig.source = {};
|
|
40
|
-
if (rsbuildConfig.source.transformImport === false || ((_b = rsbuildConfig.source.transformImport) == null ? void 0 : _b.some(
|
|
41
|
-
(item) => item.libraryName === "antd"
|
|
42
|
-
))) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
|
|
46
|
-
if (antdMajorVersion && antdMajorVersion < 5) {
|
|
47
|
-
(_c = rsbuildConfig.source) != null ? _c : rsbuildConfig.source = {};
|
|
48
|
-
rsbuildConfig.source.transformImport = [
|
|
49
|
-
...rsbuildConfig.source.transformImport || [],
|
|
50
|
-
{
|
|
51
|
-
libraryName: "antd",
|
|
52
|
-
libraryDirectory: (0, import_shared.useSSR)(api.context.target) ? "lib" : "es",
|
|
53
|
-
style: true
|
|
54
|
-
}
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
-
0 && (module.exports = {
|
|
61
|
-
applyAntdSupport
|
|
62
|
-
});
|
package/dist/arco.d.ts
DELETED
package/dist/arco.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var arco_exports = {};
|
|
20
|
-
__export(arco_exports, {
|
|
21
|
-
applyArcoSupport: () => applyArcoSupport
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(arco_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
|
-
const applyArcoSupport = (api) => {
|
|
26
|
-
const ARCO_NAME = "@arco-design/web-react";
|
|
27
|
-
const ARCO_ICON = `${ARCO_NAME}/icon`;
|
|
28
|
-
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
29
|
-
const { transformImport = [] } = rsbuildConfig.source || {};
|
|
30
|
-
if (transformImport === false || !(0, import_shared.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const isUseSSR = (0, import_shared.useSSR)(api.context.target);
|
|
34
|
-
if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
|
|
35
|
-
transformImport.push({
|
|
36
|
-
libraryName: ARCO_NAME,
|
|
37
|
-
libraryDirectory: isUseSSR ? "lib" : "es",
|
|
38
|
-
camelToDashComponentName: false,
|
|
39
|
-
style: true
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (!(transformImport == null ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
|
|
43
|
-
transformImport.push({
|
|
44
|
-
libraryName: ARCO_ICON,
|
|
45
|
-
libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
|
|
46
|
-
camelToDashComponentName: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
rsbuildConfig.source || (rsbuildConfig.source = {});
|
|
50
|
-
rsbuildConfig.source.transformImport = transformImport;
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
-
0 && (module.exports = {
|
|
55
|
-
applyArcoSupport
|
|
56
|
-
});
|
package/dist/react.d.ts
DELETED
package/dist/react.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var react_exports = {};
|
|
30
|
-
__export(react_exports, {
|
|
31
|
-
applyBasicReactSupport: () => applyBasicReactSupport
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(react_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
function getReactRefreshEntry(compiler) {
|
|
36
|
-
var _a, _b, _c, _d, _e;
|
|
37
|
-
const hot = (_b = (_a = compiler.options.devServer) == null ? void 0 : _a.hot) != null ? _b : true;
|
|
38
|
-
const refresh = (_e = (_d = (_c = compiler.options.builtins) == null ? void 0 : _c.react) == null ? void 0 : _d.refresh) != null ? _e : true;
|
|
39
|
-
if (hot && refresh) {
|
|
40
|
-
const reactRefreshEntryPath = require.resolve("@rspack/plugin-react-refresh/react-refresh-entry");
|
|
41
|
-
return reactRefreshEntryPath;
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const setupCompiler = (compiler) => {
|
|
46
|
-
if (!(0, import_shared.isClientCompiler)(compiler)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
50
|
-
if (!reactRefreshEntry) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
for (const key in compiler.options.entry) {
|
|
54
|
-
compiler.options.entry[key].import = [
|
|
55
|
-
reactRefreshEntry,
|
|
56
|
-
...compiler.options.entry[key].import || []
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const applyBasicReactSupport = (api) => {
|
|
61
|
-
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
62
|
-
if ((0, import_shared.isProd)()) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (multiCompiler.compilers) {
|
|
66
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
67
|
-
} else {
|
|
68
|
-
setupCompiler(multiCompiler);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
72
|
-
const config = api.getNormalizedConfig();
|
|
73
|
-
const usingHMR = (0, import_shared.isUsingHMR)(config, { isProd: isProd2, target });
|
|
74
|
-
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
75
|
-
const reactOptions = {
|
|
76
|
-
development: !isProd2,
|
|
77
|
-
refresh: usingHMR,
|
|
78
|
-
runtime: "automatic"
|
|
79
|
-
};
|
|
80
|
-
rule.use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
81
|
-
options.jsc.transform.react = {
|
|
82
|
-
...reactOptions
|
|
83
|
-
};
|
|
84
|
-
return options;
|
|
85
|
-
});
|
|
86
|
-
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
87
|
-
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
88
|
-
options.jsc.transform.react = {
|
|
89
|
-
...reactOptions
|
|
90
|
-
};
|
|
91
|
-
return options;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
if (!usingHMR) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const { default: ReactRefreshRspackPlugin } = await Promise.resolve().then(() => __toESM(require(
|
|
98
|
-
// TODO https://github.com/web-infra-dev/rspack/issues/4471
|
|
99
|
-
"@rspack/plugin-react-refresh"
|
|
100
|
-
)));
|
|
101
|
-
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
-
0 && (module.exports = {
|
|
106
|
-
applyBasicReactSupport
|
|
107
|
-
});
|
package/dist/splitChunks.d.ts
DELETED
package/dist/splitChunks.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var splitChunks_exports = {};
|
|
20
|
-
__export(splitChunks_exports, {
|
|
21
|
-
applySplitChunksRule: () => applySplitChunksRule,
|
|
22
|
-
splitByExperience: () => splitByExperience
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(splitChunks_exports);
|
|
25
|
-
var import_splitChunks = require("@rsbuild/core/plugins/splitChunks");
|
|
26
|
-
var import_shared = require("@rsbuild/shared");
|
|
27
|
-
async function splitByExperience(rootPath) {
|
|
28
|
-
const experienceCacheGroup = {};
|
|
29
|
-
const packageRegExps = {
|
|
30
|
-
react: (0, import_splitChunks.createDependenciesRegExp)("react", "react-dom", "scheduler"),
|
|
31
|
-
router: (0, import_splitChunks.createDependenciesRegExp)(
|
|
32
|
-
"react-router",
|
|
33
|
-
"react-router-dom",
|
|
34
|
-
"@remix-run/router",
|
|
35
|
-
"history"
|
|
36
|
-
)
|
|
37
|
-
};
|
|
38
|
-
if ((0, import_shared.isPackageInstalled)("antd", rootPath)) {
|
|
39
|
-
packageRegExps.antd = (0, import_splitChunks.createDependenciesRegExp)("antd");
|
|
40
|
-
}
|
|
41
|
-
if ((0, import_shared.isPackageInstalled)("@arco-design/web-react", rootPath)) {
|
|
42
|
-
packageRegExps.arco = (0, import_splitChunks.createDependenciesRegExp)(/@?arco-design/);
|
|
43
|
-
}
|
|
44
|
-
if ((0, import_shared.isPackageInstalled)("@douyinfe/semi-ui", rootPath)) {
|
|
45
|
-
packageRegExps.semi = (0, import_splitChunks.createDependenciesRegExp)(
|
|
46
|
-
/@(ies|douyinfe)[\\/]semi-.*/
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
Object.entries(packageRegExps).forEach(([name, test]) => {
|
|
50
|
-
const key = `lib-${name}`;
|
|
51
|
-
experienceCacheGroup[key] = {
|
|
52
|
-
test,
|
|
53
|
-
priority: 0,
|
|
54
|
-
name: key,
|
|
55
|
-
reuseExistingChunk: true
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
return experienceCacheGroup;
|
|
59
|
-
}
|
|
60
|
-
const applySplitChunksRule = (api) => {
|
|
61
|
-
api.modifyRsbuildConfig(async (rsbuildConfig) => {
|
|
62
|
-
const { chunkSplit } = rsbuildConfig.performance || {};
|
|
63
|
-
if ((chunkSplit == null ? void 0 : chunkSplit.strategy) !== "split-by-experience") {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const cacheGroups = await splitByExperience(api.context.rootPath);
|
|
67
|
-
const override = rsbuildConfig.performance.chunkSplit.override;
|
|
68
|
-
rsbuildConfig.performance.chunkSplit.override = {
|
|
69
|
-
cacheGroups: {
|
|
70
|
-
...cacheGroups,
|
|
71
|
-
...override ? override.cacheGroups : {}
|
|
72
|
-
},
|
|
73
|
-
...override || {}
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
79
|
-
applySplitChunksRule,
|
|
80
|
-
splitByExperience
|
|
81
|
-
});
|