@rsbuild/plugin-react 0.0.17 → 0.0.18
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 +5 -2
- package/dist/index.js +460 -9
- package/dist/index.mjs +527 -0
- package/package.json +5 -4
- 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.mjs
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined")
|
|
11
|
+
return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.39.2_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
38
|
+
import { fileURLToPath } from "url";
|
|
39
|
+
import path from "path";
|
|
40
|
+
var init_esm = __esm({
|
|
41
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.39.2_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ../../scripts/require_shims.js
|
|
47
|
+
import { createRequire } from "module";
|
|
48
|
+
var init_require_shims = __esm({
|
|
49
|
+
"../../scripts/require_shims.js"() {
|
|
50
|
+
"use strict";
|
|
51
|
+
global.require = createRequire(import.meta.url);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// ../core/dist/plugins/splitChunks.js
|
|
56
|
+
var require_splitChunks = __commonJS({
|
|
57
|
+
"../core/dist/plugins/splitChunks.js"(exports, module) {
|
|
58
|
+
"use strict";
|
|
59
|
+
init_esm();
|
|
60
|
+
init_require_shims();
|
|
61
|
+
var __create2 = Object.create;
|
|
62
|
+
var __defProp2 = Object.defineProperty;
|
|
63
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
64
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
65
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
66
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
67
|
+
var __export = (target, all) => {
|
|
68
|
+
for (var name in all)
|
|
69
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
70
|
+
};
|
|
71
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
72
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
73
|
+
for (let key of __getOwnPropNames2(from))
|
|
74
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
75
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
76
|
+
}
|
|
77
|
+
return to;
|
|
78
|
+
};
|
|
79
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
80
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
81
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
82
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
83
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
84
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
|
|
85
|
+
mod
|
|
86
|
+
));
|
|
87
|
+
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
88
|
+
var splitChunks_exports = {};
|
|
89
|
+
__export(splitChunks_exports, {
|
|
90
|
+
createDependenciesRegExp: () => createDependenciesRegExp2,
|
|
91
|
+
pluginSplitChunks: () => pluginSplitChunks
|
|
92
|
+
});
|
|
93
|
+
module.exports = __toCommonJS(splitChunks_exports);
|
|
94
|
+
var import_assert = __toESM2(__require("assert"));
|
|
95
|
+
var import_shared5 = __require("@rsbuild/shared");
|
|
96
|
+
function getUserDefinedCacheGroups(forceSplitting) {
|
|
97
|
+
const cacheGroups = {};
|
|
98
|
+
const pairs = Array.isArray(forceSplitting) ? forceSplitting.map(
|
|
99
|
+
(regexp, index) => [`force-split-${index}`, regexp]
|
|
100
|
+
) : Object.entries(forceSplitting);
|
|
101
|
+
pairs.forEach(([key, regexp]) => {
|
|
102
|
+
cacheGroups[key] = {
|
|
103
|
+
test: regexp,
|
|
104
|
+
name: key,
|
|
105
|
+
chunks: "all",
|
|
106
|
+
// Ignore minimum size, minimum chunks and maximum requests and always create chunks for user defined cache group.
|
|
107
|
+
enforce: true
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
return cacheGroups;
|
|
111
|
+
}
|
|
112
|
+
var DEPENDENCY_MATCH_TEMPL = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
|
|
113
|
+
var createDependenciesRegExp2 = (...dependencies) => {
|
|
114
|
+
const sources = dependencies.map(
|
|
115
|
+
(d) => typeof d === "string" ? d : d.source
|
|
116
|
+
);
|
|
117
|
+
const expr = DEPENDENCY_MATCH_TEMPL.replace("<SOURCES>", sources.join("|"));
|
|
118
|
+
return new RegExp(expr);
|
|
119
|
+
};
|
|
120
|
+
function splitByExperience2(ctx) {
|
|
121
|
+
const { override, polyfill, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
122
|
+
const experienceCacheGroup = {};
|
|
123
|
+
const packageRegExps = {
|
|
124
|
+
lodash: createDependenciesRegExp2("lodash", "lodash-es"),
|
|
125
|
+
axios: createDependenciesRegExp2("axios", /axios-.+/)
|
|
126
|
+
};
|
|
127
|
+
if (polyfill === "entry" || polyfill === "usage") {
|
|
128
|
+
packageRegExps.polyfill = createDependenciesRegExp2(
|
|
129
|
+
"tslib",
|
|
130
|
+
"core-js",
|
|
131
|
+
"@babel/runtime",
|
|
132
|
+
"@swc/helpers"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
Object.entries(packageRegExps).forEach(([name, test]) => {
|
|
136
|
+
const key = `lib-${name}`;
|
|
137
|
+
experienceCacheGroup[key] = {
|
|
138
|
+
test,
|
|
139
|
+
priority: 0,
|
|
140
|
+
name: key,
|
|
141
|
+
reuseExistingChunk: true
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
...defaultConfig,
|
|
146
|
+
...override,
|
|
147
|
+
cacheGroups: {
|
|
148
|
+
...defaultConfig.cacheGroups,
|
|
149
|
+
...experienceCacheGroup,
|
|
150
|
+
...userDefinedCacheGroups,
|
|
151
|
+
...override.cacheGroups
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function splitByModule(ctx) {
|
|
156
|
+
const { override, userDefinedCacheGroups, defaultConfig } = ctx;
|
|
157
|
+
return {
|
|
158
|
+
...defaultConfig,
|
|
159
|
+
minSize: 0,
|
|
160
|
+
maxInitialRequests: Infinity,
|
|
161
|
+
...override,
|
|
162
|
+
cacheGroups: {
|
|
163
|
+
...defaultConfig.cacheGroups,
|
|
164
|
+
...userDefinedCacheGroups,
|
|
165
|
+
// Core group
|
|
166
|
+
vendors: {
|
|
167
|
+
priority: -10,
|
|
168
|
+
test: import_shared5.NODE_MODULES_REGEX,
|
|
169
|
+
// todo: not support in rspack
|
|
170
|
+
// @ts-expect-error
|
|
171
|
+
name(module2) {
|
|
172
|
+
return (0, import_shared5.getPackageNameFromModulePath)(module2.context);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
...override.cacheGroups
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function splitBySize(ctx) {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
const { override, userDefinedCacheGroups, defaultConfig, rsbuildConfig } = ctx;
|
|
182
|
+
(0, import_assert.default)(rsbuildConfig.strategy === "split-by-size");
|
|
183
|
+
return {
|
|
184
|
+
...defaultConfig,
|
|
185
|
+
minSize: (_a = rsbuildConfig.minSize) != null ? _a : 0,
|
|
186
|
+
maxSize: (_b = rsbuildConfig.maxSize) != null ? _b : Infinity,
|
|
187
|
+
...override,
|
|
188
|
+
cacheGroups: {
|
|
189
|
+
...defaultConfig.cacheGroups,
|
|
190
|
+
...userDefinedCacheGroups,
|
|
191
|
+
...override.cacheGroups
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function splitCustom(ctx) {
|
|
196
|
+
const { override, userDefinedCacheGroups, defaultConfig } = ctx;
|
|
197
|
+
return {
|
|
198
|
+
...defaultConfig,
|
|
199
|
+
...override,
|
|
200
|
+
cacheGroups: {
|
|
201
|
+
...defaultConfig.cacheGroups,
|
|
202
|
+
...userDefinedCacheGroups,
|
|
203
|
+
...override.cacheGroups
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function allInOne(_ctx) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function singleVendor(ctx) {
|
|
211
|
+
const { override, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
212
|
+
const singleVendorCacheGroup = {
|
|
213
|
+
singleVendor: {
|
|
214
|
+
test: import_shared5.NODE_MODULES_REGEX,
|
|
215
|
+
priority: 0,
|
|
216
|
+
chunks: "all",
|
|
217
|
+
name: "vendor",
|
|
218
|
+
enforce: true,
|
|
219
|
+
reuseExistingChunk: true
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
...defaultConfig,
|
|
224
|
+
...override,
|
|
225
|
+
cacheGroups: {
|
|
226
|
+
...defaultConfig.cacheGroups,
|
|
227
|
+
...singleVendorCacheGroup,
|
|
228
|
+
...userDefinedCacheGroups,
|
|
229
|
+
...override.cacheGroups
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
var SPLIT_STRATEGY_DISPATCHER = {
|
|
234
|
+
"split-by-experience": splitByExperience2,
|
|
235
|
+
"split-by-module": splitByModule,
|
|
236
|
+
"split-by-size": splitBySize,
|
|
237
|
+
custom: splitCustom,
|
|
238
|
+
"all-in-one": allInOne,
|
|
239
|
+
"single-vendor": singleVendor
|
|
240
|
+
};
|
|
241
|
+
function pluginSplitChunks() {
|
|
242
|
+
return {
|
|
243
|
+
name: "plugin-split-chunks",
|
|
244
|
+
setup(api) {
|
|
245
|
+
api.modifyBundlerChain(
|
|
246
|
+
async (chain, { isServer, isWebWorker, isServiceWorker }) => {
|
|
247
|
+
var _a;
|
|
248
|
+
if (isServer || isWebWorker || isServiceWorker) {
|
|
249
|
+
chain.optimization.splitChunks(false);
|
|
250
|
+
if (isWebWorker || isServiceWorker) {
|
|
251
|
+
chain.module.parser.merge({
|
|
252
|
+
javascript: {
|
|
253
|
+
dynamicImportMode: "eager"
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const config = api.getNormalizedConfig();
|
|
260
|
+
const defaultConfig = {
|
|
261
|
+
// Optimize both `initial` and `async` chunks
|
|
262
|
+
chunks: "all",
|
|
263
|
+
// When chunk size >= 50000 bytes, split it into separate chunk
|
|
264
|
+
// @ts-expect-error Rspack type missing
|
|
265
|
+
enforceSizeThreshold: 5e4,
|
|
266
|
+
cacheGroups: {}
|
|
267
|
+
};
|
|
268
|
+
const { chunkSplit } = config.performance;
|
|
269
|
+
let userDefinedCacheGroups = {};
|
|
270
|
+
if (chunkSplit.forceSplitting) {
|
|
271
|
+
userDefinedCacheGroups = getUserDefinedCacheGroups(
|
|
272
|
+
chunkSplit.forceSplitting
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
const override = chunkSplit.strategy === "custom" ? (
|
|
276
|
+
// `chunkSplit.splitChunks` compat for Eden
|
|
277
|
+
(_a = chunkSplit.splitChunks) != null ? _a : chunkSplit.override
|
|
278
|
+
) : chunkSplit.override;
|
|
279
|
+
const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
|
|
280
|
+
defaultConfig,
|
|
281
|
+
override: override || {},
|
|
282
|
+
userDefinedCacheGroups,
|
|
283
|
+
rsbuildConfig: chunkSplit,
|
|
284
|
+
rootPath: api.context.rootPath,
|
|
285
|
+
polyfill: config.output.polyfill
|
|
286
|
+
});
|
|
287
|
+
chain.optimization.splitChunks(splitChunksOptions);
|
|
288
|
+
if (chunkSplit.strategy !== "all-in-one") {
|
|
289
|
+
chain.optimization.runtimeChunk({
|
|
290
|
+
name: import_shared5.RUNTIME_CHUNK_NAME
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// src/index.ts
|
|
302
|
+
init_esm();
|
|
303
|
+
init_require_shims();
|
|
304
|
+
|
|
305
|
+
// src/antd.ts
|
|
306
|
+
init_esm();
|
|
307
|
+
init_require_shims();
|
|
308
|
+
import { isServerTarget } from "@rsbuild/shared";
|
|
309
|
+
var getAntdMajorVersion = (appDirectory) => {
|
|
310
|
+
try {
|
|
311
|
+
const pkgJsonPath = __require.resolve("antd/package.json", {
|
|
312
|
+
paths: [appDirectory]
|
|
313
|
+
});
|
|
314
|
+
const { version } = __require(pkgJsonPath);
|
|
315
|
+
return Number(version.split(".")[0]);
|
|
316
|
+
} catch (err) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
var applyAntdSupport = (api) => {
|
|
321
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
322
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
323
|
+
if (rsbuildConfig.source.transformImport === false || rsbuildConfig.source.transformImport?.some(
|
|
324
|
+
(item) => item.libraryName === "antd"
|
|
325
|
+
)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
|
|
329
|
+
if (antdMajorVersion && antdMajorVersion < 5) {
|
|
330
|
+
rsbuildConfig.source ?? (rsbuildConfig.source = {});
|
|
331
|
+
rsbuildConfig.source.transformImport = [
|
|
332
|
+
...rsbuildConfig.source.transformImport || [],
|
|
333
|
+
{
|
|
334
|
+
libraryName: "antd",
|
|
335
|
+
libraryDirectory: isServerTarget(api.context.target) ? "lib" : "es",
|
|
336
|
+
style: true
|
|
337
|
+
}
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// src/arco.ts
|
|
344
|
+
init_esm();
|
|
345
|
+
init_require_shims();
|
|
346
|
+
import {
|
|
347
|
+
isServerTarget as isServerTarget2,
|
|
348
|
+
isPackageInstalled
|
|
349
|
+
} from "@rsbuild/shared";
|
|
350
|
+
var applyArcoSupport = (api) => {
|
|
351
|
+
const ARCO_NAME = "@arco-design/web-react";
|
|
352
|
+
const ARCO_ICON = `${ARCO_NAME}/icon`;
|
|
353
|
+
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
354
|
+
const { transformImport = [] } = rsbuildConfig.source || {};
|
|
355
|
+
if (transformImport === false || !isPackageInstalled(ARCO_NAME, api.context.rootPath)) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const isUseSSR = isServerTarget2(api.context.target);
|
|
359
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_NAME)) {
|
|
360
|
+
transformImport.push({
|
|
361
|
+
libraryName: ARCO_NAME,
|
|
362
|
+
libraryDirectory: isUseSSR ? "lib" : "es",
|
|
363
|
+
camelToDashComponentName: false,
|
|
364
|
+
style: true
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (!transformImport?.some((item) => item.libraryName === ARCO_ICON)) {
|
|
368
|
+
transformImport.push({
|
|
369
|
+
libraryName: ARCO_ICON,
|
|
370
|
+
libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
|
|
371
|
+
camelToDashComponentName: false
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
rsbuildConfig.source || (rsbuildConfig.source = {});
|
|
375
|
+
rsbuildConfig.source.transformImport = transformImport;
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/splitChunks.ts
|
|
380
|
+
init_esm();
|
|
381
|
+
init_require_shims();
|
|
382
|
+
var import_splitChunks = __toESM(require_splitChunks());
|
|
383
|
+
import {
|
|
384
|
+
isPackageInstalled as isPackageInstalled2
|
|
385
|
+
} from "@rsbuild/shared";
|
|
386
|
+
async function splitByExperience(rootPath) {
|
|
387
|
+
const experienceCacheGroup = {};
|
|
388
|
+
const packageRegExps = {
|
|
389
|
+
react: (0, import_splitChunks.createDependenciesRegExp)("react", "react-dom", "scheduler"),
|
|
390
|
+
router: (0, import_splitChunks.createDependenciesRegExp)(
|
|
391
|
+
"react-router",
|
|
392
|
+
"react-router-dom",
|
|
393
|
+
"@remix-run/router",
|
|
394
|
+
"history"
|
|
395
|
+
)
|
|
396
|
+
};
|
|
397
|
+
if (isPackageInstalled2("antd", rootPath)) {
|
|
398
|
+
packageRegExps.antd = (0, import_splitChunks.createDependenciesRegExp)("antd");
|
|
399
|
+
}
|
|
400
|
+
if (isPackageInstalled2("@arco-design/web-react", rootPath)) {
|
|
401
|
+
packageRegExps.arco = (0, import_splitChunks.createDependenciesRegExp)(/@?arco-design/);
|
|
402
|
+
}
|
|
403
|
+
if (isPackageInstalled2("@douyinfe/semi-ui", rootPath)) {
|
|
404
|
+
packageRegExps.semi = (0, import_splitChunks.createDependenciesRegExp)(
|
|
405
|
+
/@(ies|douyinfe)[\\/]semi-.*/
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
Object.entries(packageRegExps).forEach(([name, test]) => {
|
|
409
|
+
const key = `lib-${name}`;
|
|
410
|
+
experienceCacheGroup[key] = {
|
|
411
|
+
test,
|
|
412
|
+
priority: 0,
|
|
413
|
+
name: key,
|
|
414
|
+
reuseExistingChunk: true
|
|
415
|
+
};
|
|
416
|
+
});
|
|
417
|
+
return experienceCacheGroup;
|
|
418
|
+
}
|
|
419
|
+
var applySplitChunksRule = (api) => {
|
|
420
|
+
api.modifyRsbuildConfig(async (rsbuildConfig) => {
|
|
421
|
+
const { chunkSplit } = rsbuildConfig.performance || {};
|
|
422
|
+
if (chunkSplit?.strategy !== "split-by-experience") {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const cacheGroups = await splitByExperience(api.context.rootPath);
|
|
426
|
+
const override = rsbuildConfig.performance.chunkSplit.override;
|
|
427
|
+
rsbuildConfig.performance.chunkSplit.override = {
|
|
428
|
+
cacheGroups: {
|
|
429
|
+
...cacheGroups,
|
|
430
|
+
...override ? override.cacheGroups : {}
|
|
431
|
+
},
|
|
432
|
+
...override || {}
|
|
433
|
+
};
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// src/react.ts
|
|
438
|
+
init_esm();
|
|
439
|
+
init_require_shims();
|
|
440
|
+
import { isUsingHMR, isClientCompiler, isProd } from "@rsbuild/shared";
|
|
441
|
+
function getReactRefreshEntry(compiler) {
|
|
442
|
+
const hot = compiler.options.devServer?.hot ?? true;
|
|
443
|
+
const refresh = compiler.options.builtins?.react?.refresh ?? true;
|
|
444
|
+
if (hot && refresh) {
|
|
445
|
+
const reactRefreshEntryPath = __require.resolve(
|
|
446
|
+
"@rspack/plugin-react-refresh/react-refresh-entry"
|
|
447
|
+
);
|
|
448
|
+
return reactRefreshEntryPath;
|
|
449
|
+
}
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
var setupCompiler = (compiler) => {
|
|
453
|
+
if (!isClientCompiler(compiler)) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
457
|
+
if (!reactRefreshEntry) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
for (const key in compiler.options.entry) {
|
|
461
|
+
compiler.options.entry[key].import = [
|
|
462
|
+
reactRefreshEntry,
|
|
463
|
+
...compiler.options.entry[key].import || []
|
|
464
|
+
];
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
var applyBasicReactSupport = (api) => {
|
|
468
|
+
api.onAfterCreateCompiler(({ compiler: multiCompiler }) => {
|
|
469
|
+
if (isProd()) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (multiCompiler.compilers) {
|
|
473
|
+
multiCompiler.compilers.forEach(setupCompiler);
|
|
474
|
+
} else {
|
|
475
|
+
setupCompiler(multiCompiler);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
479
|
+
const config = api.getNormalizedConfig();
|
|
480
|
+
const usingHMR = isUsingHMR(config, { isProd: isProd2, target });
|
|
481
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
482
|
+
const reactOptions = {
|
|
483
|
+
development: !isProd2,
|
|
484
|
+
refresh: usingHMR,
|
|
485
|
+
runtime: "automatic"
|
|
486
|
+
};
|
|
487
|
+
rule.use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
488
|
+
options.jsc.transform.react = {
|
|
489
|
+
...reactOptions
|
|
490
|
+
};
|
|
491
|
+
return options;
|
|
492
|
+
});
|
|
493
|
+
if (chain.module.rules.has(CHAIN_ID.RULE.JS_DATA_URI)) {
|
|
494
|
+
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).use(CHAIN_ID.USE.SWC).tap((options) => {
|
|
495
|
+
options.jsc.transform.react = {
|
|
496
|
+
...reactOptions
|
|
497
|
+
};
|
|
498
|
+
return options;
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (!usingHMR) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const { default: ReactRefreshRspackPlugin } = await import(
|
|
505
|
+
// TODO https://github.com/web-infra-dev/rspack/issues/4471
|
|
506
|
+
"@rspack/plugin-react-refresh"
|
|
507
|
+
);
|
|
508
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
509
|
+
});
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
// src/index.ts
|
|
513
|
+
var pluginReact = () => ({
|
|
514
|
+
name: "plugin-react",
|
|
515
|
+
pre: ["plugin-swc"],
|
|
516
|
+
setup(api) {
|
|
517
|
+
if (api.context.bundlerType === "rspack") {
|
|
518
|
+
applyBasicReactSupport(api);
|
|
519
|
+
}
|
|
520
|
+
applyAntdSupport(api);
|
|
521
|
+
applyArcoSupport(api);
|
|
522
|
+
applySplitChunksRule(api);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
export {
|
|
526
|
+
pluginReact
|
|
527
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
14
15
|
"default": "./dist/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
@@ -22,13 +23,13 @@
|
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@rspack/plugin-react-refresh": "0.3.11",
|
|
24
25
|
"react-refresh": "^0.14.0",
|
|
25
|
-
"@rsbuild/shared": "0.0.
|
|
26
|
+
"@rsbuild/shared": "0.0.18"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^16",
|
|
29
30
|
"typescript": "^5.2.2",
|
|
30
|
-
"@rsbuild/core": "0.0.
|
|
31
|
-
"@rsbuild/test-helper": "0.0.
|
|
31
|
+
"@rsbuild/core": "0.0.18",
|
|
32
|
+
"@rsbuild/test-helper": "0.0.18"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|
|
34
35
|
"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