@rsbuild/core 0.7.8 → 0.7.9
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/bin/rsbuild.js +1 -2
- package/compiled/css-loader/index.js +20 -20
- package/compiled/launch-editor-middleware/index.js +21 -15
- package/compiled/launch-editor-middleware/package.json +1 -1
- package/compiled/postcss-loader/index.js +8 -8
- package/compiled/rslog/index.d.ts +66 -0
- package/compiled/rslog/index.js +334 -0
- package/compiled/rslog/license +21 -0
- package/compiled/rslog/package.json +1 -0
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/index.cjs +687 -416
- package/dist/index.js +519 -290
- package/dist-types/configChain.d.ts +10 -0
- package/dist-types/constants.d.ts +2 -0
- package/dist-types/createContext.d.ts +1 -1
- package/dist-types/helpers.d.ts +20 -3
- package/dist-types/index.d.ts +1 -1
- package/dist-types/initPlugins.d.ts +1 -1
- package/dist-types/internal.d.ts +3 -1
- package/dist-types/logger.d.ts +4 -0
- package/dist-types/provider/initConfigs.d.ts +1 -1
- package/dist-types/server/devMiddleware.d.ts +11 -1
- package/dist-types/server/proxy.d.ts +1 -1
- package/dist-types/server/socketServer.d.ts +1 -1
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -118,7 +118,7 @@ var init_format = __esm({
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// src/constants.ts
|
|
121
|
-
var import_node_path, ROOT_DIST_DIR, HTML_DIST_DIR, SERVER_DIST_DIR, SERVICE_WORKER_DIST_DIR, JS_DIST_DIR, CSS_DIST_DIR, SVG_DIST_DIR, FONT_DIST_DIR, WASM_DIST_DIR, IMAGE_DIST_DIR, MEDIA_DIST_DIR, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, DEFAULT_PORT, DEFAULT_DATA_URL_SIZE, DEFAULT_MOUNT_ID, DEFAULT_DEV_HOST, HTML_REGEX, CSS_REGEX, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, FONT_EXTENSIONS, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS;
|
|
121
|
+
var import_node_path, ROOT_DIST_DIR, HTML_DIST_DIR, SERVER_DIST_DIR, SERVICE_WORKER_DIST_DIR, JS_DIST_DIR, CSS_DIST_DIR, SVG_DIST_DIR, FONT_DIST_DIR, WASM_DIST_DIR, IMAGE_DIST_DIR, MEDIA_DIST_DIR, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, DEFAULT_PORT, DEFAULT_DATA_URL_SIZE, DEFAULT_MOUNT_ID, DEFAULT_DEV_HOST, HTML_REGEX, CSS_REGEX, PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, FONT_EXTENSIONS, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, AUDIO_EXTENSIONS, TARGET_ID_MAP;
|
|
122
122
|
var init_constants = __esm({
|
|
123
123
|
"src/constants.ts"() {
|
|
124
124
|
"use strict";
|
|
@@ -165,6 +165,48 @@ var init_constants = __esm({
|
|
|
165
165
|
];
|
|
166
166
|
VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
|
|
167
167
|
AUDIO_EXTENSIONS = ["mp3", "wav", "flac", "aac", "m4a", "opus"];
|
|
168
|
+
TARGET_ID_MAP = {
|
|
169
|
+
web: "Client",
|
|
170
|
+
node: "Server",
|
|
171
|
+
"web-worker": "Web Worker",
|
|
172
|
+
"service-worker": "Service Worker"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// src/logger.ts
|
|
178
|
+
function getTime() {
|
|
179
|
+
const now = /* @__PURE__ */ new Date();
|
|
180
|
+
const hours = String(now.getHours()).padStart(2, "0");
|
|
181
|
+
const minutes = String(now.getMinutes()).padStart(2, "0");
|
|
182
|
+
const seconds = String(now.getSeconds()).padStart(2, "0");
|
|
183
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
184
|
+
}
|
|
185
|
+
var import_shared, import_rslog, isDebug;
|
|
186
|
+
var init_logger = __esm({
|
|
187
|
+
"src/logger.ts"() {
|
|
188
|
+
"use strict";
|
|
189
|
+
import_shared = require("@rsbuild/shared");
|
|
190
|
+
import_rslog = require("../compiled/rslog/index.js");
|
|
191
|
+
isDebug = () => {
|
|
192
|
+
if (!process.env.DEBUG) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const values = process.env.DEBUG.toLocaleLowerCase().split(",");
|
|
196
|
+
return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
|
|
197
|
+
};
|
|
198
|
+
if (isDebug()) {
|
|
199
|
+
import_rslog.logger.level = "verbose";
|
|
200
|
+
}
|
|
201
|
+
import_rslog.logger.override({
|
|
202
|
+
debug: (message, ...args) => {
|
|
203
|
+
if (import_rslog.logger.level !== "verbose") {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const time = import_shared.color.gray(`${getTime()}`);
|
|
207
|
+
console.log(` ${import_shared.color.magenta("rsbuild")} ${time} ${message}`, ...args);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
168
210
|
}
|
|
169
211
|
});
|
|
170
212
|
|
|
@@ -174,14 +216,14 @@ function formatErrorMessage(errors) {
|
|
|
174
216
|
const text = `${messages.join("\n\n")}
|
|
175
217
|
`;
|
|
176
218
|
const isTerserError = text.includes("from Terser");
|
|
177
|
-
const title =
|
|
178
|
-
|
|
219
|
+
const title = import_shared2.color.bold(
|
|
220
|
+
import_shared2.color.red(isTerserError ? "Minify error: " : "Compile error: ")
|
|
179
221
|
);
|
|
180
222
|
if (!errors.length) {
|
|
181
223
|
return `${title}
|
|
182
|
-
${
|
|
224
|
+
${import_shared2.color.yellow(`For more details, please setting 'stats.errors: true' `)}`;
|
|
183
225
|
}
|
|
184
|
-
const tip =
|
|
226
|
+
const tip = import_shared2.color.yellow(
|
|
185
227
|
isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
|
|
186
228
|
);
|
|
187
229
|
return `${title}
|
|
@@ -189,7 +231,7 @@ ${tip}
|
|
|
189
231
|
${text}`;
|
|
190
232
|
}
|
|
191
233
|
function getStatsOptions(compiler) {
|
|
192
|
-
if (
|
|
234
|
+
if (isMultiCompiler(compiler)) {
|
|
193
235
|
return {
|
|
194
236
|
children: compiler.compilers.map(
|
|
195
237
|
(compiler2) => compiler2.options ? compiler2.options.stats : void 0
|
|
@@ -212,7 +254,7 @@ function formatStats(stats, options = {}) {
|
|
|
212
254
|
warnings: getAllStatsWarnings(statsData)
|
|
213
255
|
},
|
|
214
256
|
// display verbose messages in prod build or debug mode
|
|
215
|
-
(0,
|
|
257
|
+
(0, import_shared2.isProd)() || import_rslog.logger.level === "verbose"
|
|
216
258
|
);
|
|
217
259
|
if (stats.hasErrors()) {
|
|
218
260
|
return {
|
|
@@ -221,7 +263,7 @@ function formatStats(stats, options = {}) {
|
|
|
221
263
|
};
|
|
222
264
|
}
|
|
223
265
|
if (warnings.length) {
|
|
224
|
-
const title =
|
|
266
|
+
const title = import_shared2.color.bold(import_shared2.color.yellow("Compile Warning: \n"));
|
|
225
267
|
return {
|
|
226
268
|
message: `${title}${warnings.join("\n\n")}
|
|
227
269
|
`,
|
|
@@ -231,21 +273,86 @@ function formatStats(stats, options = {}) {
|
|
|
231
273
|
return {};
|
|
232
274
|
}
|
|
233
275
|
function isEmptyDir(path13) {
|
|
234
|
-
const files =
|
|
276
|
+
const files = import_shared3.fse.readdirSync(path13);
|
|
235
277
|
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
236
278
|
}
|
|
237
279
|
async function isFileExists(file) {
|
|
238
|
-
return
|
|
280
|
+
return import_shared3.fse.promises.access(file, import_shared3.fse.constants.F_OK).then(() => true).catch(() => false);
|
|
281
|
+
}
|
|
282
|
+
function getFilename(config, type, isProd7) {
|
|
283
|
+
const { filename, filenameHash } = config.output;
|
|
284
|
+
const getHash = () => {
|
|
285
|
+
if (typeof filenameHash === "string") {
|
|
286
|
+
return filenameHash ? `.[${filenameHash}]` : "";
|
|
287
|
+
}
|
|
288
|
+
return filenameHash ? ".[contenthash:8]" : "";
|
|
289
|
+
};
|
|
290
|
+
const hash = getHash();
|
|
291
|
+
switch (type) {
|
|
292
|
+
case "js":
|
|
293
|
+
return filename.js ?? `[name]${isProd7 ? hash : ""}.js`;
|
|
294
|
+
case "css":
|
|
295
|
+
return filename.css ?? `[name]${isProd7 ? hash : ""}.css`;
|
|
296
|
+
case "svg":
|
|
297
|
+
return filename.svg ?? `[name]${hash}.svg`;
|
|
298
|
+
case "font":
|
|
299
|
+
return filename.font ?? `[name]${hash}[ext]`;
|
|
300
|
+
case "image":
|
|
301
|
+
return filename.image ?? `[name]${hash}[ext]`;
|
|
302
|
+
case "media":
|
|
303
|
+
return filename.media ?? `[name]${hash}[ext]`;
|
|
304
|
+
default:
|
|
305
|
+
throw new Error(`unknown key ${type} in "output.filename"`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function partition(array, predicate) {
|
|
309
|
+
const truthy = [];
|
|
310
|
+
const falsy = [];
|
|
311
|
+
for (const value of array) {
|
|
312
|
+
if (predicate(value)) {
|
|
313
|
+
truthy.push(value);
|
|
314
|
+
} else {
|
|
315
|
+
falsy.push(value);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return [truthy, falsy];
|
|
239
319
|
}
|
|
240
|
-
|
|
320
|
+
function debounce(func, wait) {
|
|
321
|
+
let timeoutId = null;
|
|
322
|
+
return (...args) => {
|
|
323
|
+
if (timeoutId !== null) {
|
|
324
|
+
clearTimeout(timeoutId);
|
|
325
|
+
}
|
|
326
|
+
timeoutId = setTimeout(() => {
|
|
327
|
+
func(...args);
|
|
328
|
+
}, wait);
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function isWebTarget(target) {
|
|
332
|
+
const targets = (0, import_shared2.castArray)(target);
|
|
333
|
+
return targets.includes("web") || target.includes("web-worker");
|
|
334
|
+
}
|
|
335
|
+
function pick(obj, keys) {
|
|
336
|
+
return keys.reduce(
|
|
337
|
+
(ret, key) => {
|
|
338
|
+
if (obj[key] !== void 0) {
|
|
339
|
+
ret[key] = obj[key];
|
|
340
|
+
}
|
|
341
|
+
return ret;
|
|
342
|
+
},
|
|
343
|
+
{}
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
var import_node_path2, import_shared2, import_shared3, rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, removeLeadingSlash, removeTailingSlash, addTrailingSlash, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists, urlJoin, canParse, ensureAssetPrefix, applyToCompiler, upperFirst, isURL, createVirtualModule, isRegExp, isMultiCompiler, onCompileDone;
|
|
241
347
|
var init_helpers = __esm({
|
|
242
348
|
"src/helpers.ts"() {
|
|
243
349
|
"use strict";
|
|
244
350
|
import_node_path2 = __toESM(require("path"));
|
|
245
|
-
import_shared = require("@rsbuild/shared");
|
|
246
351
|
import_shared2 = require("@rsbuild/shared");
|
|
352
|
+
import_shared3 = require("@rsbuild/shared");
|
|
247
353
|
init_format();
|
|
248
354
|
init_constants();
|
|
355
|
+
init_logger();
|
|
249
356
|
rspackMinVersion = "0.6.2";
|
|
250
357
|
compareSemver = (version1, version2) => {
|
|
251
358
|
const parts1 = version1.split(".").map(Number);
|
|
@@ -330,7 +437,7 @@ var init_helpers = __esm({
|
|
|
330
437
|
];
|
|
331
438
|
return `${message}
|
|
332
439
|
|
|
333
|
-
${
|
|
440
|
+
${import_shared2.color.yellow(tips.join("\n"))}`;
|
|
334
441
|
}
|
|
335
442
|
return message;
|
|
336
443
|
};
|
|
@@ -352,23 +459,26 @@ ${import_shared.color.yellow(tips.join("\n"))}`;
|
|
|
352
459
|
}
|
|
353
460
|
return statsData.warnings;
|
|
354
461
|
};
|
|
462
|
+
removeLeadingSlash = (s) => s.replace(/^\/+/, "");
|
|
463
|
+
removeTailingSlash = (s) => s.replace(/\/+$/, "");
|
|
464
|
+
addTrailingSlash = (s) => s.endsWith("/") ? s : `${s}/`;
|
|
355
465
|
formatPublicPath = (publicPath, withSlash = true) => {
|
|
356
466
|
if (publicPath === "auto") {
|
|
357
467
|
return publicPath;
|
|
358
468
|
}
|
|
359
|
-
return withSlash ?
|
|
469
|
+
return withSlash ? addTrailingSlash(publicPath) : removeTailingSlash(publicPath);
|
|
360
470
|
};
|
|
361
471
|
getPublicPathFromChain = (chain, withSlash = true) => {
|
|
362
472
|
const publicPath = chain.output.get("publicPath");
|
|
363
473
|
if (typeof publicPath === "string") {
|
|
364
474
|
return formatPublicPath(publicPath, withSlash);
|
|
365
475
|
}
|
|
366
|
-
return formatPublicPath(
|
|
476
|
+
return formatPublicPath(import_shared2.DEFAULT_ASSET_PREFIX, withSlash);
|
|
367
477
|
};
|
|
368
478
|
ensureAbsolutePath = (base, filePath) => import_node_path2.default.isAbsolute(filePath) ? filePath : import_node_path2.default.resolve(base, filePath);
|
|
369
479
|
isFileSync = (filePath) => {
|
|
370
480
|
try {
|
|
371
|
-
return
|
|
481
|
+
return import_shared3.fse.statSync(filePath, { throwIfNoEntry: false })?.isFile();
|
|
372
482
|
} catch (_) {
|
|
373
483
|
return false;
|
|
374
484
|
}
|
|
@@ -409,15 +519,59 @@ ${import_shared.color.yellow(tips.join("\n"))}`;
|
|
|
409
519
|
}
|
|
410
520
|
return import_node_path2.posix.join(assetPrefix, url2);
|
|
411
521
|
};
|
|
522
|
+
applyToCompiler = (compiler, apply) => {
|
|
523
|
+
if (isMultiCompiler(compiler)) {
|
|
524
|
+
compiler.compilers.forEach(apply);
|
|
525
|
+
} else {
|
|
526
|
+
apply(compiler);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
upperFirst = (str) => str ? str.charAt(0).toUpperCase() + str.slice(1) : "";
|
|
530
|
+
isURL = (str) => str.startsWith("http") || str.startsWith("//:");
|
|
531
|
+
createVirtualModule = (content) => `data:text/javascript,${content}`;
|
|
532
|
+
isRegExp = (obj) => Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
533
|
+
isMultiCompiler = (compiler) => {
|
|
534
|
+
return compiler.constructor.name === "MultiCompiler";
|
|
535
|
+
};
|
|
536
|
+
onCompileDone = (compiler, onDone, MultiStatsCtor) => {
|
|
537
|
+
if (isMultiCompiler(compiler)) {
|
|
538
|
+
const { compilers } = compiler;
|
|
539
|
+
const compilerStats = [];
|
|
540
|
+
let doneCompilers = 0;
|
|
541
|
+
for (let index = 0; index < compilers.length; index++) {
|
|
542
|
+
const compiler2 = compilers[index];
|
|
543
|
+
const compilerIndex = index;
|
|
544
|
+
let compilerDone = false;
|
|
545
|
+
compiler2.hooks.done.tapPromise("rsbuild:done", async (stats) => {
|
|
546
|
+
if (!compilerDone) {
|
|
547
|
+
compilerDone = true;
|
|
548
|
+
doneCompilers++;
|
|
549
|
+
}
|
|
550
|
+
compilerStats[compilerIndex] = stats;
|
|
551
|
+
if (doneCompilers === compilers.length) {
|
|
552
|
+
await onDone(new MultiStatsCtor(compilerStats));
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
compiler2.hooks.invalid.tap("rsbuild:done", () => {
|
|
556
|
+
if (compilerDone) {
|
|
557
|
+
compilerDone = false;
|
|
558
|
+
doneCompilers--;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
compiler.hooks.done.tapPromise("rsbuild:done", onDone);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
412
566
|
}
|
|
413
567
|
});
|
|
414
568
|
|
|
415
569
|
// src/mergeConfig.ts
|
|
416
|
-
var
|
|
570
|
+
var import_shared4, OVERRIDE_PATH, isOverridePath, merge, mergeRsbuildConfig;
|
|
417
571
|
var init_mergeConfig = __esm({
|
|
418
572
|
"src/mergeConfig.ts"() {
|
|
419
573
|
"use strict";
|
|
420
|
-
|
|
574
|
+
import_shared4 = require("@rsbuild/shared");
|
|
421
575
|
OVERRIDE_PATH = [
|
|
422
576
|
"performance.removeConsole",
|
|
423
577
|
"output.inlineScripts",
|
|
@@ -443,12 +597,12 @@ var init_mergeConfig = __esm({
|
|
|
443
597
|
}
|
|
444
598
|
const pair = [x, y];
|
|
445
599
|
if (pair.some(Array.isArray)) {
|
|
446
|
-
return [...(0,
|
|
600
|
+
return [...(0, import_shared4.castArray)(x), ...(0, import_shared4.castArray)(y)];
|
|
447
601
|
}
|
|
448
|
-
if (pair.some(
|
|
602
|
+
if (pair.some(import_shared4.isFunction)) {
|
|
449
603
|
return pair;
|
|
450
604
|
}
|
|
451
|
-
if (!(0,
|
|
605
|
+
if (!(0, import_shared4.isPlainObject)(x) || !(0, import_shared4.isPlainObject)(y)) {
|
|
452
606
|
return y;
|
|
453
607
|
}
|
|
454
608
|
const merged = {};
|
|
@@ -475,13 +629,14 @@ var init_mergeConfig = __esm({
|
|
|
475
629
|
});
|
|
476
630
|
|
|
477
631
|
// src/server/restart.ts
|
|
478
|
-
var import_node_path3,
|
|
632
|
+
var import_node_path3, import_shared5, cleaners, onBeforeRestartServer, clearConsole, restartDevServer;
|
|
479
633
|
var init_restart = __esm({
|
|
480
634
|
"src/server/restart.ts"() {
|
|
481
635
|
"use strict";
|
|
482
636
|
import_node_path3 = __toESM(require("path"));
|
|
483
|
-
|
|
637
|
+
import_shared5 = require("@rsbuild/shared");
|
|
484
638
|
init_init();
|
|
639
|
+
init_logger();
|
|
485
640
|
cleaners = [];
|
|
486
641
|
onBeforeRestartServer = (cleaner) => {
|
|
487
642
|
cleaners.push(cleaner);
|
|
@@ -494,7 +649,7 @@ var init_restart = __esm({
|
|
|
494
649
|
restartDevServer = async ({ filePath }) => {
|
|
495
650
|
clearConsole();
|
|
496
651
|
const filename = import_node_path3.default.basename(filePath);
|
|
497
|
-
|
|
652
|
+
import_rslog.logger.info(`Restart because ${import_shared5.color.yellow(filename)} is changed.
|
|
498
653
|
`);
|
|
499
654
|
for (const cleaner of cleaners) {
|
|
500
655
|
await cleaner();
|
|
@@ -543,7 +698,7 @@ async function watchFiles(files) {
|
|
|
543
698
|
// If watching fails due to read permissions, the errors will be suppressed silently.
|
|
544
699
|
ignorePermissionErrors: true
|
|
545
700
|
});
|
|
546
|
-
const callback =
|
|
701
|
+
const callback = debounce(
|
|
547
702
|
async (filePath) => {
|
|
548
703
|
watcher.close();
|
|
549
704
|
await restartDevServer({ filePath });
|
|
@@ -583,22 +738,22 @@ async function loadConfig({
|
|
|
583
738
|
if (typeof configExport === "function") {
|
|
584
739
|
const command = process.argv[2];
|
|
585
740
|
const params = {
|
|
586
|
-
env: (0,
|
|
741
|
+
env: (0, import_shared6.getNodeEnv)(),
|
|
587
742
|
command,
|
|
588
|
-
envMode: envMode || (0,
|
|
743
|
+
envMode: envMode || (0, import_shared6.getNodeEnv)()
|
|
589
744
|
};
|
|
590
745
|
const result = await configExport(params);
|
|
591
746
|
if (result === void 0) {
|
|
592
|
-
throw new Error("
|
|
747
|
+
throw new Error("The config function must return a config object.");
|
|
593
748
|
}
|
|
594
749
|
return {
|
|
595
750
|
content: applyMetaInfo(result),
|
|
596
751
|
filePath: configFilePath
|
|
597
752
|
};
|
|
598
753
|
}
|
|
599
|
-
if (!(0,
|
|
754
|
+
if (!(0, import_shared6.isObject)(configExport)) {
|
|
600
755
|
throw new Error(
|
|
601
|
-
`
|
|
756
|
+
`The config must be an object or a function that returns an object, get ${import_shared6.color.yellow(
|
|
602
757
|
configExport
|
|
603
758
|
)}`
|
|
604
759
|
);
|
|
@@ -608,7 +763,7 @@ async function loadConfig({
|
|
|
608
763
|
filePath: configFilePath
|
|
609
764
|
};
|
|
610
765
|
} catch (err) {
|
|
611
|
-
|
|
766
|
+
import_rslog.logger.error(`Failed to load file: ${import_shared6.color.dim(configFilePath)}`);
|
|
612
767
|
throw err;
|
|
613
768
|
}
|
|
614
769
|
}
|
|
@@ -630,27 +785,27 @@ async function outputInspectConfigFiles({
|
|
|
630
785
|
const suffix = rsbuildConfig.output.targets[index];
|
|
631
786
|
const outputFile = `${configType}.config.${suffix}.mjs`;
|
|
632
787
|
let outputFilePath = (0, import_node_path4.join)(outputPath, outputFile);
|
|
633
|
-
if (
|
|
788
|
+
if (import_shared6.fse.existsSync(outputFilePath)) {
|
|
634
789
|
outputFilePath = outputFilePath.replace(/\.mjs$/, `.${Date.now()}.mjs`);
|
|
635
790
|
}
|
|
636
791
|
return {
|
|
637
792
|
path: outputFilePath,
|
|
638
|
-
label: `${
|
|
793
|
+
label: `${upperFirst(configType)} Config (${suffix})`,
|
|
639
794
|
content
|
|
640
795
|
};
|
|
641
796
|
})
|
|
642
797
|
];
|
|
643
798
|
await Promise.all(
|
|
644
799
|
files.map(
|
|
645
|
-
(item) =>
|
|
800
|
+
(item) => import_shared6.fse.outputFile(item.path, `export default ${item.content}`)
|
|
646
801
|
)
|
|
647
802
|
);
|
|
648
803
|
const fileInfos = files.map(
|
|
649
|
-
(item) => ` - ${
|
|
804
|
+
(item) => ` - ${import_shared6.color.bold(import_shared6.color.yellow(item.label))}: ${import_shared6.color.underline(
|
|
650
805
|
item.path
|
|
651
806
|
)}`
|
|
652
807
|
).join("\n");
|
|
653
|
-
|
|
808
|
+
import_rslog.logger.success(
|
|
654
809
|
`Inspect config succeed, open following files to view the content:
|
|
655
810
|
|
|
656
811
|
${fileInfos}
|
|
@@ -658,24 +813,25 @@ ${fileInfos}
|
|
|
658
813
|
);
|
|
659
814
|
}
|
|
660
815
|
async function stringifyConfig(config, verbose) {
|
|
661
|
-
const stringify =
|
|
816
|
+
const stringify = import_shared6.RspackChain.toString;
|
|
662
817
|
return stringify(config, { verbose });
|
|
663
818
|
}
|
|
664
|
-
var import_node_fs, import_node_path4,
|
|
819
|
+
var import_node_fs, import_node_path4, import_shared6, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath, normalizePublicDirs;
|
|
665
820
|
var init_config = __esm({
|
|
666
821
|
"src/config.ts"() {
|
|
667
822
|
"use strict";
|
|
668
823
|
import_node_fs = __toESM(require("fs"));
|
|
669
824
|
import_node_path4 = require("path");
|
|
670
|
-
|
|
825
|
+
import_shared6 = require("@rsbuild/shared");
|
|
671
826
|
init_constants();
|
|
672
827
|
init_helpers();
|
|
828
|
+
init_logger();
|
|
673
829
|
init_mergeConfig();
|
|
674
830
|
init_restart();
|
|
675
831
|
getDefaultDevConfig = () => ({
|
|
676
832
|
hmr: true,
|
|
677
833
|
liveReload: true,
|
|
678
|
-
assetPrefix:
|
|
834
|
+
assetPrefix: import_shared6.DEFAULT_ASSET_PREFIX,
|
|
679
835
|
startUrl: false,
|
|
680
836
|
client: {
|
|
681
837
|
overlay: true
|
|
@@ -750,7 +906,7 @@ var init_config = __esm({
|
|
|
750
906
|
server: SERVER_DIST_DIR,
|
|
751
907
|
worker: SERVICE_WORKER_DIST_DIR
|
|
752
908
|
},
|
|
753
|
-
assetPrefix:
|
|
909
|
+
assetPrefix: import_shared6.DEFAULT_ASSET_PREFIX,
|
|
754
910
|
filename: {},
|
|
755
911
|
charset: "ascii",
|
|
756
912
|
polyfill: "usage",
|
|
@@ -810,7 +966,7 @@ var init_config = __esm({
|
|
|
810
966
|
if (import_node_fs.default.existsSync(customConfigPath)) {
|
|
811
967
|
return customConfigPath;
|
|
812
968
|
}
|
|
813
|
-
|
|
969
|
+
import_rslog.logger.warn(`Cannot find config file: ${import_shared6.color.dim(customConfigPath)}
|
|
814
970
|
`);
|
|
815
971
|
}
|
|
816
972
|
const CONFIG_FILES = [
|
|
@@ -860,7 +1016,7 @@ var init_config = __esm({
|
|
|
860
1016
|
// src/loadEnv.ts
|
|
861
1017
|
function loadEnv({
|
|
862
1018
|
cwd = process.cwd(),
|
|
863
|
-
mode = (0,
|
|
1019
|
+
mode = (0, import_shared7.getNodeEnv)(),
|
|
864
1020
|
prefixes = ["PUBLIC_"]
|
|
865
1021
|
} = {}) {
|
|
866
1022
|
if (mode === "local") {
|
|
@@ -910,13 +1066,13 @@ function loadEnv({
|
|
|
910
1066
|
publicVars
|
|
911
1067
|
};
|
|
912
1068
|
}
|
|
913
|
-
var import_node_fs2, import_node_path5,
|
|
1069
|
+
var import_node_fs2, import_node_path5, import_shared7, import_dotenv, import_dotenv_expand;
|
|
914
1070
|
var init_loadEnv = __esm({
|
|
915
1071
|
"src/loadEnv.ts"() {
|
|
916
1072
|
"use strict";
|
|
917
1073
|
import_node_fs2 = __toESM(require("fs"));
|
|
918
1074
|
import_node_path5 = require("path");
|
|
919
|
-
|
|
1075
|
+
import_shared7 = require("@rsbuild/shared");
|
|
920
1076
|
import_dotenv = require("../compiled/dotenv/index.js");
|
|
921
1077
|
import_dotenv_expand = require("../compiled/dotenv-expand/index.js");
|
|
922
1078
|
init_helpers();
|
|
@@ -929,7 +1085,7 @@ function createAsyncHook() {
|
|
|
929
1085
|
const postGroup = [];
|
|
930
1086
|
const defaultGroup = [];
|
|
931
1087
|
const tap = (cb) => {
|
|
932
|
-
if ((0,
|
|
1088
|
+
if ((0, import_shared8.isFunction)(cb)) {
|
|
933
1089
|
defaultGroup.push(cb);
|
|
934
1090
|
} else if (cb.order === "pre") {
|
|
935
1091
|
preGroup.push(cb.handler);
|
|
@@ -976,11 +1132,11 @@ function initHooks() {
|
|
|
976
1132
|
modifyRsbuildConfig: createAsyncHook()
|
|
977
1133
|
};
|
|
978
1134
|
}
|
|
979
|
-
var
|
|
1135
|
+
var import_shared8;
|
|
980
1136
|
var init_initHooks = __esm({
|
|
981
1137
|
"src/initHooks.ts"() {
|
|
982
1138
|
"use strict";
|
|
983
|
-
|
|
1139
|
+
import_shared8 = require("@rsbuild/shared");
|
|
984
1140
|
}
|
|
985
1141
|
});
|
|
986
1142
|
|
|
@@ -994,17 +1150,18 @@ function getEntryObject(config, target) {
|
|
|
994
1150
|
if (!config.source?.entry) {
|
|
995
1151
|
return {};
|
|
996
1152
|
}
|
|
997
|
-
return (0,
|
|
1153
|
+
return (0, import_shared9.reduceConfigsMergeContext)({
|
|
998
1154
|
initial: {},
|
|
999
1155
|
config: config.source?.entry,
|
|
1000
1156
|
ctx: { target }
|
|
1001
1157
|
});
|
|
1002
1158
|
}
|
|
1003
|
-
var
|
|
1159
|
+
var import_shared9, pluginEntry;
|
|
1004
1160
|
var init_entry = __esm({
|
|
1005
1161
|
"src/plugins/entry.ts"() {
|
|
1006
1162
|
"use strict";
|
|
1007
|
-
|
|
1163
|
+
import_shared9 = require("@rsbuild/shared");
|
|
1164
|
+
init_helpers();
|
|
1008
1165
|
pluginEntry = () => ({
|
|
1009
1166
|
name: "rsbuild:entry",
|
|
1010
1167
|
setup(api) {
|
|
@@ -1021,18 +1178,18 @@ var init_entry = __esm({
|
|
|
1021
1178
|
};
|
|
1022
1179
|
preEntry.forEach(addEntry);
|
|
1023
1180
|
if (injectCoreJsEntry) {
|
|
1024
|
-
addEntry(
|
|
1181
|
+
addEntry(createVirtualModule('import "core-js";'));
|
|
1025
1182
|
}
|
|
1026
|
-
(0,
|
|
1183
|
+
(0, import_shared9.castArray)(entry[entryName]).forEach(addEntry);
|
|
1027
1184
|
}
|
|
1028
1185
|
}
|
|
1029
1186
|
);
|
|
1030
1187
|
api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
|
|
1031
1188
|
if (bundlerConfigs.every((config) => !config.entry)) {
|
|
1032
1189
|
throw new Error(
|
|
1033
|
-
`Could not find any entry module, please make sure that ${
|
|
1190
|
+
`Could not find any entry module, please make sure that ${import_shared9.color.cyan(
|
|
1034
1191
|
"src/index.(ts|js|tsx|jsx|mjs|cjs)"
|
|
1035
|
-
)} exists, or customize entry through the ${
|
|
1192
|
+
)} exists, or customize entry through the ${import_shared9.color.cyan(
|
|
1036
1193
|
"source.entry"
|
|
1037
1194
|
)} configuration.`
|
|
1038
1195
|
);
|
|
@@ -1048,7 +1205,7 @@ function getAbsolutePath(root, filepath) {
|
|
|
1048
1205
|
return (0, import_node_path6.isAbsolute)(filepath) ? filepath : (0, import_node_path6.join)(root, filepath);
|
|
1049
1206
|
}
|
|
1050
1207
|
function getAbsoluteDistPath(cwd, config) {
|
|
1051
|
-
const dirRoot =
|
|
1208
|
+
const dirRoot = config.output?.distPath?.root ?? ROOT_DIST_DIR;
|
|
1052
1209
|
return getAbsolutePath(cwd, dirRoot);
|
|
1053
1210
|
}
|
|
1054
1211
|
async function createContextByConfig(options, bundlerType, config = {}) {
|
|
@@ -1060,7 +1217,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
|
|
|
1060
1217
|
return {
|
|
1061
1218
|
entry: getEntryObject(config, "web"),
|
|
1062
1219
|
targets: config.output?.targets || [],
|
|
1063
|
-
version: "0.7.
|
|
1220
|
+
version: "0.7.9",
|
|
1064
1221
|
rootPath,
|
|
1065
1222
|
distPath,
|
|
1066
1223
|
cachePath,
|
|
@@ -1102,7 +1259,7 @@ function createPublicContext(context) {
|
|
|
1102
1259
|
return void 0;
|
|
1103
1260
|
},
|
|
1104
1261
|
set(_, prop) {
|
|
1105
|
-
|
|
1262
|
+
import_rslog.logger.error(
|
|
1106
1263
|
`Context is readonly, you can not assign to the "context.${prop}" prop.`
|
|
1107
1264
|
);
|
|
1108
1265
|
return true;
|
|
@@ -1123,23 +1280,23 @@ async function createContext(options, userRsbuildConfig, bundlerType) {
|
|
|
1123
1280
|
originalConfig: userRsbuildConfig
|
|
1124
1281
|
};
|
|
1125
1282
|
}
|
|
1126
|
-
var import_node_path6
|
|
1283
|
+
var import_node_path6;
|
|
1127
1284
|
var init_createContext = __esm({
|
|
1128
1285
|
"src/createContext.ts"() {
|
|
1129
1286
|
"use strict";
|
|
1130
1287
|
import_node_path6 = require("path");
|
|
1131
|
-
import_shared9 = require("@rsbuild/shared");
|
|
1132
1288
|
init_config();
|
|
1289
|
+
init_constants();
|
|
1133
1290
|
init_initHooks();
|
|
1291
|
+
init_logger();
|
|
1134
1292
|
init_entry();
|
|
1135
1293
|
}
|
|
1136
1294
|
});
|
|
1137
1295
|
|
|
1138
1296
|
// src/initPlugins.ts
|
|
1139
1297
|
function getHTMLPathByEntry(entryName, config) {
|
|
1140
|
-
const htmlPath = (0, import_shared10.getDistPath)(config, "html");
|
|
1141
1298
|
const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
|
|
1142
|
-
return
|
|
1299
|
+
return removeLeadingSlash(`${config.output.distPath.html}/${filename}`);
|
|
1143
1300
|
}
|
|
1144
1301
|
function applyTransformPlugin(chain, transformer) {
|
|
1145
1302
|
const name = "RsbuildTransformPlugin";
|
|
@@ -1256,14 +1413,14 @@ function getPluginAPI({
|
|
|
1256
1413
|
modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap
|
|
1257
1414
|
};
|
|
1258
1415
|
}
|
|
1259
|
-
var import_node_path7
|
|
1416
|
+
var import_node_path7;
|
|
1260
1417
|
var init_initPlugins = __esm({
|
|
1261
1418
|
"src/initPlugins.ts"() {
|
|
1262
1419
|
"use strict";
|
|
1263
1420
|
import_node_path7 = require("path");
|
|
1264
|
-
import_shared10 = require("@rsbuild/shared");
|
|
1265
1421
|
init_constants();
|
|
1266
1422
|
init_createContext();
|
|
1423
|
+
init_helpers();
|
|
1267
1424
|
}
|
|
1268
1425
|
});
|
|
1269
1426
|
|
|
@@ -1304,18 +1461,18 @@ function validatePlugin(plugin) {
|
|
|
1304
1461
|
`Expect Rsbuild plugin instance to be an object, but got ${type}.`
|
|
1305
1462
|
);
|
|
1306
1463
|
}
|
|
1307
|
-
if ((0,
|
|
1464
|
+
if ((0, import_shared10.isFunction)(plugin.setup)) {
|
|
1308
1465
|
return;
|
|
1309
1466
|
}
|
|
1310
|
-
if ((0,
|
|
1467
|
+
if ((0, import_shared10.isFunction)(plugin.apply)) {
|
|
1311
1468
|
const { name = "SomeWebpackPlugin" } = plugin.constructor || {};
|
|
1312
1469
|
const messages = [
|
|
1313
|
-
`${
|
|
1470
|
+
`${import_shared10.color.yellow(
|
|
1314
1471
|
name
|
|
1315
|
-
)} looks like a Webpack or Rspack plugin, please use ${
|
|
1472
|
+
)} looks like a Webpack or Rspack plugin, please use ${import_shared10.color.yellow(
|
|
1316
1473
|
"`tools.rspack`"
|
|
1317
1474
|
)} to register it:`,
|
|
1318
|
-
|
|
1475
|
+
import_shared10.color.green(`
|
|
1319
1476
|
// rsbuild.config.ts
|
|
1320
1477
|
export default {
|
|
1321
1478
|
tools: {
|
|
@@ -1342,13 +1499,13 @@ function createPluginManager() {
|
|
|
1342
1499
|
}
|
|
1343
1500
|
validatePlugin(newPlugin);
|
|
1344
1501
|
if (plugins.find((item) => item.name === newPlugin.name)) {
|
|
1345
|
-
|
|
1502
|
+
import_rslog.logger.warn(
|
|
1346
1503
|
`Rsbuild plugin "${newPlugin.name}" registered multiple times.`
|
|
1347
1504
|
);
|
|
1348
1505
|
} else if (before) {
|
|
1349
1506
|
const index = plugins.findIndex((item) => item.name === before);
|
|
1350
1507
|
if (index === -1) {
|
|
1351
|
-
|
|
1508
|
+
import_rslog.logger.warn(`Plugin "${before}" does not exist.`);
|
|
1352
1509
|
plugins.push(newPlugin);
|
|
1353
1510
|
} else {
|
|
1354
1511
|
plugins.splice(index, 0, newPlugin);
|
|
@@ -1373,7 +1530,7 @@ async function initPlugins({
|
|
|
1373
1530
|
pluginAPI,
|
|
1374
1531
|
pluginManager
|
|
1375
1532
|
}) {
|
|
1376
|
-
|
|
1533
|
+
import_rslog.logger.debug("init plugins");
|
|
1377
1534
|
const plugins = pluginDagSort(pluginManager.getPlugins());
|
|
1378
1535
|
const removedPlugins = plugins.reduce((ret, plugin) => {
|
|
1379
1536
|
if (plugin.remove) {
|
|
@@ -1387,13 +1544,14 @@ async function initPlugins({
|
|
|
1387
1544
|
}
|
|
1388
1545
|
await plugin.setup(pluginAPI);
|
|
1389
1546
|
}
|
|
1390
|
-
|
|
1547
|
+
import_rslog.logger.debug("init plugins done");
|
|
1391
1548
|
}
|
|
1392
|
-
var
|
|
1549
|
+
var import_shared10, pluginDagSort;
|
|
1393
1550
|
var init_pluginManager = __esm({
|
|
1394
1551
|
"src/pluginManager.ts"() {
|
|
1395
1552
|
"use strict";
|
|
1396
|
-
|
|
1553
|
+
import_shared10 = require("@rsbuild/shared");
|
|
1554
|
+
init_logger();
|
|
1397
1555
|
pluginDagSort = (plugins) => {
|
|
1398
1556
|
let allLines = [];
|
|
1399
1557
|
function getPlugin(name) {
|
|
@@ -1464,9 +1622,9 @@ async function inspectConfig({
|
|
|
1464
1622
|
inspectOptions = {}
|
|
1465
1623
|
}) {
|
|
1466
1624
|
if (inspectOptions.env) {
|
|
1467
|
-
(0,
|
|
1468
|
-
} else if (!(0,
|
|
1469
|
-
(0,
|
|
1625
|
+
(0, import_shared11.setNodeEnv)(inspectOptions.env);
|
|
1626
|
+
} else if (!(0, import_shared11.getNodeEnv)()) {
|
|
1627
|
+
(0, import_shared11.setNodeEnv)("development");
|
|
1470
1628
|
}
|
|
1471
1629
|
const rspackConfigs = bundlerConfigs || (await initConfigs({
|
|
1472
1630
|
context,
|
|
@@ -1511,20 +1669,81 @@ async function inspectConfig({
|
|
|
1511
1669
|
}
|
|
1512
1670
|
};
|
|
1513
1671
|
}
|
|
1514
|
-
var import_node_path8,
|
|
1672
|
+
var import_node_path8, import_shared11;
|
|
1515
1673
|
var init_inspectConfig = __esm({
|
|
1516
1674
|
"src/provider/inspectConfig.ts"() {
|
|
1517
1675
|
"use strict";
|
|
1518
1676
|
import_node_path8 = require("path");
|
|
1519
|
-
|
|
1677
|
+
import_shared11 = require("@rsbuild/shared");
|
|
1520
1678
|
init_config();
|
|
1521
1679
|
init_initConfigs();
|
|
1522
1680
|
}
|
|
1523
1681
|
});
|
|
1524
1682
|
|
|
1683
|
+
// src/configChain.ts
|
|
1684
|
+
async function getBundlerChain() {
|
|
1685
|
+
const bundlerChain = new import_shared12.RspackChain();
|
|
1686
|
+
return bundlerChain;
|
|
1687
|
+
}
|
|
1688
|
+
async function modifyBundlerChain(context, utils) {
|
|
1689
|
+
import_rslog.logger.debug("modify bundler chain");
|
|
1690
|
+
const bundlerChain = await getBundlerChain();
|
|
1691
|
+
const [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.call(
|
|
1692
|
+
bundlerChain,
|
|
1693
|
+
utils
|
|
1694
|
+
);
|
|
1695
|
+
if (context.config.tools?.bundlerChain) {
|
|
1696
|
+
for (const item of (0, import_shared12.castArray)(context.config.tools.bundlerChain)) {
|
|
1697
|
+
await item(modifiedBundlerChain, utils);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
import_rslog.logger.debug("modify bundler chain done");
|
|
1701
|
+
return modifiedBundlerChain;
|
|
1702
|
+
}
|
|
1703
|
+
function chainToConfig(chain) {
|
|
1704
|
+
const config = chain.toConfig();
|
|
1705
|
+
const { entry } = config;
|
|
1706
|
+
if (!(0, import_shared12.isPlainObject)(entry)) {
|
|
1707
|
+
return config;
|
|
1708
|
+
}
|
|
1709
|
+
const formattedEntry = {};
|
|
1710
|
+
for (const [entryName, entryValue] of Object.entries(entry)) {
|
|
1711
|
+
const entryImport = [];
|
|
1712
|
+
let entryDescription = null;
|
|
1713
|
+
for (const item of (0, import_shared12.castArray)(entryValue)) {
|
|
1714
|
+
if (typeof item === "string") {
|
|
1715
|
+
entryImport.push(item);
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
if (item.import) {
|
|
1719
|
+
entryImport.push(...(0, import_shared12.castArray)(item.import));
|
|
1720
|
+
}
|
|
1721
|
+
if (entryDescription) {
|
|
1722
|
+
Object.assign(entryDescription, item);
|
|
1723
|
+
} else {
|
|
1724
|
+
entryDescription = item;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
formattedEntry[entryName] = entryDescription ? {
|
|
1728
|
+
...entryDescription,
|
|
1729
|
+
import: entryImport
|
|
1730
|
+
} : entryImport;
|
|
1731
|
+
}
|
|
1732
|
+
config.entry = formattedEntry;
|
|
1733
|
+
return config;
|
|
1734
|
+
}
|
|
1735
|
+
var import_shared12;
|
|
1736
|
+
var init_configChain = __esm({
|
|
1737
|
+
"src/configChain.ts"() {
|
|
1738
|
+
"use strict";
|
|
1739
|
+
import_shared12 = require("@rsbuild/shared");
|
|
1740
|
+
init_logger();
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
|
|
1525
1744
|
// src/provider/rspackConfig.ts
|
|
1526
1745
|
async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
1527
|
-
|
|
1746
|
+
import_rslog.logger.debug("modify Rspack config");
|
|
1528
1747
|
let [modifiedConfig] = await context.hooks.modifyRspackConfig.call(
|
|
1529
1748
|
rspackConfig,
|
|
1530
1749
|
utils
|
|
@@ -1537,7 +1756,7 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
|
1537
1756
|
mergeFn: utils.mergeConfig
|
|
1538
1757
|
});
|
|
1539
1758
|
}
|
|
1540
|
-
|
|
1759
|
+
import_rslog.logger.debug("modify Rspack config done");
|
|
1541
1760
|
return modifiedConfig;
|
|
1542
1761
|
}
|
|
1543
1762
|
async function getConfigUtils(config, chainUtils) {
|
|
@@ -1605,7 +1824,7 @@ async function generateRspackConfig({
|
|
|
1605
1824
|
ProvidePlugin,
|
|
1606
1825
|
HotModuleReplacementPlugin
|
|
1607
1826
|
} = import_core2.rspack;
|
|
1608
|
-
const chain = await
|
|
1827
|
+
const chain = await modifyBundlerChain(context, {
|
|
1609
1828
|
...chainUtils,
|
|
1610
1829
|
bundler: {
|
|
1611
1830
|
BannerPlugin,
|
|
@@ -1615,7 +1834,7 @@ async function generateRspackConfig({
|
|
|
1615
1834
|
HotModuleReplacementPlugin
|
|
1616
1835
|
}
|
|
1617
1836
|
});
|
|
1618
|
-
let rspackConfig =
|
|
1837
|
+
let rspackConfig = chainToConfig(chain);
|
|
1619
1838
|
rspackConfig = await modifyRspackConfig(
|
|
1620
1839
|
context,
|
|
1621
1840
|
rspackConfig,
|
|
@@ -1629,19 +1848,21 @@ var init_rspackConfig = __esm({
|
|
|
1629
1848
|
"use strict";
|
|
1630
1849
|
import_shared13 = require("@rsbuild/shared");
|
|
1631
1850
|
import_core2 = require("@rspack/core");
|
|
1851
|
+
init_configChain();
|
|
1852
|
+
init_logger();
|
|
1632
1853
|
init_pluginHelper();
|
|
1633
1854
|
}
|
|
1634
1855
|
});
|
|
1635
1856
|
|
|
1636
1857
|
// src/provider/initConfigs.ts
|
|
1637
1858
|
async function modifyRsbuildConfig(context) {
|
|
1638
|
-
|
|
1859
|
+
import_rslog.logger.debug("modify Rsbuild config");
|
|
1639
1860
|
const [modified] = await context.hooks.modifyRsbuildConfig.call(
|
|
1640
1861
|
context.config,
|
|
1641
1862
|
{ mergeRsbuildConfig }
|
|
1642
1863
|
);
|
|
1643
1864
|
context.config = modified;
|
|
1644
|
-
|
|
1865
|
+
import_rslog.logger.debug("modify Rsbuild config done");
|
|
1645
1866
|
}
|
|
1646
1867
|
async function initRsbuildConfig({
|
|
1647
1868
|
context,
|
|
@@ -1669,7 +1890,7 @@ async function initConfigs({
|
|
|
1669
1890
|
const rspackConfigs = await Promise.all(
|
|
1670
1891
|
targets.map((target) => generateRspackConfig({ target, context }))
|
|
1671
1892
|
);
|
|
1672
|
-
if (
|
|
1893
|
+
if (isDebug()) {
|
|
1673
1894
|
const inspect = () => {
|
|
1674
1895
|
const inspectOptions = {
|
|
1675
1896
|
verbose: true,
|
|
@@ -1690,13 +1911,12 @@ async function initConfigs({
|
|
|
1690
1911
|
rspackConfigs
|
|
1691
1912
|
};
|
|
1692
1913
|
}
|
|
1693
|
-
var import_shared14;
|
|
1694
1914
|
var init_initConfigs = __esm({
|
|
1695
1915
|
"src/provider/initConfigs.ts"() {
|
|
1696
1916
|
"use strict";
|
|
1697
|
-
import_shared14 = require("@rsbuild/shared");
|
|
1698
1917
|
init_config();
|
|
1699
1918
|
init_createContext();
|
|
1919
|
+
init_logger();
|
|
1700
1920
|
init_mergeConfig();
|
|
1701
1921
|
init_pluginManager();
|
|
1702
1922
|
init_inspectConfig();
|
|
@@ -1708,6 +1928,8 @@ var init_initConfigs = __esm({
|
|
|
1708
1928
|
var devMiddleware_exports = {};
|
|
1709
1929
|
__export(devMiddleware_exports, {
|
|
1710
1930
|
getDevMiddleware: () => getDevMiddleware,
|
|
1931
|
+
isClientCompiler: () => isClientCompiler,
|
|
1932
|
+
isNodeCompiler: () => isNodeCompiler,
|
|
1711
1933
|
setupServerHooks: () => setupServerHooks
|
|
1712
1934
|
});
|
|
1713
1935
|
function applyHMREntry({
|
|
@@ -1716,7 +1938,7 @@ function applyHMREntry({
|
|
|
1716
1938
|
clientConfig = {},
|
|
1717
1939
|
liveReload = true
|
|
1718
1940
|
}) {
|
|
1719
|
-
if (!
|
|
1941
|
+
if (!isClientCompiler(compiler)) {
|
|
1720
1942
|
return;
|
|
1721
1943
|
}
|
|
1722
1944
|
new compiler.webpack.DefinePlugin({
|
|
@@ -1729,13 +1951,27 @@ function applyHMREntry({
|
|
|
1729
1951
|
}).apply(compiler);
|
|
1730
1952
|
}
|
|
1731
1953
|
}
|
|
1732
|
-
var
|
|
1954
|
+
var isClientCompiler, isNodeCompiler, setupServerHooks, getDevMiddleware;
|
|
1733
1955
|
var init_devMiddleware = __esm({
|
|
1734
1956
|
"src/server/devMiddleware.ts"() {
|
|
1735
1957
|
"use strict";
|
|
1736
|
-
|
|
1958
|
+
init_helpers();
|
|
1959
|
+
isClientCompiler = (compiler) => {
|
|
1960
|
+
const { target } = compiler.options;
|
|
1961
|
+
if (target) {
|
|
1962
|
+
return Array.isArray(target) ? target.includes("web") : target === "web";
|
|
1963
|
+
}
|
|
1964
|
+
return false;
|
|
1965
|
+
};
|
|
1966
|
+
isNodeCompiler = (compiler) => {
|
|
1967
|
+
const { target } = compiler.options;
|
|
1968
|
+
if (target) {
|
|
1969
|
+
return Array.isArray(target) ? target.includes("node") : target === "node";
|
|
1970
|
+
}
|
|
1971
|
+
return false;
|
|
1972
|
+
};
|
|
1737
1973
|
setupServerHooks = (compiler, hookCallbacks) => {
|
|
1738
|
-
if (
|
|
1974
|
+
if (isNodeCompiler(compiler)) {
|
|
1739
1975
|
return;
|
|
1740
1976
|
}
|
|
1741
1977
|
const { compile, invalid, done } = compiler.hooks;
|
|
@@ -1758,7 +1994,7 @@ var init_devMiddleware = __esm({
|
|
|
1758
1994
|
}
|
|
1759
1995
|
setupServerHooks(compiler, callbacks);
|
|
1760
1996
|
};
|
|
1761
|
-
|
|
1997
|
+
applyToCompiler(multiCompiler, setupCompiler);
|
|
1762
1998
|
return webpackDevMiddleware(multiCompiler, restOptions);
|
|
1763
1999
|
};
|
|
1764
2000
|
};
|
|
@@ -1775,13 +2011,13 @@ async function createCompiler({
|
|
|
1775
2011
|
context,
|
|
1776
2012
|
rspackConfigs
|
|
1777
2013
|
}) {
|
|
1778
|
-
|
|
2014
|
+
import_rslog.logger.debug("create compiler");
|
|
1779
2015
|
await context.hooks.onBeforeCreateCompiler.call({
|
|
1780
2016
|
bundlerConfigs: rspackConfigs
|
|
1781
2017
|
});
|
|
1782
2018
|
if (!await isSatisfyRspackVersion(import_core3.rspack.rspackVersion)) {
|
|
1783
2019
|
throw new Error(
|
|
1784
|
-
`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${
|
|
2020
|
+
`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared14.color.green(
|
|
1785
2021
|
rspackMinVersion
|
|
1786
2022
|
)}`
|
|
1787
2023
|
);
|
|
@@ -1792,18 +2028,18 @@ async function createCompiler({
|
|
|
1792
2028
|
let isCompiling = false;
|
|
1793
2029
|
const logRspackVersion = () => {
|
|
1794
2030
|
if (!isVersionLogged) {
|
|
1795
|
-
|
|
2031
|
+
import_rslog.logger.debug(`Use Rspack v${import_core3.rspack.rspackVersion}`);
|
|
1796
2032
|
isVersionLogged = true;
|
|
1797
2033
|
}
|
|
1798
2034
|
};
|
|
1799
2035
|
compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
|
|
1800
2036
|
logRspackVersion();
|
|
1801
2037
|
if (!isCompiling) {
|
|
1802
|
-
|
|
2038
|
+
import_rslog.logger.start("Compiling...");
|
|
1803
2039
|
}
|
|
1804
2040
|
isCompiling = true;
|
|
1805
2041
|
});
|
|
1806
|
-
if ((0,
|
|
2042
|
+
if ((0, import_shared14.isProd)()) {
|
|
1807
2043
|
compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
|
|
1808
2044
|
}
|
|
1809
2045
|
const done = async (stats) => {
|
|
@@ -1813,10 +2049,10 @@ async function createCompiler({
|
|
|
1813
2049
|
});
|
|
1814
2050
|
const printTime = (c, index) => {
|
|
1815
2051
|
if (c.time) {
|
|
1816
|
-
const time = (0,
|
|
2052
|
+
const time = (0, import_shared14.prettyTime)(c.time / 1e3);
|
|
1817
2053
|
const target = context.targets[index];
|
|
1818
|
-
const name =
|
|
1819
|
-
|
|
2054
|
+
const name = TARGET_ID_MAP[target || "web"];
|
|
2055
|
+
import_rslog.logger.ready(`${name} compiled in ${time}`);
|
|
1820
2056
|
}
|
|
1821
2057
|
};
|
|
1822
2058
|
if (!stats.hasErrors()) {
|
|
@@ -1830,12 +2066,12 @@ async function createCompiler({
|
|
|
1830
2066
|
}
|
|
1831
2067
|
const { message, level } = formatStats(stats, getStatsOptions(compiler));
|
|
1832
2068
|
if (level === "error") {
|
|
1833
|
-
|
|
2069
|
+
import_rslog.logger.error(message);
|
|
1834
2070
|
}
|
|
1835
2071
|
if (level === "warning") {
|
|
1836
|
-
|
|
2072
|
+
import_rslog.logger.warn(message);
|
|
1837
2073
|
}
|
|
1838
|
-
if ((0,
|
|
2074
|
+
if ((0, import_shared14.isDev)()) {
|
|
1839
2075
|
await context.hooks.onDevCompileDone.call({
|
|
1840
2076
|
isFirstCompile,
|
|
1841
2077
|
stats
|
|
@@ -1844,14 +2080,14 @@ async function createCompiler({
|
|
|
1844
2080
|
isCompiling = false;
|
|
1845
2081
|
isFirstCompile = false;
|
|
1846
2082
|
};
|
|
1847
|
-
|
|
2083
|
+
onCompileDone(
|
|
1848
2084
|
compiler,
|
|
1849
2085
|
done,
|
|
1850
2086
|
// @ts-expect-error type mismatch
|
|
1851
2087
|
import_core3.rspack.MultiStats
|
|
1852
2088
|
);
|
|
1853
2089
|
await context.hooks.onAfterCreateCompiler.call({ compiler });
|
|
1854
|
-
|
|
2090
|
+
import_rslog.logger.debug("create compiler done");
|
|
1855
2091
|
return compiler;
|
|
1856
2092
|
}
|
|
1857
2093
|
async function createDevMiddleware(options, customCompiler) {
|
|
@@ -1871,25 +2107,28 @@ async function createDevMiddleware(options, customCompiler) {
|
|
|
1871
2107
|
compiler
|
|
1872
2108
|
};
|
|
1873
2109
|
}
|
|
1874
|
-
var
|
|
2110
|
+
var import_shared14, import_core3;
|
|
1875
2111
|
var init_createCompiler = __esm({
|
|
1876
2112
|
"src/provider/createCompiler.ts"() {
|
|
1877
2113
|
"use strict";
|
|
1878
|
-
|
|
2114
|
+
import_shared14 = require("@rsbuild/shared");
|
|
1879
2115
|
import_core3 = require("@rspack/core");
|
|
2116
|
+
init_constants();
|
|
1880
2117
|
init_helpers();
|
|
2118
|
+
init_logger();
|
|
1881
2119
|
init_initConfigs();
|
|
1882
2120
|
}
|
|
1883
2121
|
});
|
|
1884
2122
|
|
|
1885
2123
|
// src/server/middlewares.ts
|
|
1886
|
-
var import_node_path9, import_node_url,
|
|
2124
|
+
var import_node_path9, import_node_url, import_shared15, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
|
|
1887
2125
|
var init_middlewares = __esm({
|
|
1888
2126
|
"src/server/middlewares.ts"() {
|
|
1889
2127
|
"use strict";
|
|
1890
2128
|
import_node_path9 = __toESM(require("path"));
|
|
1891
2129
|
import_node_url = require("url");
|
|
1892
|
-
|
|
2130
|
+
import_shared15 = require("@rsbuild/shared");
|
|
2131
|
+
init_logger();
|
|
1893
2132
|
faviconFallbackMiddleware = (req, res, next) => {
|
|
1894
2133
|
if (req.url === "/favicon.ico") {
|
|
1895
2134
|
res.statusCode = 204;
|
|
@@ -1900,16 +2139,16 @@ var init_middlewares = __esm({
|
|
|
1900
2139
|
};
|
|
1901
2140
|
getStatusCodeColor = (status) => {
|
|
1902
2141
|
if (status >= 500) {
|
|
1903
|
-
return
|
|
2142
|
+
return import_shared15.color.red;
|
|
1904
2143
|
}
|
|
1905
2144
|
if (status >= 400) {
|
|
1906
|
-
return
|
|
2145
|
+
return import_shared15.color.yellow;
|
|
1907
2146
|
}
|
|
1908
2147
|
if (status >= 300) {
|
|
1909
|
-
return
|
|
2148
|
+
return import_shared15.color.cyan;
|
|
1910
2149
|
}
|
|
1911
2150
|
if (status >= 200) {
|
|
1912
|
-
return
|
|
2151
|
+
return import_shared15.color.green;
|
|
1913
2152
|
}
|
|
1914
2153
|
return (res) => res;
|
|
1915
2154
|
};
|
|
@@ -1924,8 +2163,8 @@ var init_middlewares = __esm({
|
|
|
1924
2163
|
const statusColor = getStatusCodeColor(status);
|
|
1925
2164
|
const endAt = process.hrtime();
|
|
1926
2165
|
const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
1927
|
-
|
|
1928
|
-
`${statusColor(status)} ${method} ${
|
|
2166
|
+
import_rslog.logger.debug(
|
|
2167
|
+
`${statusColor(status)} ${method} ${import_shared15.color.gray(url2)} ${import_shared15.color.gray(
|
|
1929
2168
|
`${totalTime.toFixed(3)} ms`
|
|
1930
2169
|
)}`
|
|
1931
2170
|
);
|
|
@@ -1954,8 +2193,8 @@ var init_middlewares = __esm({
|
|
|
1954
2193
|
try {
|
|
1955
2194
|
pathname = (0, import_node_url.parse)(url2, false, true).pathname;
|
|
1956
2195
|
} catch (err) {
|
|
1957
|
-
|
|
1958
|
-
new Error(`Invalid URL: ${
|
|
2196
|
+
import_rslog.logger.error(
|
|
2197
|
+
new Error(`Invalid URL: ${import_shared15.color.yellow(url2)}`, { cause: err })
|
|
1959
2198
|
);
|
|
1960
2199
|
return next();
|
|
1961
2200
|
}
|
|
@@ -1967,10 +2206,10 @@ var init_middlewares = __esm({
|
|
|
1967
2206
|
});
|
|
1968
2207
|
};
|
|
1969
2208
|
const rewrite = (newUrl, isFallback = false) => {
|
|
1970
|
-
if (isFallback &&
|
|
1971
|
-
|
|
1972
|
-
`${req.method} ${
|
|
1973
|
-
`${req.url} ${
|
|
2209
|
+
if (isFallback && import_rslog.logger.level === "verbose") {
|
|
2210
|
+
import_rslog.logger.debug(
|
|
2211
|
+
`${req.method} ${import_shared15.color.gray(
|
|
2212
|
+
`${req.url} ${import_shared15.color.yellow("fallback")} to ${newUrl}`
|
|
1974
2213
|
)}`
|
|
1975
2214
|
);
|
|
1976
2215
|
}
|
|
@@ -2036,18 +2275,18 @@ function formatProxyOptions(proxyOptions) {
|
|
|
2036
2275
|
ret.push(opts);
|
|
2037
2276
|
}
|
|
2038
2277
|
}
|
|
2039
|
-
const handleError = (err) =>
|
|
2278
|
+
const handleError = (err) => import_rslog.logger.error(err);
|
|
2040
2279
|
for (const opts of ret) {
|
|
2041
2280
|
opts.onError ??= handleError;
|
|
2042
2281
|
}
|
|
2043
2282
|
return ret;
|
|
2044
2283
|
}
|
|
2045
|
-
var
|
|
2284
|
+
var import_http_proxy_middleware, createProxyMiddleware;
|
|
2046
2285
|
var init_proxy = __esm({
|
|
2047
2286
|
"src/server/proxy.ts"() {
|
|
2048
2287
|
"use strict";
|
|
2049
|
-
import_shared18 = require("@rsbuild/shared");
|
|
2050
2288
|
import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
|
|
2289
|
+
init_logger();
|
|
2051
2290
|
createProxyMiddleware = (proxyOptions) => {
|
|
2052
2291
|
const formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
2053
2292
|
const proxyMiddlewares = [];
|
|
@@ -2087,14 +2326,14 @@ var init_proxy = __esm({
|
|
|
2087
2326
|
});
|
|
2088
2327
|
|
|
2089
2328
|
// src/server/getDevMiddlewares.ts
|
|
2090
|
-
var import_node_path10, import_node_url2,
|
|
2329
|
+
var import_node_path10, import_node_url2, applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
|
|
2091
2330
|
var init_getDevMiddlewares = __esm({
|
|
2092
2331
|
"src/server/getDevMiddlewares.ts"() {
|
|
2093
2332
|
"use strict";
|
|
2094
2333
|
import_node_path10 = require("path");
|
|
2095
2334
|
import_node_url2 = __toESM(require("url"));
|
|
2096
|
-
import_shared19 = require("@rsbuild/shared");
|
|
2097
2335
|
init_config();
|
|
2336
|
+
init_logger();
|
|
2098
2337
|
init_middlewares();
|
|
2099
2338
|
applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
|
|
2100
2339
|
const setupMiddlewares = dev.setupMiddlewares || [];
|
|
@@ -2212,7 +2451,7 @@ var init_getDevMiddlewares = __esm({
|
|
|
2212
2451
|
getMiddlewares = async (options) => {
|
|
2213
2452
|
const middlewares = [];
|
|
2214
2453
|
const { compileMiddlewareAPI } = options;
|
|
2215
|
-
if (
|
|
2454
|
+
if (import_rslog.logger.level === "verbose") {
|
|
2216
2455
|
middlewares.push(await getRequestLoggerMiddleware());
|
|
2217
2456
|
}
|
|
2218
2457
|
const { before, after } = applySetupMiddlewares(
|
|
@@ -2240,7 +2479,7 @@ var init_getDevMiddlewares = __esm({
|
|
|
2240
2479
|
function getURLMessages(urls, routes) {
|
|
2241
2480
|
if (routes.length === 1) {
|
|
2242
2481
|
return urls.map(
|
|
2243
|
-
({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${
|
|
2482
|
+
({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared16.color.cyan(
|
|
2244
2483
|
normalizeUrl(`${url2}${routes[0].pathname}`)
|
|
2245
2484
|
)}
|
|
2246
2485
|
`
|
|
@@ -2255,9 +2494,9 @@ function getURLMessages(urls, routes) {
|
|
|
2255
2494
|
message += ` ${`> ${label}`}
|
|
2256
2495
|
`;
|
|
2257
2496
|
for (const r of routes) {
|
|
2258
|
-
message += ` ${
|
|
2497
|
+
message += ` ${import_shared16.color.dim("-")} ${import_shared16.color.dim(
|
|
2259
2498
|
r.entryName.padEnd(maxNameLength + 4)
|
|
2260
|
-
)}${
|
|
2499
|
+
)}${import_shared16.color.cyan(normalizeUrl(`${url2}${r.pathname}`))}
|
|
2261
2500
|
`;
|
|
2262
2501
|
}
|
|
2263
2502
|
});
|
|
@@ -2274,7 +2513,7 @@ function printServerURLs({
|
|
|
2274
2513
|
return;
|
|
2275
2514
|
}
|
|
2276
2515
|
let urls = originalUrls;
|
|
2277
|
-
if ((0,
|
|
2516
|
+
if ((0, import_shared16.isFunction)(printUrls)) {
|
|
2278
2517
|
const newUrls = printUrls({
|
|
2279
2518
|
urls: urls.map((item) => item.url),
|
|
2280
2519
|
port,
|
|
@@ -2298,17 +2537,18 @@ function printServerURLs({
|
|
|
2298
2537
|
return;
|
|
2299
2538
|
}
|
|
2300
2539
|
const message = getURLMessages(urls, routes);
|
|
2301
|
-
|
|
2540
|
+
import_rslog.logger.log(message);
|
|
2302
2541
|
return message;
|
|
2303
2542
|
}
|
|
2304
|
-
var import_node_net, import_node_os,
|
|
2543
|
+
var import_node_net, import_node_os, import_shared16, normalizeUrl, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
|
|
2305
2544
|
var init_helper = __esm({
|
|
2306
2545
|
"src/server/helper.ts"() {
|
|
2307
2546
|
"use strict";
|
|
2308
2547
|
import_node_net = __toESM(require("net"));
|
|
2309
2548
|
import_node_os = __toESM(require("os"));
|
|
2310
|
-
|
|
2549
|
+
import_shared16 = require("@rsbuild/shared");
|
|
2311
2550
|
init_constants();
|
|
2551
|
+
init_logger();
|
|
2312
2552
|
normalizeUrl = (url2) => url2.replace(/([^:]\/)\/+/g, "$1");
|
|
2313
2553
|
formatPrefix = (prefix) => {
|
|
2314
2554
|
if (!prefix) {
|
|
@@ -2372,8 +2612,8 @@ var init_helper = __esm({
|
|
|
2372
2612
|
);
|
|
2373
2613
|
}
|
|
2374
2614
|
if (!silent) {
|
|
2375
|
-
|
|
2376
|
-
`Port ${original} is in use, ${
|
|
2615
|
+
import_rslog.logger.info(
|
|
2616
|
+
`Port ${original} is in use, ${import_shared16.color.yellow(`using port ${port}.`)}
|
|
2377
2617
|
`
|
|
2378
2618
|
);
|
|
2379
2619
|
}
|
|
@@ -2410,7 +2650,7 @@ var init_helper = __esm({
|
|
|
2410
2650
|
writeToDisk: false,
|
|
2411
2651
|
liveReload: true
|
|
2412
2652
|
};
|
|
2413
|
-
const devConfig = config.dev ? (0,
|
|
2653
|
+
const devConfig = config.dev ? (0, import_shared16.deepmerge)(defaultDevConfig, config.dev) : defaultDevConfig;
|
|
2414
2654
|
return devConfig;
|
|
2415
2655
|
};
|
|
2416
2656
|
getIpv4Interfaces = () => {
|
|
@@ -2596,12 +2836,12 @@ var init_watchFiles = __esm({
|
|
|
2596
2836
|
});
|
|
2597
2837
|
|
|
2598
2838
|
// src/server/socketServer.ts
|
|
2599
|
-
var
|
|
2839
|
+
var SocketServer;
|
|
2600
2840
|
var init_socketServer = __esm({
|
|
2601
2841
|
"src/server/socketServer.ts"() {
|
|
2602
2842
|
"use strict";
|
|
2603
|
-
import_shared21 = require("@rsbuild/shared");
|
|
2604
2843
|
init_helpers();
|
|
2844
|
+
init_logger();
|
|
2605
2845
|
SocketServer = class {
|
|
2606
2846
|
constructor(options) {
|
|
2607
2847
|
__publicField(this, "wsServer");
|
|
@@ -2627,7 +2867,7 @@ var init_socketServer = __esm({
|
|
|
2627
2867
|
path: this.options.client?.path
|
|
2628
2868
|
});
|
|
2629
2869
|
this.wsServer.on("error", (err) => {
|
|
2630
|
-
|
|
2870
|
+
import_rslog.logger.error(err);
|
|
2631
2871
|
});
|
|
2632
2872
|
this.timer = setInterval(() => {
|
|
2633
2873
|
for (const socket of this.wsServer.clients) {
|
|
@@ -2848,10 +3088,10 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2848
3088
|
getPortSilently,
|
|
2849
3089
|
runCompile = true
|
|
2850
3090
|
} = {}) {
|
|
2851
|
-
if (!(0,
|
|
2852
|
-
(0,
|
|
3091
|
+
if (!(0, import_shared17.getNodeEnv)()) {
|
|
3092
|
+
(0, import_shared17.setNodeEnv)("development");
|
|
2853
3093
|
}
|
|
2854
|
-
|
|
3094
|
+
import_rslog.logger.debug("create dev server");
|
|
2855
3095
|
const serverConfig = config.server;
|
|
2856
3096
|
const { port, host, https } = await getServerConfig({
|
|
2857
3097
|
config,
|
|
@@ -2878,7 +3118,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2878
3118
|
customCompiler
|
|
2879
3119
|
);
|
|
2880
3120
|
const { CompilerDevMiddleware: CompilerDevMiddleware2 } = await Promise.resolve().then(() => (init_compilerDevMiddleware(), compilerDevMiddleware_exports));
|
|
2881
|
-
const publicPaths =
|
|
3121
|
+
const publicPaths = isMultiCompiler(compiler) ? compiler.compilers.map(import_shared17.getPublicPathFromCompiler) : [(0, import_shared17.getPublicPathFromCompiler)(compiler)];
|
|
2882
3122
|
const compilerDevMiddleware = new CompilerDevMiddleware2({
|
|
2883
3123
|
dev: devConfig,
|
|
2884
3124
|
server: serverConfig,
|
|
@@ -2886,7 +3126,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2886
3126
|
devMiddleware
|
|
2887
3127
|
});
|
|
2888
3128
|
await compilerDevMiddleware.init();
|
|
2889
|
-
outputFileSystem = (
|
|
3129
|
+
outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || import_node_fs3.default;
|
|
2890
3130
|
return {
|
|
2891
3131
|
middleware: compilerDevMiddleware.middleware,
|
|
2892
3132
|
sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
|
|
@@ -2950,7 +3190,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2950
3190
|
serverConfig,
|
|
2951
3191
|
middlewares
|
|
2952
3192
|
});
|
|
2953
|
-
|
|
3193
|
+
import_rslog.logger.debug("listen dev server");
|
|
2954
3194
|
return new Promise((resolve) => {
|
|
2955
3195
|
httpServer.listen(
|
|
2956
3196
|
{
|
|
@@ -2963,7 +3203,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2963
3203
|
}
|
|
2964
3204
|
middlewares.use(notFoundMiddleware);
|
|
2965
3205
|
httpServer.on("upgrade", devMiddlewares.onUpgrade);
|
|
2966
|
-
|
|
3206
|
+
import_rslog.logger.debug("listen dev server done");
|
|
2967
3207
|
await server.afterListen();
|
|
2968
3208
|
const closeServer = async () => {
|
|
2969
3209
|
await server.close();
|
|
@@ -2994,16 +3234,18 @@ async function createDevServer(options, createDevMiddleware2, config, {
|
|
|
2994
3234
|
await fileWatcher?.close();
|
|
2995
3235
|
}
|
|
2996
3236
|
};
|
|
2997
|
-
|
|
3237
|
+
import_rslog.logger.debug("create dev server done");
|
|
2998
3238
|
return server;
|
|
2999
3239
|
}
|
|
3000
|
-
var import_node_fs3,
|
|
3240
|
+
var import_node_fs3, import_shared17;
|
|
3001
3241
|
var init_devServer = __esm({
|
|
3002
3242
|
"src/server/devServer.ts"() {
|
|
3003
3243
|
"use strict";
|
|
3004
3244
|
import_node_fs3 = __toESM(require("fs"));
|
|
3005
|
-
|
|
3245
|
+
import_shared17 = require("@rsbuild/shared");
|
|
3006
3246
|
init_constants();
|
|
3247
|
+
init_helpers();
|
|
3248
|
+
init_logger();
|
|
3007
3249
|
init_getDevMiddlewares();
|
|
3008
3250
|
init_helper();
|
|
3009
3251
|
init_httpServer();
|
|
@@ -3018,17 +3260,19 @@ var build_exports = {};
|
|
|
3018
3260
|
__export(build_exports, {
|
|
3019
3261
|
build: () => build
|
|
3020
3262
|
});
|
|
3021
|
-
var
|
|
3263
|
+
var import_shared18, import_core4, build;
|
|
3022
3264
|
var init_build = __esm({
|
|
3023
3265
|
"src/provider/build.ts"() {
|
|
3024
3266
|
"use strict";
|
|
3025
|
-
|
|
3267
|
+
import_shared18 = require("@rsbuild/shared");
|
|
3026
3268
|
import_core4 = require("@rspack/core");
|
|
3269
|
+
init_helpers();
|
|
3270
|
+
init_logger();
|
|
3027
3271
|
init_createCompiler();
|
|
3028
3272
|
init_initConfigs();
|
|
3029
3273
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
3030
|
-
if (!(0,
|
|
3031
|
-
(0,
|
|
3274
|
+
if (!(0, import_shared18.getNodeEnv)()) {
|
|
3275
|
+
(0, import_shared18.setNodeEnv)(mode);
|
|
3032
3276
|
}
|
|
3033
3277
|
const { context } = initOptions;
|
|
3034
3278
|
let compiler;
|
|
@@ -3052,7 +3296,7 @@ var init_build = __esm({
|
|
|
3052
3296
|
isFirstCompile = false;
|
|
3053
3297
|
await p;
|
|
3054
3298
|
};
|
|
3055
|
-
|
|
3299
|
+
onCompileDone(
|
|
3056
3300
|
compiler,
|
|
3057
3301
|
onDone,
|
|
3058
3302
|
// @ts-expect-error type mismatch
|
|
@@ -3061,7 +3305,7 @@ var init_build = __esm({
|
|
|
3061
3305
|
if (watch) {
|
|
3062
3306
|
compiler.watch({}, (err) => {
|
|
3063
3307
|
if (err) {
|
|
3064
|
-
|
|
3308
|
+
import_rslog.logger.error(err);
|
|
3065
3309
|
}
|
|
3066
3310
|
});
|
|
3067
3311
|
return;
|
|
@@ -3074,7 +3318,7 @@ var init_build = __esm({
|
|
|
3074
3318
|
} else {
|
|
3075
3319
|
compiler.close((closeErr) => {
|
|
3076
3320
|
if (closeErr) {
|
|
3077
|
-
|
|
3321
|
+
import_rslog.logger.error(closeErr);
|
|
3078
3322
|
}
|
|
3079
3323
|
resolve({ stats });
|
|
3080
3324
|
});
|
|
@@ -3169,22 +3413,30 @@ var basic_exports = {};
|
|
|
3169
3413
|
__export(basic_exports, {
|
|
3170
3414
|
pluginBasic: () => pluginBasic
|
|
3171
3415
|
});
|
|
3172
|
-
var import_node_path11,
|
|
3416
|
+
var import_node_path11, import_shared19, getJsSourceMap, pluginBasic;
|
|
3173
3417
|
var init_basic = __esm({
|
|
3174
3418
|
"src/plugins/basic.ts"() {
|
|
3175
3419
|
"use strict";
|
|
3176
3420
|
import_node_path11 = __toESM(require("path"));
|
|
3177
|
-
|
|
3421
|
+
import_shared19 = require("@rsbuild/shared");
|
|
3422
|
+
init_constants();
|
|
3423
|
+
getJsSourceMap = (config) => {
|
|
3424
|
+
const { sourceMap } = config.output;
|
|
3425
|
+
if (sourceMap.js === void 0) {
|
|
3426
|
+
return (0, import_shared19.isProd)() ? false : "cheap-module-source-map";
|
|
3427
|
+
}
|
|
3428
|
+
return sourceMap.js;
|
|
3429
|
+
};
|
|
3178
3430
|
pluginBasic = () => ({
|
|
3179
3431
|
name: "rsbuild:basic",
|
|
3180
3432
|
setup(api) {
|
|
3181
3433
|
api.modifyBundlerChain(
|
|
3182
|
-
(chain, { env, isProd:
|
|
3434
|
+
(chain, { env, isProd: isProd7, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
|
|
3183
3435
|
const config = api.getNormalizedConfig();
|
|
3184
|
-
chain.name(
|
|
3185
|
-
chain.devtool(
|
|
3436
|
+
chain.name(TARGET_ID_MAP[target]);
|
|
3437
|
+
chain.devtool(getJsSourceMap(config));
|
|
3186
3438
|
chain.context(api.context.rootPath);
|
|
3187
|
-
chain.mode(
|
|
3439
|
+
chain.mode(isProd7 ? "production" : "development");
|
|
3188
3440
|
chain.merge({
|
|
3189
3441
|
infrastructureLogging: {
|
|
3190
3442
|
// Using `error` level to avoid `cache.PackFileCacheStrategy` logs
|
|
@@ -3197,9 +3449,9 @@ var init_basic = __esm({
|
|
|
3197
3449
|
exportsPresence: "error"
|
|
3198
3450
|
}
|
|
3199
3451
|
});
|
|
3200
|
-
const isMinimize =
|
|
3452
|
+
const isMinimize = isProd7 && config.output.minify !== false;
|
|
3201
3453
|
chain.optimization.minimize(isMinimize);
|
|
3202
|
-
const usingHMR = (0,
|
|
3454
|
+
const usingHMR = (0, import_shared19.isUsingHMR)(config, { target, isProd: isProd7 });
|
|
3203
3455
|
if (usingHMR) {
|
|
3204
3456
|
chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
|
|
3205
3457
|
}
|
|
@@ -3225,13 +3477,13 @@ __export(cache_exports, {
|
|
|
3225
3477
|
async function validateCache(cacheDirectory, buildDependencies) {
|
|
3226
3478
|
const configFile = (0, import_node_path12.join)(cacheDirectory, "buildDependencies.json");
|
|
3227
3479
|
if (await isFileExists(configFile)) {
|
|
3228
|
-
const prevBuildDependencies = await
|
|
3480
|
+
const prevBuildDependencies = await import_shared20.fse.readJSON(configFile);
|
|
3229
3481
|
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
|
|
3230
3482
|
return;
|
|
3231
3483
|
}
|
|
3232
|
-
await
|
|
3484
|
+
await import_shared20.fse.remove(cacheDirectory);
|
|
3233
3485
|
}
|
|
3234
|
-
await
|
|
3486
|
+
await import_shared20.fse.outputJSON(configFile, buildDependencies);
|
|
3235
3487
|
}
|
|
3236
3488
|
function getDigestHash(digest) {
|
|
3237
3489
|
const fsHash = import_node_crypto.default.createHash("md5");
|
|
@@ -3270,13 +3522,13 @@ async function getBuildDependencies(context, config) {
|
|
|
3270
3522
|
}
|
|
3271
3523
|
return buildDependencies;
|
|
3272
3524
|
}
|
|
3273
|
-
var import_node_crypto, import_node_path12,
|
|
3525
|
+
var import_node_crypto, import_node_path12, import_shared20, pluginCache;
|
|
3274
3526
|
var init_cache = __esm({
|
|
3275
3527
|
"src/plugins/cache.ts"() {
|
|
3276
3528
|
"use strict";
|
|
3277
3529
|
import_node_crypto = __toESM(require("crypto"));
|
|
3278
3530
|
import_node_path12 = require("path");
|
|
3279
|
-
|
|
3531
|
+
import_shared20 = require("@rsbuild/shared");
|
|
3280
3532
|
init_helpers();
|
|
3281
3533
|
pluginCache = () => ({
|
|
3282
3534
|
name: "rsbuild:cache",
|
|
@@ -3316,11 +3568,11 @@ var target_exports = {};
|
|
|
3316
3568
|
__export(target_exports, {
|
|
3317
3569
|
pluginTarget: () => pluginTarget
|
|
3318
3570
|
});
|
|
3319
|
-
var
|
|
3571
|
+
var import_shared21, pluginTarget;
|
|
3320
3572
|
var init_target = __esm({
|
|
3321
3573
|
"src/plugins/target.ts"() {
|
|
3322
3574
|
"use strict";
|
|
3323
|
-
|
|
3575
|
+
import_shared21 = require("@rsbuild/shared");
|
|
3324
3576
|
pluginTarget = () => ({
|
|
3325
3577
|
name: "rsbuild:target",
|
|
3326
3578
|
setup(api) {
|
|
@@ -3332,12 +3584,12 @@ var init_target = __esm({
|
|
|
3332
3584
|
return;
|
|
3333
3585
|
}
|
|
3334
3586
|
const config = api.getNormalizedConfig();
|
|
3335
|
-
const browserslist = await (0,
|
|
3587
|
+
const browserslist = await (0, import_shared21.getBrowserslistWithDefault)(
|
|
3336
3588
|
api.context.rootPath,
|
|
3337
3589
|
config,
|
|
3338
3590
|
target
|
|
3339
3591
|
);
|
|
3340
|
-
const esVersion = (0,
|
|
3592
|
+
const esVersion = (0, import_shared21.browserslistToESVersion)(browserslist);
|
|
3341
3593
|
if (target === "web-worker" || target === "service-worker") {
|
|
3342
3594
|
chain.target(["webworker", `es${esVersion}`]);
|
|
3343
3595
|
return;
|
|
@@ -3381,16 +3633,16 @@ async function applyCSSRule({
|
|
|
3381
3633
|
rule,
|
|
3382
3634
|
config,
|
|
3383
3635
|
context,
|
|
3384
|
-
utils: { target, isProd:
|
|
3636
|
+
utils: { target, isProd: isProd7, CHAIN_ID: CHAIN_ID3 },
|
|
3385
3637
|
importLoaders = 1
|
|
3386
3638
|
}) {
|
|
3387
|
-
const browserslist = await (0,
|
|
3639
|
+
const browserslist = await (0, import_shared22.getBrowserslistWithDefault)(
|
|
3388
3640
|
context.rootPath,
|
|
3389
3641
|
config,
|
|
3390
3642
|
target
|
|
3391
3643
|
);
|
|
3392
3644
|
const enableExtractCSS = isUseCssExtract(config, target);
|
|
3393
|
-
const localIdentName = getCSSModulesLocalIdentName(config,
|
|
3645
|
+
const localIdentName = getCSSModulesLocalIdentName(config, isProd7);
|
|
3394
3646
|
const cssLoaderOptions = getCSSLoaderOptions({
|
|
3395
3647
|
config,
|
|
3396
3648
|
importLoaders,
|
|
@@ -3401,7 +3653,7 @@ async function applyCSSRule({
|
|
|
3401
3653
|
if (enableExtractCSS) {
|
|
3402
3654
|
rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
|
|
3403
3655
|
} else {
|
|
3404
|
-
const styleLoaderOptions = (0,
|
|
3656
|
+
const styleLoaderOptions = (0, import_shared22.reduceConfigs)({
|
|
3405
3657
|
initial: {},
|
|
3406
3658
|
config: config.tools.styleLoader
|
|
3407
3659
|
});
|
|
@@ -3422,19 +3674,19 @@ async function applyCSSRule({
|
|
|
3422
3674
|
rule.merge({ sideEffects: true });
|
|
3423
3675
|
rule.resolve.preferRelative(true);
|
|
3424
3676
|
}
|
|
3425
|
-
var import_node_path13,
|
|
3677
|
+
var import_node_path13, import_shared22, enableNativeCss, isUseCssExtract, getCSSModulesLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCSSLoaderOptions, pluginCss;
|
|
3426
3678
|
var init_css = __esm({
|
|
3427
3679
|
"src/plugins/css.ts"() {
|
|
3428
3680
|
"use strict";
|
|
3429
3681
|
import_node_path13 = __toESM(require("path"));
|
|
3430
|
-
|
|
3682
|
+
import_shared22 = require("@rsbuild/shared");
|
|
3431
3683
|
init_constants();
|
|
3432
3684
|
init_helpers();
|
|
3433
3685
|
init_pluginHelper();
|
|
3434
3686
|
enableNativeCss = (config) => !config.output.injectStyles;
|
|
3435
3687
|
isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
|
|
3436
|
-
getCSSModulesLocalIdentName = (config,
|
|
3437
|
-
(
|
|
3688
|
+
getCSSModulesLocalIdentName = (config, isProd7) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
|
|
3689
|
+
(isProd7 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
|
|
3438
3690
|
normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
|
|
3439
3691
|
if (options.modules && exportOnlyLocals) {
|
|
3440
3692
|
let { modules } = options;
|
|
@@ -3461,17 +3713,17 @@ var init_css = __esm({
|
|
|
3461
3713
|
userPostcssrcCache = /* @__PURE__ */ new Map();
|
|
3462
3714
|
applyAutoprefixer = async (plugins, browserslist, config) => {
|
|
3463
3715
|
const pluginObjects = plugins.map(
|
|
3464
|
-
(plugin) => (0,
|
|
3716
|
+
(plugin) => (0, import_shared22.isFunction)(plugin) ? plugin({}) : plugin
|
|
3465
3717
|
);
|
|
3466
3718
|
const hasAutoprefixer = pluginObjects.some((pluginObject) => {
|
|
3467
|
-
if ((0,
|
|
3719
|
+
if ((0, import_shared22.isPlainObject)(pluginObject) && "postcssPlugin" in pluginObject) {
|
|
3468
3720
|
return pluginObject.postcssPlugin === "autoprefixer";
|
|
3469
3721
|
}
|
|
3470
3722
|
return false;
|
|
3471
3723
|
});
|
|
3472
3724
|
if (!hasAutoprefixer) {
|
|
3473
3725
|
const { default: autoprefixer } = await import("@rsbuild/shared/autoprefixer");
|
|
3474
|
-
const autoprefixerOptions = (0,
|
|
3726
|
+
const autoprefixerOptions = (0, import_shared22.reduceConfigs)({
|
|
3475
3727
|
initial: {
|
|
3476
3728
|
flexbox: "no-2009",
|
|
3477
3729
|
overrideBrowserslist: browserslist
|
|
@@ -3511,7 +3763,7 @@ var init_css = __esm({
|
|
|
3511
3763
|
},
|
|
3512
3764
|
sourceMap: config.output.sourceMap.css
|
|
3513
3765
|
};
|
|
3514
|
-
const mergedConfig = (0,
|
|
3766
|
+
const mergedConfig = (0, import_shared22.reduceConfigsWithContext)({
|
|
3515
3767
|
initial: defaultPostcssConfig,
|
|
3516
3768
|
config: config.tools.postcss,
|
|
3517
3769
|
ctx: utils
|
|
@@ -3538,10 +3790,10 @@ var init_css = __esm({
|
|
|
3538
3790
|
},
|
|
3539
3791
|
sourceMap: config.output.sourceMap.css
|
|
3540
3792
|
};
|
|
3541
|
-
const mergedCssLoaderOptions = (0,
|
|
3793
|
+
const mergedCssLoaderOptions = (0, import_shared22.reduceConfigs)({
|
|
3542
3794
|
initial: defaultOptions2,
|
|
3543
3795
|
config: config.tools.cssLoader,
|
|
3544
|
-
mergeFn:
|
|
3796
|
+
mergeFn: import_shared22.deepmerge
|
|
3545
3797
|
});
|
|
3546
3798
|
const cssLoaderOptions = normalizeCssLoaderOptions(
|
|
3547
3799
|
mergedCssLoaderOptions,
|
|
@@ -3581,13 +3833,13 @@ __export(output_exports, {
|
|
|
3581
3833
|
pluginOutput: () => pluginOutput
|
|
3582
3834
|
});
|
|
3583
3835
|
function getPublicPath({
|
|
3584
|
-
isProd:
|
|
3836
|
+
isProd: isProd7,
|
|
3585
3837
|
config,
|
|
3586
3838
|
context
|
|
3587
3839
|
}) {
|
|
3588
3840
|
const { dev, output } = config;
|
|
3589
|
-
let publicPath =
|
|
3590
|
-
if (
|
|
3841
|
+
let publicPath = import_shared23.DEFAULT_ASSET_PREFIX;
|
|
3842
|
+
if (isProd7) {
|
|
3591
3843
|
if (typeof output.assetPrefix === "string") {
|
|
3592
3844
|
publicPath = output.assetPrefix;
|
|
3593
3845
|
}
|
|
@@ -3606,12 +3858,12 @@ function getPublicPath({
|
|
|
3606
3858
|
}
|
|
3607
3859
|
return formatPublicPath(publicPath);
|
|
3608
3860
|
}
|
|
3609
|
-
var import_node_path14,
|
|
3861
|
+
var import_node_path14, import_shared23, import_core5, pluginOutput;
|
|
3610
3862
|
var init_output = __esm({
|
|
3611
3863
|
"src/plugins/output.ts"() {
|
|
3612
3864
|
"use strict";
|
|
3613
3865
|
import_node_path14 = require("path");
|
|
3614
|
-
|
|
3866
|
+
import_shared23 = require("@rsbuild/shared");
|
|
3615
3867
|
import_core5 = require("@rspack/core");
|
|
3616
3868
|
init_constants();
|
|
3617
3869
|
init_helpers();
|
|
@@ -3621,16 +3873,16 @@ var init_output = __esm({
|
|
|
3621
3873
|
name: "rsbuild:output",
|
|
3622
3874
|
setup(api) {
|
|
3623
3875
|
api.modifyBundlerChain(
|
|
3624
|
-
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd:
|
|
3876
|
+
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd7, isServer, isServiceWorker }) => {
|
|
3625
3877
|
const config = api.getNormalizedConfig();
|
|
3626
3878
|
const publicPath = getPublicPath({
|
|
3627
3879
|
config,
|
|
3628
|
-
isProd:
|
|
3880
|
+
isProd: isProd7,
|
|
3629
3881
|
context: api.context
|
|
3630
3882
|
});
|
|
3631
|
-
const jsPath =
|
|
3632
|
-
const jsAsyncPath =
|
|
3633
|
-
const jsFilename =
|
|
3883
|
+
const jsPath = config.output.distPath.js;
|
|
3884
|
+
const jsAsyncPath = config.output.distPath.jsAsync ?? (jsPath ? `${jsPath}/async` : "async");
|
|
3885
|
+
const jsFilename = getFilename(config, "js", isProd7);
|
|
3634
3886
|
const isJsFilenameFn = typeof jsFilename === "function";
|
|
3635
3887
|
chain.output.path(api.context.distPath).filename(
|
|
3636
3888
|
isJsFilenameFn ? (...args) => {
|
|
@@ -3644,14 +3896,14 @@ var init_output = __esm({
|
|
|
3644
3896
|
} : import_node_path14.posix.join(jsAsyncPath, jsFilename)
|
|
3645
3897
|
).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
|
|
3646
3898
|
if (isServer) {
|
|
3647
|
-
const serverPath =
|
|
3899
|
+
const serverPath = config.output.distPath.server;
|
|
3648
3900
|
chain.output.path(import_node_path14.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
|
|
3649
3901
|
...chain.output.get("library") || {},
|
|
3650
3902
|
type: "commonjs2"
|
|
3651
3903
|
});
|
|
3652
3904
|
}
|
|
3653
3905
|
if (isServiceWorker) {
|
|
3654
|
-
const workerPath =
|
|
3906
|
+
const workerPath = config.output.distPath.worker;
|
|
3655
3907
|
const filename = import_node_path14.posix.join(workerPath, "[name].js");
|
|
3656
3908
|
chain.output.filename(filename).chunkFilename(filename);
|
|
3657
3909
|
}
|
|
@@ -3662,9 +3914,9 @@ var init_output = __esm({
|
|
|
3662
3914
|
}
|
|
3663
3915
|
if (isUseCssExtract(config, target)) {
|
|
3664
3916
|
const extractPluginOptions = config.tools.cssExtract.pluginOptions;
|
|
3665
|
-
const cssPath =
|
|
3666
|
-
const cssFilename =
|
|
3667
|
-
const cssAsyncPath =
|
|
3917
|
+
const cssPath = config.output.distPath.css;
|
|
3918
|
+
const cssFilename = getFilename(config, "css", isProd7);
|
|
3919
|
+
const cssAsyncPath = config.output.distPath.cssAsync ?? (cssPath ? `${cssPath}/async` : "async");
|
|
3668
3920
|
chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
|
|
3669
3921
|
{
|
|
3670
3922
|
filename: import_node_path14.posix.join(cssPath, cssFilename),
|
|
@@ -3713,13 +3965,13 @@ function applyAlias({
|
|
|
3713
3965
|
if (!alias) {
|
|
3714
3966
|
return;
|
|
3715
3967
|
}
|
|
3716
|
-
const mergedAlias = (0,
|
|
3968
|
+
const mergedAlias = (0, import_shared24.reduceConfigsWithContext)({
|
|
3717
3969
|
initial: {},
|
|
3718
3970
|
config: alias,
|
|
3719
3971
|
ctx: { target }
|
|
3720
3972
|
});
|
|
3721
3973
|
for (const name of Object.keys(mergedAlias)) {
|
|
3722
|
-
const values = (0,
|
|
3974
|
+
const values = (0, import_shared24.castArray)(mergedAlias[name]);
|
|
3723
3975
|
const formattedValues = values.map((value) => {
|
|
3724
3976
|
if (typeof value === "string" && value.startsWith(".")) {
|
|
3725
3977
|
return ensureAbsolutePath(rootPath, value);
|
|
@@ -3732,11 +3984,11 @@ function applyAlias({
|
|
|
3732
3984
|
);
|
|
3733
3985
|
}
|
|
3734
3986
|
}
|
|
3735
|
-
var
|
|
3987
|
+
var import_shared24, pluginResolve;
|
|
3736
3988
|
var init_resolve = __esm({
|
|
3737
3989
|
"src/plugins/resolve.ts"() {
|
|
3738
3990
|
"use strict";
|
|
3739
|
-
|
|
3991
|
+
import_shared24 = require("@rsbuild/shared");
|
|
3740
3992
|
init_helpers();
|
|
3741
3993
|
pluginResolve = () => ({
|
|
3742
3994
|
name: "rsbuild:resolve",
|
|
@@ -3784,7 +4036,7 @@ async function printHeader(longestFileLength, longestLabelLength) {
|
|
|
3784
4036
|
}
|
|
3785
4037
|
return `${prev + curLabel} `;
|
|
3786
4038
|
}, " ");
|
|
3787
|
-
|
|
4039
|
+
import_rslog.logger.log(import_shared26.color.bold(import_shared26.color.blue(headerRow)));
|
|
3788
4040
|
}
|
|
3789
4041
|
async function printFileSizes(config, stats, rootPath) {
|
|
3790
4042
|
if (config.detail === false && config.total === false) {
|
|
@@ -3793,7 +4045,7 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3793
4045
|
const { default: gzipSize } = await import("@rsbuild/shared/gzip-size");
|
|
3794
4046
|
const formatAsset = (asset, distPath, distFolder) => {
|
|
3795
4047
|
const fileName = asset.name.split("?")[0];
|
|
3796
|
-
const contents =
|
|
4048
|
+
const contents = import_shared25.fse.readFileSync(import_node_path15.default.join(distPath, fileName));
|
|
3797
4049
|
const size = contents.length;
|
|
3798
4050
|
const gzippedSize = gzipSize.sync(contents);
|
|
3799
4051
|
return {
|
|
@@ -3835,7 +4087,7 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3835
4087
|
return;
|
|
3836
4088
|
}
|
|
3837
4089
|
assets.sort((a, b) => a.size - b.size);
|
|
3838
|
-
|
|
4090
|
+
import_rslog.logger.info("Production file sizes:\n");
|
|
3839
4091
|
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
3840
4092
|
const longestFileLength = Math.max(
|
|
3841
4093
|
...assets.map((a) => (a.folder + import_node_path15.default.sep + a.name).length)
|
|
@@ -3857,60 +4109,61 @@ async function printFileSizes(config, stats, rootPath) {
|
|
|
3857
4109
|
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
3858
4110
|
sizeLabel += rightPadding;
|
|
3859
4111
|
}
|
|
3860
|
-
let fileNameLabel =
|
|
4112
|
+
let fileNameLabel = import_shared26.color.dim(asset.folder + import_node_path15.default.sep) + coloringAssetName(asset.name);
|
|
3861
4113
|
if (fileNameLength < longestFileLength) {
|
|
3862
4114
|
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
3863
4115
|
fileNameLabel += rightPadding;
|
|
3864
4116
|
}
|
|
3865
|
-
|
|
4117
|
+
import_rslog.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
3866
4118
|
}
|
|
3867
4119
|
}
|
|
3868
4120
|
if (config.total !== false) {
|
|
3869
|
-
const totalSizeLabel = `${
|
|
3870
|
-
|
|
4121
|
+
const totalSizeLabel = `${import_shared26.color.bold(
|
|
4122
|
+
import_shared26.color.blue("Total size:")
|
|
3871
4123
|
)} ${calcFileSize(totalSize)}`;
|
|
3872
|
-
const gzippedSizeLabel = `${
|
|
3873
|
-
|
|
4124
|
+
const gzippedSizeLabel = `${import_shared26.color.bold(
|
|
4125
|
+
import_shared26.color.blue("Gzipped size:")
|
|
3874
4126
|
)} ${calcFileSize(totalGzipSize)}`;
|
|
3875
|
-
|
|
4127
|
+
import_rslog.logger.log(`
|
|
3876
4128
|
${totalSizeLabel}
|
|
3877
4129
|
${gzippedSizeLabel}
|
|
3878
4130
|
`);
|
|
3879
4131
|
}
|
|
3880
4132
|
}
|
|
3881
|
-
var import_node_path15,
|
|
4133
|
+
var import_node_path15, import_shared25, import_shared26, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
|
|
3882
4134
|
var init_fileSize = __esm({
|
|
3883
4135
|
"src/plugins/fileSize.ts"() {
|
|
3884
4136
|
"use strict";
|
|
3885
4137
|
import_node_path15 = __toESM(require("path"));
|
|
3886
|
-
|
|
3887
|
-
|
|
4138
|
+
import_shared25 = require("@rsbuild/shared");
|
|
4139
|
+
import_shared26 = require("@rsbuild/shared");
|
|
3888
4140
|
init_constants();
|
|
4141
|
+
init_logger();
|
|
3889
4142
|
filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
3890
4143
|
getAssetColor = (size) => {
|
|
3891
4144
|
if (size > 300 * 1e3) {
|
|
3892
|
-
return
|
|
4145
|
+
return import_shared26.color.red;
|
|
3893
4146
|
}
|
|
3894
4147
|
if (size > 100 * 1e3) {
|
|
3895
|
-
return
|
|
4148
|
+
return import_shared26.color.yellow;
|
|
3896
4149
|
}
|
|
3897
|
-
return
|
|
4150
|
+
return import_shared26.color.green;
|
|
3898
4151
|
};
|
|
3899
4152
|
calcFileSize = (len) => {
|
|
3900
4153
|
const val = len / 1e3;
|
|
3901
4154
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
3902
4155
|
};
|
|
3903
4156
|
coloringAssetName = (assetName) => {
|
|
3904
|
-
if (
|
|
3905
|
-
return
|
|
4157
|
+
if (import_shared25.JS_REGEX.test(assetName)) {
|
|
4158
|
+
return import_shared26.color.cyan(assetName);
|
|
3906
4159
|
}
|
|
3907
4160
|
if (CSS_REGEX.test(assetName)) {
|
|
3908
|
-
return
|
|
4161
|
+
return import_shared26.color.yellow(assetName);
|
|
3909
4162
|
}
|
|
3910
4163
|
if (HTML_REGEX.test(assetName)) {
|
|
3911
|
-
return
|
|
4164
|
+
return import_shared26.color.green(assetName);
|
|
3912
4165
|
}
|
|
3913
|
-
return
|
|
4166
|
+
return import_shared26.color.magenta(assetName);
|
|
3914
4167
|
};
|
|
3915
4168
|
pluginFileSize = () => ({
|
|
3916
4169
|
name: "rsbuild:file-size",
|
|
@@ -3932,8 +4185,8 @@ var init_fileSize = __esm({
|
|
|
3932
4185
|
api.context.rootPath
|
|
3933
4186
|
);
|
|
3934
4187
|
} catch (err) {
|
|
3935
|
-
|
|
3936
|
-
|
|
4188
|
+
import_rslog.logger.warn("Failed to print file size.");
|
|
4189
|
+
import_rslog.logger.warn(err);
|
|
3937
4190
|
}
|
|
3938
4191
|
}
|
|
3939
4192
|
});
|
|
@@ -3947,15 +4200,16 @@ var cleanOutput_exports = {};
|
|
|
3947
4200
|
__export(cleanOutput_exports, {
|
|
3948
4201
|
pluginCleanOutput: () => pluginCleanOutput
|
|
3949
4202
|
});
|
|
3950
|
-
var import_node_path16,
|
|
4203
|
+
var import_node_path16, import_shared27, emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
|
|
3951
4204
|
var init_cleanOutput = __esm({
|
|
3952
4205
|
"src/plugins/cleanOutput.ts"() {
|
|
3953
4206
|
"use strict";
|
|
3954
4207
|
import_node_path16 = require("path");
|
|
3955
|
-
|
|
4208
|
+
import_shared27 = require("@rsbuild/shared");
|
|
4209
|
+
init_logger();
|
|
3956
4210
|
emptyDir = async (dir) => {
|
|
3957
|
-
if (await
|
|
3958
|
-
await
|
|
4211
|
+
if (await import_shared27.fse.pathExists(dir)) {
|
|
4212
|
+
await import_shared27.fse.emptyDir(dir);
|
|
3959
4213
|
}
|
|
3960
4214
|
};
|
|
3961
4215
|
addTrailingSep = (dir) => dir.endsWith(import_node_path16.sep) ? dir : dir + import_node_path16.sep;
|
|
@@ -3974,14 +4228,14 @@ var init_cleanOutput = __esm({
|
|
|
3974
4228
|
if (cleanDistPath === void 0) {
|
|
3975
4229
|
cleanDistPath = isStrictSubdir(rootPath, distPath);
|
|
3976
4230
|
if (!cleanDistPath) {
|
|
3977
|
-
|
|
4231
|
+
import_rslog.logger.warn(
|
|
3978
4232
|
"The dist path is not a subdir of root path, Rsbuild will not empty it."
|
|
3979
4233
|
);
|
|
3980
|
-
|
|
3981
|
-
`Please set ${
|
|
4234
|
+
import_rslog.logger.warn(
|
|
4235
|
+
`Please set ${import_shared27.color.yellow("`output.cleanDistPath`")} config manually.`
|
|
3982
4236
|
);
|
|
3983
|
-
|
|
3984
|
-
|
|
4237
|
+
import_rslog.logger.warn(`Current root path: ${import_shared27.color.dim(rootPath)}`);
|
|
4238
|
+
import_rslog.logger.warn(`Current dist path: ${import_shared27.color.dim(distPath)}`);
|
|
3985
4239
|
}
|
|
3986
4240
|
}
|
|
3987
4241
|
if (cleanDistPath) {
|
|
@@ -4008,13 +4262,13 @@ function getRegExpForExts(exts) {
|
|
|
4008
4262
|
"i"
|
|
4009
4263
|
);
|
|
4010
4264
|
}
|
|
4011
|
-
var import_node_path17,
|
|
4265
|
+
var import_node_path17, chainStaticAssetRule, pluginAsset;
|
|
4012
4266
|
var init_asset = __esm({
|
|
4013
4267
|
"src/plugins/asset.ts"() {
|
|
4014
4268
|
"use strict";
|
|
4015
4269
|
import_node_path17 = __toESM(require("path"));
|
|
4016
|
-
import_shared33 = require("@rsbuild/shared");
|
|
4017
4270
|
init_constants();
|
|
4271
|
+
init_helpers();
|
|
4018
4272
|
chainStaticAssetRule = ({
|
|
4019
4273
|
emit,
|
|
4020
4274
|
rule,
|
|
@@ -4039,12 +4293,12 @@ var init_asset = __esm({
|
|
|
4039
4293
|
pluginAsset = () => ({
|
|
4040
4294
|
name: "rsbuild:asset",
|
|
4041
4295
|
setup(api) {
|
|
4042
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
4296
|
+
api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
|
|
4043
4297
|
const config = api.getNormalizedConfig();
|
|
4044
4298
|
const createAssetRule = (assetType, exts, emit2) => {
|
|
4045
4299
|
const regExp = getRegExpForExts(exts);
|
|
4046
|
-
const distDir =
|
|
4047
|
-
const filename =
|
|
4300
|
+
const distDir = config.output.distPath[assetType];
|
|
4301
|
+
const filename = getFilename(config, assetType, isProd7);
|
|
4048
4302
|
const { dataUriLimit } = config.output;
|
|
4049
4303
|
const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
|
|
4050
4304
|
const rule = chain.module.rule(assetType).test(regExp);
|
|
@@ -4078,24 +4332,24 @@ __export(minimize_exports, {
|
|
|
4078
4332
|
parseMinifyOptions: () => parseMinifyOptions,
|
|
4079
4333
|
pluginMinimize: () => pluginMinimize
|
|
4080
4334
|
});
|
|
4081
|
-
var
|
|
4335
|
+
var import_shared28, import_core6, getSwcMinimizerOptions, parseMinifyOptions, pluginMinimize;
|
|
4082
4336
|
var init_minimize = __esm({
|
|
4083
4337
|
"src/plugins/minimize.ts"() {
|
|
4084
4338
|
"use strict";
|
|
4085
|
-
|
|
4339
|
+
import_shared28 = require("@rsbuild/shared");
|
|
4086
4340
|
import_core6 = require("@rspack/core");
|
|
4087
4341
|
getSwcMinimizerOptions = (config) => {
|
|
4088
4342
|
const options = {};
|
|
4089
4343
|
const { removeConsole } = config.performance;
|
|
4090
4344
|
if (removeConsole === true) {
|
|
4091
4345
|
options.compress = {
|
|
4092
|
-
...(0,
|
|
4346
|
+
...(0, import_shared28.isObject)(options.compress) ? options.compress : {},
|
|
4093
4347
|
drop_console: true
|
|
4094
4348
|
};
|
|
4095
4349
|
} else if (Array.isArray(removeConsole)) {
|
|
4096
4350
|
const pureFuncs = removeConsole.map((method) => `console.${method}`);
|
|
4097
4351
|
options.compress = {
|
|
4098
|
-
...(0,
|
|
4352
|
+
...(0, import_shared28.isObject)(options.compress) ? options.compress : {},
|
|
4099
4353
|
pure_funcs: pureFuncs
|
|
4100
4354
|
};
|
|
4101
4355
|
}
|
|
@@ -4118,13 +4372,13 @@ var init_minimize = __esm({
|
|
|
4118
4372
|
options.format.asciiOnly = config.output.charset === "ascii";
|
|
4119
4373
|
const jsOptions = parseMinifyOptions(config).jsOptions;
|
|
4120
4374
|
if (jsOptions) {
|
|
4121
|
-
return (0,
|
|
4375
|
+
return (0, import_shared28.deepmerge)(options, jsOptions);
|
|
4122
4376
|
}
|
|
4123
4377
|
return options;
|
|
4124
4378
|
};
|
|
4125
|
-
parseMinifyOptions = (config,
|
|
4379
|
+
parseMinifyOptions = (config, isProd7 = true) => {
|
|
4126
4380
|
const minify = config.output.minify;
|
|
4127
|
-
if (minify === false || !
|
|
4381
|
+
if (minify === false || !isProd7) {
|
|
4128
4382
|
return {
|
|
4129
4383
|
minifyJs: false,
|
|
4130
4384
|
minifyCss: false,
|
|
@@ -4156,19 +4410,19 @@ var init_minimize = __esm({
|
|
|
4156
4410
|
if (api.context.bundlerType === "webpack") {
|
|
4157
4411
|
return;
|
|
4158
4412
|
}
|
|
4159
|
-
api.modifyBundlerChain(async (chain, { isProd:
|
|
4413
|
+
api.modifyBundlerChain(async (chain, { isProd: isProd7 }) => {
|
|
4160
4414
|
const config = api.getNormalizedConfig();
|
|
4161
|
-
const isMinimize =
|
|
4415
|
+
const isMinimize = isProd7 && config.output.minify !== false;
|
|
4162
4416
|
if (!isMinimize) {
|
|
4163
4417
|
return;
|
|
4164
4418
|
}
|
|
4165
4419
|
const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = import_core6.rspack;
|
|
4166
4420
|
const { minifyJs, minifyCss } = parseMinifyOptions(config);
|
|
4167
4421
|
if (minifyJs) {
|
|
4168
|
-
chain.optimization.minimizer(
|
|
4422
|
+
chain.optimization.minimizer(import_shared28.CHAIN_ID.MINIMIZER.JS).use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]).end();
|
|
4169
4423
|
}
|
|
4170
4424
|
if (minifyCss) {
|
|
4171
|
-
chain.optimization.minimizer(
|
|
4425
|
+
chain.optimization.minimizer(import_shared28.CHAIN_ID.MINIMIZER.CSS).use(SwcCssMinimizerRspackPlugin, []).end();
|
|
4172
4426
|
}
|
|
4173
4427
|
});
|
|
4174
4428
|
}
|
|
@@ -4185,11 +4439,11 @@ __export(HtmlBasicPlugin_exports, {
|
|
|
4185
4439
|
VOID_TAGS: () => VOID_TAGS,
|
|
4186
4440
|
hasTitle: () => hasTitle
|
|
4187
4441
|
});
|
|
4188
|
-
var
|
|
4442
|
+
var import_shared29, VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
|
|
4189
4443
|
var init_HtmlBasicPlugin = __esm({
|
|
4190
4444
|
"src/rspack/HtmlBasicPlugin.ts"() {
|
|
4191
4445
|
"use strict";
|
|
4192
|
-
|
|
4446
|
+
import_shared29 = require("@rsbuild/shared");
|
|
4193
4447
|
init_helpers();
|
|
4194
4448
|
init_pluginHelper();
|
|
4195
4449
|
VOID_TAGS = [
|
|
@@ -4301,7 +4555,7 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4301
4555
|
publicPath: data.publicPath
|
|
4302
4556
|
};
|
|
4303
4557
|
for (const item of tagConfig.tags) {
|
|
4304
|
-
if ((0,
|
|
4558
|
+
if ((0, import_shared29.isFunction)(item)) {
|
|
4305
4559
|
tags = item(tags, utils) || tags;
|
|
4306
4560
|
} else {
|
|
4307
4561
|
tags.push(item);
|
|
@@ -4310,7 +4564,7 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4310
4564
|
(tag1, tag2) => getTagPriority(tag1, tagConfig) - getTagPriority(tag2, tagConfig)
|
|
4311
4565
|
);
|
|
4312
4566
|
}
|
|
4313
|
-
const [headTags, bodyTags] =
|
|
4567
|
+
const [headTags, bodyTags] = partition(
|
|
4314
4568
|
tags,
|
|
4315
4569
|
(tag) => tag.head ?? HEAD_TAGS.includes(tag.tag)
|
|
4316
4570
|
);
|
|
@@ -4392,13 +4646,13 @@ var HtmlAppIconPlugin_exports = {};
|
|
|
4392
4646
|
__export(HtmlAppIconPlugin_exports, {
|
|
4393
4647
|
HtmlAppIconPlugin: () => HtmlAppIconPlugin
|
|
4394
4648
|
});
|
|
4395
|
-
var import_node_fs4, import_node_path18,
|
|
4649
|
+
var import_node_fs4, import_node_path18, import_shared30, HtmlAppIconPlugin;
|
|
4396
4650
|
var init_HtmlAppIconPlugin = __esm({
|
|
4397
4651
|
"src/rspack/HtmlAppIconPlugin.ts"() {
|
|
4398
4652
|
"use strict";
|
|
4399
4653
|
import_node_fs4 = __toESM(require("fs"));
|
|
4400
4654
|
import_node_path18 = require("path");
|
|
4401
|
-
|
|
4655
|
+
import_shared30 = require("@rsbuild/shared");
|
|
4402
4656
|
init_helpers();
|
|
4403
4657
|
init_pluginHelper();
|
|
4404
4658
|
HtmlAppIconPlugin = class {
|
|
@@ -4419,7 +4673,7 @@ var init_HtmlAppIconPlugin = __esm({
|
|
|
4419
4673
|
const iconRelativePath = import_node_path18.posix.join(this.distDir, (0, import_node_path18.basename)(this.iconPath));
|
|
4420
4674
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
4421
4675
|
getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
|
|
4422
|
-
const publicPath = (0,
|
|
4676
|
+
const publicPath = (0, import_shared30.getPublicPathFromCompiler)(compiler);
|
|
4423
4677
|
data.headTags.unshift({
|
|
4424
4678
|
tagName: "link",
|
|
4425
4679
|
voidTag: true,
|
|
@@ -4499,8 +4753,8 @@ function getTerserMinifyOptions(config) {
|
|
|
4499
4753
|
const finalOptions = applyRemoveConsole(options, config);
|
|
4500
4754
|
return finalOptions;
|
|
4501
4755
|
}
|
|
4502
|
-
async function getHtmlMinifyOptions(
|
|
4503
|
-
if (!
|
|
4756
|
+
async function getHtmlMinifyOptions(isProd7, config) {
|
|
4757
|
+
if (!isProd7 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
|
|
4504
4758
|
return false;
|
|
4505
4759
|
}
|
|
4506
4760
|
const minifyJS = getTerserMinifyOptions(config);
|
|
@@ -4518,17 +4772,17 @@ async function getHtmlMinifyOptions(isProd6, config) {
|
|
|
4518
4772
|
minifyURLs: true
|
|
4519
4773
|
};
|
|
4520
4774
|
const htmlMinifyOptions = parseMinifyOptions(config).htmlOptions;
|
|
4521
|
-
return typeof htmlMinifyOptions === "object" ? (0,
|
|
4775
|
+
return typeof htmlMinifyOptions === "object" ? (0, import_shared31.deepmerge)(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
|
|
4522
4776
|
}
|
|
4523
4777
|
function getTitle(entryName, config) {
|
|
4524
|
-
return (0,
|
|
4778
|
+
return (0, import_shared31.reduceConfigsMergeContext)({
|
|
4525
4779
|
initial: "",
|
|
4526
4780
|
config: config.html.title,
|
|
4527
4781
|
ctx: { entryName }
|
|
4528
4782
|
});
|
|
4529
4783
|
}
|
|
4530
4784
|
function getInject(entryName, config) {
|
|
4531
|
-
return (0,
|
|
4785
|
+
return (0, import_shared31.reduceConfigsMergeContext)({
|
|
4532
4786
|
initial: "head",
|
|
4533
4787
|
config: config.html.inject,
|
|
4534
4788
|
ctx: { entryName }
|
|
@@ -4536,7 +4790,7 @@ function getInject(entryName, config) {
|
|
|
4536
4790
|
}
|
|
4537
4791
|
async function getTemplate(entryName, config, rootPath) {
|
|
4538
4792
|
const DEFAULT_TEMPLATE = import_node_path19.default.resolve(STATIC_PATH, "template.html");
|
|
4539
|
-
const templatePath = (0,
|
|
4793
|
+
const templatePath = (0, import_shared31.reduceConfigsMergeContext)({
|
|
4540
4794
|
initial: DEFAULT_TEMPLATE,
|
|
4541
4795
|
config: config.html.template,
|
|
4542
4796
|
ctx: { entryName }
|
|
@@ -4550,28 +4804,28 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
4550
4804
|
if (!existTemplatePath.includes(absolutePath)) {
|
|
4551
4805
|
if (!await isFileExists(absolutePath)) {
|
|
4552
4806
|
throw new Error(
|
|
4553
|
-
`Failed to resolve HTML template, please check if the file exists: ${
|
|
4807
|
+
`Failed to resolve HTML template, please check if the file exists: ${import_shared31.color.cyan(
|
|
4554
4808
|
absolutePath
|
|
4555
4809
|
)}`
|
|
4556
4810
|
);
|
|
4557
4811
|
}
|
|
4558
4812
|
existTemplatePath.push(absolutePath);
|
|
4559
4813
|
}
|
|
4560
|
-
const templateContent = await
|
|
4814
|
+
const templateContent = await import_shared31.fse.readFile(absolutePath, "utf-8");
|
|
4561
4815
|
return {
|
|
4562
4816
|
templatePath: absolutePath,
|
|
4563
4817
|
templateContent
|
|
4564
4818
|
};
|
|
4565
4819
|
}
|
|
4566
4820
|
function getFavicon(entryName, config) {
|
|
4567
|
-
return (0,
|
|
4821
|
+
return (0, import_shared31.reduceConfigsMergeContext)({
|
|
4568
4822
|
initial: "",
|
|
4569
4823
|
config: config.html.favicon,
|
|
4570
4824
|
ctx: { entryName }
|
|
4571
4825
|
});
|
|
4572
4826
|
}
|
|
4573
4827
|
function getMetaTags(entryName, config, templateContent) {
|
|
4574
|
-
const metaTags = (0,
|
|
4828
|
+
const metaTags = (0, import_shared31.reduceConfigsMergeContext)({
|
|
4575
4829
|
initial: {},
|
|
4576
4830
|
config: config.html.meta,
|
|
4577
4831
|
ctx: { entryName }
|
|
@@ -4599,7 +4853,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
4599
4853
|
options: pluginOptions
|
|
4600
4854
|
}
|
|
4601
4855
|
};
|
|
4602
|
-
return (0,
|
|
4856
|
+
return (0, import_shared31.reduceConfigsWithContext)({
|
|
4603
4857
|
initial: defaultOptions2,
|
|
4604
4858
|
config: templateParameters,
|
|
4605
4859
|
ctx: { entryName }
|
|
@@ -4609,7 +4863,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
4609
4863
|
function getChunks(entryName, entryValue) {
|
|
4610
4864
|
const chunks = [entryName];
|
|
4611
4865
|
for (const item of entryValue) {
|
|
4612
|
-
if (!(0,
|
|
4866
|
+
if (!(0, import_shared31.isPlainObject)(item)) {
|
|
4613
4867
|
continue;
|
|
4614
4868
|
}
|
|
4615
4869
|
const { dependOn } = item;
|
|
@@ -4624,19 +4878,19 @@ function getChunks(entryName, entryValue) {
|
|
|
4624
4878
|
}
|
|
4625
4879
|
return chunks;
|
|
4626
4880
|
}
|
|
4627
|
-
var import_node_path19,
|
|
4881
|
+
var import_node_path19, import_shared31, existTemplatePath, getTagConfig, pluginHtml;
|
|
4628
4882
|
var init_html = __esm({
|
|
4629
4883
|
"src/plugins/html.ts"() {
|
|
4630
4884
|
"use strict";
|
|
4631
4885
|
import_node_path19 = __toESM(require("path"));
|
|
4632
|
-
|
|
4886
|
+
import_shared31 = require("@rsbuild/shared");
|
|
4633
4887
|
init_constants();
|
|
4634
4888
|
init_helpers();
|
|
4635
4889
|
init_minimize();
|
|
4636
4890
|
existTemplatePath = [];
|
|
4637
4891
|
getTagConfig = (api) => {
|
|
4638
4892
|
const config = api.getNormalizedConfig();
|
|
4639
|
-
const tags = (0,
|
|
4893
|
+
const tags = (0, import_shared31.castArray)(config.html.tags).filter(Boolean);
|
|
4640
4894
|
if (!tags.length) {
|
|
4641
4895
|
return void 0;
|
|
4642
4896
|
}
|
|
@@ -4651,12 +4905,12 @@ var init_html = __esm({
|
|
|
4651
4905
|
name: "rsbuild:html",
|
|
4652
4906
|
setup(api) {
|
|
4653
4907
|
api.modifyBundlerChain(
|
|
4654
|
-
async (chain, { HtmlPlugin, isProd:
|
|
4908
|
+
async (chain, { HtmlPlugin, isProd: isProd7, CHAIN_ID: CHAIN_ID3, target }) => {
|
|
4655
4909
|
const config = api.getNormalizedConfig();
|
|
4656
|
-
if ((0,
|
|
4910
|
+
if ((0, import_shared31.isHtmlDisabled)(config, target)) {
|
|
4657
4911
|
return;
|
|
4658
4912
|
}
|
|
4659
|
-
const minify = await getHtmlMinifyOptions(
|
|
4913
|
+
const minify = await getHtmlMinifyOptions(isProd7, config);
|
|
4660
4914
|
const assetPrefix = getPublicPathFromChain(chain, false);
|
|
4661
4915
|
const entries = chain.entryPoints.entries() || {};
|
|
4662
4916
|
const entryNames = Object.keys(entries);
|
|
@@ -4705,13 +4959,13 @@ var init_html = __esm({
|
|
|
4705
4959
|
pluginOptions.title = getTitle(entryName, config);
|
|
4706
4960
|
const favicon = getFavicon(entryName, config);
|
|
4707
4961
|
if (favicon) {
|
|
4708
|
-
if (
|
|
4962
|
+
if (isURL(favicon)) {
|
|
4709
4963
|
htmlInfo.favicon = favicon;
|
|
4710
4964
|
} else {
|
|
4711
4965
|
pluginOptions.favicon = favicon;
|
|
4712
4966
|
}
|
|
4713
4967
|
}
|
|
4714
|
-
const finalOptions2 = (0,
|
|
4968
|
+
const finalOptions2 = (0, import_shared31.reduceConfigsWithContext)({
|
|
4715
4969
|
initial: pluginOptions,
|
|
4716
4970
|
config: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
|
|
4717
4971
|
ctx: { entryName, entryValue }
|
|
@@ -4732,7 +4986,7 @@ var init_html = __esm({
|
|
|
4732
4986
|
}
|
|
4733
4987
|
if (appIcon) {
|
|
4734
4988
|
const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
|
|
4735
|
-
const distDir =
|
|
4989
|
+
const distDir = config.output.distPath.image;
|
|
4736
4990
|
const iconPath = import_node_path19.default.isAbsolute(appIcon) ? appIcon : import_node_path19.default.join(api.context.rootPath, appIcon);
|
|
4737
4991
|
chain.plugin(CHAIN_ID3.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
|
|
4738
4992
|
}
|
|
@@ -4767,18 +5021,17 @@ var wasm_exports = {};
|
|
|
4767
5021
|
__export(wasm_exports, {
|
|
4768
5022
|
pluginWasm: () => pluginWasm
|
|
4769
5023
|
});
|
|
4770
|
-
var import_node_path20,
|
|
5024
|
+
var import_node_path20, pluginWasm;
|
|
4771
5025
|
var init_wasm = __esm({
|
|
4772
5026
|
"src/plugins/wasm.ts"() {
|
|
4773
5027
|
"use strict";
|
|
4774
5028
|
import_node_path20 = require("path");
|
|
4775
|
-
import_shared38 = require("@rsbuild/shared");
|
|
4776
5029
|
pluginWasm = () => ({
|
|
4777
5030
|
name: "rsbuild:wasm",
|
|
4778
5031
|
setup(api) {
|
|
4779
5032
|
api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
|
|
4780
5033
|
const config = api.getNormalizedConfig();
|
|
4781
|
-
const distPath =
|
|
5034
|
+
const distPath = config.output.distPath.wasm;
|
|
4782
5035
|
chain.experiments({
|
|
4783
5036
|
...chain.get("experiments"),
|
|
4784
5037
|
asyncWebAssembly: true
|
|
@@ -4831,12 +5084,12 @@ var nodeAddons_exports = {};
|
|
|
4831
5084
|
__export(nodeAddons_exports, {
|
|
4832
5085
|
pluginNodeAddons: () => pluginNodeAddons
|
|
4833
5086
|
});
|
|
4834
|
-
var import_node_path21,
|
|
5087
|
+
var import_node_path21, getFilename2, pluginNodeAddons;
|
|
4835
5088
|
var init_nodeAddons = __esm({
|
|
4836
5089
|
"src/plugins/nodeAddons.ts"() {
|
|
4837
5090
|
"use strict";
|
|
4838
5091
|
import_node_path21 = __toESM(require("path"));
|
|
4839
|
-
|
|
5092
|
+
getFilename2 = (resourcePath) => {
|
|
4840
5093
|
let basename2 = "";
|
|
4841
5094
|
if (resourcePath) {
|
|
4842
5095
|
const parsed = import_node_path21.default.parse(resourcePath);
|
|
@@ -4855,7 +5108,7 @@ var init_nodeAddons = __esm({
|
|
|
4855
5108
|
api.transform(
|
|
4856
5109
|
{ test: /\.node$/, targets: ["node"], raw: true },
|
|
4857
5110
|
({ code, emitFile, resourcePath }) => {
|
|
4858
|
-
const name =
|
|
5111
|
+
const name = getFilename2(resourcePath);
|
|
4859
5112
|
if (name === null) {
|
|
4860
5113
|
throw new Error(`Failed to load Node.js addon: "${resourcePath}"`);
|
|
4861
5114
|
}
|
|
@@ -4880,11 +5133,11 @@ var define_exports = {};
|
|
|
4880
5133
|
__export(define_exports, {
|
|
4881
5134
|
pluginDefine: () => pluginDefine
|
|
4882
5135
|
});
|
|
4883
|
-
var
|
|
5136
|
+
var import_shared32, pluginDefine;
|
|
4884
5137
|
var init_define = __esm({
|
|
4885
5138
|
"src/plugins/define.ts"() {
|
|
4886
5139
|
"use strict";
|
|
4887
|
-
|
|
5140
|
+
import_shared32 = require("@rsbuild/shared");
|
|
4888
5141
|
init_helpers();
|
|
4889
5142
|
pluginDefine = () => ({
|
|
4890
5143
|
name: "rsbuild:define",
|
|
@@ -4892,7 +5145,7 @@ var init_define = __esm({
|
|
|
4892
5145
|
api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID3, bundler }) => {
|
|
4893
5146
|
const config = api.getNormalizedConfig();
|
|
4894
5147
|
const builtinVars = {
|
|
4895
|
-
"process.env.NODE_ENV": JSON.stringify((0,
|
|
5148
|
+
"process.env.NODE_ENV": JSON.stringify((0, import_shared32.getNodeEnv)()),
|
|
4896
5149
|
"process.env.ASSET_PREFIX": JSON.stringify(
|
|
4897
5150
|
getPublicPathFromChain(chain, false)
|
|
4898
5151
|
)
|
|
@@ -4911,12 +5164,13 @@ var progress_exports = {};
|
|
|
4911
5164
|
__export(progress_exports, {
|
|
4912
5165
|
pluginProgress: () => pluginProgress
|
|
4913
5166
|
});
|
|
4914
|
-
var
|
|
5167
|
+
var import_shared33, import_core7, pluginProgress;
|
|
4915
5168
|
var init_progress = __esm({
|
|
4916
5169
|
"src/plugins/progress.ts"() {
|
|
4917
5170
|
"use strict";
|
|
4918
|
-
|
|
5171
|
+
import_shared33 = require("@rsbuild/shared");
|
|
4919
5172
|
import_core7 = require("@rspack/core");
|
|
5173
|
+
init_constants();
|
|
4920
5174
|
pluginProgress = () => ({
|
|
4921
5175
|
name: "rsbuild:progress",
|
|
4922
5176
|
setup(api) {
|
|
@@ -4926,11 +5180,11 @@ var init_progress = __esm({
|
|
|
4926
5180
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
|
|
4927
5181
|
const config = api.getNormalizedConfig();
|
|
4928
5182
|
const options = config.dev.progressBar ?? // enable progress bar in production by default
|
|
4929
|
-
(0,
|
|
5183
|
+
(0, import_shared33.isProd)();
|
|
4930
5184
|
if (!options) {
|
|
4931
5185
|
return;
|
|
4932
5186
|
}
|
|
4933
|
-
const prefix = options !== true && options.id !== void 0 ? options.id :
|
|
5187
|
+
const prefix = options !== true && options.id !== void 0 ? options.id : TARGET_ID_MAP[target];
|
|
4934
5188
|
chain.plugin(CHAIN_ID3.PLUGIN.PROGRESS).use(import_core7.rspack.ProgressPlugin, [
|
|
4935
5189
|
{
|
|
4936
5190
|
prefix,
|
|
@@ -4964,13 +5218,13 @@ async function getDefaultSwcConfig(config, rootPath, target) {
|
|
|
4964
5218
|
},
|
|
4965
5219
|
isModule: "unknown",
|
|
4966
5220
|
env: {
|
|
4967
|
-
targets: await (0,
|
|
5221
|
+
targets: await (0, import_shared34.getBrowserslistWithDefault)(rootPath, config, target)
|
|
4968
5222
|
}
|
|
4969
5223
|
};
|
|
4970
5224
|
}
|
|
4971
5225
|
async function applyCoreJs(swcConfig, polyfillMode) {
|
|
4972
5226
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
4973
|
-
const version2 = (0,
|
|
5227
|
+
const version2 = (0, import_shared34.getCoreJsVersion)(coreJsPath);
|
|
4974
5228
|
const coreJsDir = import_node_path22.default.dirname(coreJsPath);
|
|
4975
5229
|
swcConfig.env.coreJs = version2;
|
|
4976
5230
|
if (polyfillMode === "usage") {
|
|
@@ -5003,13 +5257,14 @@ function applySwcDecoratorConfig(swcConfig, config) {
|
|
|
5003
5257
|
throw new Error("Unknown decorators version: ${version}");
|
|
5004
5258
|
}
|
|
5005
5259
|
}
|
|
5006
|
-
var import_node_path22,
|
|
5260
|
+
var import_node_path22, import_shared34, builtinSwcLoaderName, pluginSwc;
|
|
5007
5261
|
var init_swc = __esm({
|
|
5008
5262
|
"src/plugins/swc.ts"() {
|
|
5009
5263
|
"use strict";
|
|
5010
5264
|
import_node_path22 = __toESM(require("path"));
|
|
5011
|
-
|
|
5265
|
+
import_shared34 = require("@rsbuild/shared");
|
|
5012
5266
|
init_constants();
|
|
5267
|
+
init_helpers();
|
|
5013
5268
|
builtinSwcLoaderName = "builtin:swc-loader";
|
|
5014
5269
|
pluginSwc = () => ({
|
|
5015
5270
|
name: PLUGIN_SWC_NAME,
|
|
@@ -5021,11 +5276,11 @@ var init_swc = __esm({
|
|
|
5021
5276
|
order: "pre",
|
|
5022
5277
|
handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
|
|
5023
5278
|
const config = api.getNormalizedConfig();
|
|
5024
|
-
const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(
|
|
5279
|
+
const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared34.SCRIPT_REGEX).type("javascript/auto");
|
|
5025
5280
|
const dataUriRule = chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
|
|
5026
5281
|
or: ["text/javascript", "application/javascript"]
|
|
5027
5282
|
});
|
|
5028
|
-
(0,
|
|
5283
|
+
(0, import_shared34.applyScriptCondition)({
|
|
5029
5284
|
rule,
|
|
5030
5285
|
chain,
|
|
5031
5286
|
config,
|
|
@@ -5046,7 +5301,7 @@ var init_swc = __esm({
|
|
|
5046
5301
|
import_node_path22.default.dirname(require.resolve("@swc/helpers/package.json"))
|
|
5047
5302
|
);
|
|
5048
5303
|
}
|
|
5049
|
-
if (
|
|
5304
|
+
if (isWebTarget(target)) {
|
|
5050
5305
|
const polyfillMode = config.output.polyfill;
|
|
5051
5306
|
if (polyfillMode === "off") {
|
|
5052
5307
|
swcConfig.env.mode = void 0;
|
|
@@ -5058,13 +5313,13 @@ var init_swc = __esm({
|
|
|
5058
5313
|
}
|
|
5059
5314
|
}
|
|
5060
5315
|
}
|
|
5061
|
-
const mergedSwcConfig = (0,
|
|
5316
|
+
const mergedSwcConfig = (0, import_shared34.reduceConfigs)({
|
|
5062
5317
|
initial: swcConfig,
|
|
5063
5318
|
config: config.tools.swc,
|
|
5064
|
-
mergeFn:
|
|
5319
|
+
mergeFn: import_shared34.deepmerge
|
|
5065
5320
|
});
|
|
5066
5321
|
rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
|
|
5067
|
-
dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0,
|
|
5322
|
+
dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared34.cloneDeep)(mergedSwcConfig));
|
|
5068
5323
|
}
|
|
5069
5324
|
});
|
|
5070
5325
|
}
|
|
@@ -5131,11 +5386,11 @@ function splitByExperience(ctx) {
|
|
|
5131
5386
|
const { override, polyfill, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
5132
5387
|
const experienceCacheGroup = {};
|
|
5133
5388
|
const packageRegExps = {
|
|
5134
|
-
lodash: (0,
|
|
5135
|
-
axios: (0,
|
|
5389
|
+
lodash: (0, import_shared35.createDependenciesRegExp)("lodash", "lodash-es"),
|
|
5390
|
+
axios: (0, import_shared35.createDependenciesRegExp)("axios", /axios-.+/)
|
|
5136
5391
|
};
|
|
5137
5392
|
if (polyfill === "entry" || polyfill === "usage") {
|
|
5138
|
-
packageRegExps.polyfill = (0,
|
|
5393
|
+
packageRegExps.polyfill = (0, import_shared35.createDependenciesRegExp)(
|
|
5139
5394
|
"tslib",
|
|
5140
5395
|
"core-js",
|
|
5141
5396
|
"@babel/runtime",
|
|
@@ -5184,7 +5439,7 @@ function splitByModule(ctx) {
|
|
|
5184
5439
|
// Core group
|
|
5185
5440
|
vendors: {
|
|
5186
5441
|
priority: -9,
|
|
5187
|
-
test:
|
|
5442
|
+
test: import_shared35.NODE_MODULES_REGEX,
|
|
5188
5443
|
name(module2) {
|
|
5189
5444
|
return module2 ? getPackageNameFromModulePath(module2.context) : void 0;
|
|
5190
5445
|
}
|
|
@@ -5227,7 +5482,7 @@ function singleVendor(ctx) {
|
|
|
5227
5482
|
const { override, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
5228
5483
|
const singleVendorCacheGroup = {
|
|
5229
5484
|
singleVendor: {
|
|
5230
|
-
test:
|
|
5485
|
+
test: import_shared35.NODE_MODULES_REGEX,
|
|
5231
5486
|
priority: 0,
|
|
5232
5487
|
chunks: "all",
|
|
5233
5488
|
name: "vendor",
|
|
@@ -5246,12 +5501,12 @@ function singleVendor(ctx) {
|
|
|
5246
5501
|
}
|
|
5247
5502
|
};
|
|
5248
5503
|
}
|
|
5249
|
-
var import_node_assert,
|
|
5504
|
+
var import_node_assert, import_shared35, MODULE_PATH_REGEX, SPLIT_STRATEGY_DISPATCHER, pluginSplitChunks;
|
|
5250
5505
|
var init_splitChunks = __esm({
|
|
5251
5506
|
"src/plugins/splitChunks.ts"() {
|
|
5252
5507
|
"use strict";
|
|
5253
5508
|
import_node_assert = __toESM(require("assert"));
|
|
5254
|
-
|
|
5509
|
+
import_shared35 = require("@rsbuild/shared");
|
|
5255
5510
|
MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/;
|
|
5256
5511
|
SPLIT_STRATEGY_DISPATCHER = {
|
|
5257
5512
|
"split-by-experience": splitByExperience,
|
|
@@ -5334,10 +5589,10 @@ async function openBrowser(url2) {
|
|
|
5334
5589
|
);
|
|
5335
5590
|
return true;
|
|
5336
5591
|
}
|
|
5337
|
-
|
|
5592
|
+
import_rslog.logger.debug("Failed to find the target browser.");
|
|
5338
5593
|
} catch (err) {
|
|
5339
|
-
|
|
5340
|
-
|
|
5594
|
+
import_rslog.logger.debug("Failed to open start URL with apple script.");
|
|
5595
|
+
import_rslog.logger.debug(err);
|
|
5341
5596
|
}
|
|
5342
5597
|
}
|
|
5343
5598
|
try {
|
|
@@ -5345,8 +5600,8 @@ async function openBrowser(url2) {
|
|
|
5345
5600
|
await open(url2);
|
|
5346
5601
|
return true;
|
|
5347
5602
|
} catch (err) {
|
|
5348
|
-
|
|
5349
|
-
|
|
5603
|
+
import_rslog.logger.error("Failed to open start URL.");
|
|
5604
|
+
import_rslog.logger.error(err);
|
|
5350
5605
|
return false;
|
|
5351
5606
|
}
|
|
5352
5607
|
}
|
|
@@ -5409,15 +5664,16 @@ function pluginOpen() {
|
|
|
5409
5664
|
}
|
|
5410
5665
|
};
|
|
5411
5666
|
}
|
|
5412
|
-
var import_node_child_process, import_node_util,
|
|
5667
|
+
var import_node_child_process, import_node_util, import_shared36, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
|
|
5413
5668
|
var init_open = __esm({
|
|
5414
5669
|
"src/plugins/open.ts"() {
|
|
5415
5670
|
"use strict";
|
|
5416
5671
|
import_node_child_process = require("child_process");
|
|
5417
5672
|
import_node_util = require("util");
|
|
5418
|
-
|
|
5673
|
+
import_shared36 = require("@rsbuild/shared");
|
|
5419
5674
|
init_constants();
|
|
5420
5675
|
init_helpers();
|
|
5676
|
+
init_logger();
|
|
5421
5677
|
execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
5422
5678
|
supportedChromiumBrowsers = [
|
|
5423
5679
|
"Google Chrome Canary",
|
|
@@ -5455,7 +5711,7 @@ var init_open = __esm({
|
|
|
5455
5711
|
return { targets: open, before: beforeStartUrl };
|
|
5456
5712
|
}
|
|
5457
5713
|
return {
|
|
5458
|
-
targets: open.target ? (0,
|
|
5714
|
+
targets: open.target ? (0, import_shared36.castArray)(open.target) : [],
|
|
5459
5715
|
before: open.before
|
|
5460
5716
|
};
|
|
5461
5717
|
};
|
|
@@ -5467,12 +5723,13 @@ var InlineChunkHtmlPlugin_exports = {};
|
|
|
5467
5723
|
__export(InlineChunkHtmlPlugin_exports, {
|
|
5468
5724
|
InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
|
|
5469
5725
|
});
|
|
5470
|
-
var import_node_path23,
|
|
5726
|
+
var import_node_path23, import_shared37, InlineChunkHtmlPlugin;
|
|
5471
5727
|
var init_InlineChunkHtmlPlugin = __esm({
|
|
5472
5728
|
"src/rspack/InlineChunkHtmlPlugin.ts"() {
|
|
5473
5729
|
"use strict";
|
|
5474
5730
|
import_node_path23 = require("path");
|
|
5475
|
-
|
|
5731
|
+
import_shared37 = require("@rsbuild/shared");
|
|
5732
|
+
init_helpers();
|
|
5476
5733
|
init_pluginHelper();
|
|
5477
5734
|
InlineChunkHtmlPlugin = class {
|
|
5478
5735
|
constructor({
|
|
@@ -5505,7 +5762,7 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5505
5762
|
const { devtool } = compilation.options;
|
|
5506
5763
|
if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
|
|
5507
5764
|
!devtool.includes("inline") && source.includes("# sourceMappingURL")) {
|
|
5508
|
-
const prefix =
|
|
5765
|
+
const prefix = addTrailingSlash(
|
|
5509
5766
|
(0, import_node_path23.join)(publicPath, this.distPath[type] || "")
|
|
5510
5767
|
);
|
|
5511
5768
|
return source.replace(
|
|
@@ -5517,7 +5774,7 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5517
5774
|
}
|
|
5518
5775
|
matchTests(name, source, tests) {
|
|
5519
5776
|
return tests.some((test) => {
|
|
5520
|
-
if ((0,
|
|
5777
|
+
if ((0, import_shared37.isFunction)(test)) {
|
|
5521
5778
|
const size = source.length;
|
|
5522
5779
|
return test({ name, size });
|
|
5523
5780
|
}
|
|
@@ -5603,7 +5860,7 @@ var init_InlineChunkHtmlPlugin = __esm({
|
|
|
5603
5860
|
}
|
|
5604
5861
|
apply(compiler) {
|
|
5605
5862
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
5606
|
-
const publicPath = (0,
|
|
5863
|
+
const publicPath = (0, import_shared37.getPublicPathFromCompiler)(compiler);
|
|
5607
5864
|
const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
|
|
5608
5865
|
const hooks = getHTMLPlugin().getHooks(compilation);
|
|
5609
5866
|
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
@@ -5643,18 +5900,19 @@ var inlineChunk_exports = {};
|
|
|
5643
5900
|
__export(inlineChunk_exports, {
|
|
5644
5901
|
pluginInlineChunk: () => pluginInlineChunk
|
|
5645
5902
|
});
|
|
5646
|
-
var
|
|
5903
|
+
var import_shared38, pluginInlineChunk;
|
|
5647
5904
|
var init_inlineChunk = __esm({
|
|
5648
5905
|
"src/plugins/inlineChunk.ts"() {
|
|
5649
5906
|
"use strict";
|
|
5650
|
-
|
|
5907
|
+
import_shared38 = require("@rsbuild/shared");
|
|
5651
5908
|
init_constants();
|
|
5909
|
+
init_helpers();
|
|
5652
5910
|
pluginInlineChunk = () => ({
|
|
5653
5911
|
name: "rsbuild:inline-chunk",
|
|
5654
5912
|
setup(api) {
|
|
5655
5913
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3, isDev: isDev3 }) => {
|
|
5656
5914
|
const config = api.getNormalizedConfig();
|
|
5657
|
-
if ((0,
|
|
5915
|
+
if ((0, import_shared38.isHtmlDisabled)(config, target) || isDev3) {
|
|
5658
5916
|
return;
|
|
5659
5917
|
}
|
|
5660
5918
|
const { InlineChunkHtmlPlugin: InlineChunkHtmlPlugin2 } = await Promise.resolve().then(() => (init_InlineChunkHtmlPlugin(), InlineChunkHtmlPlugin_exports));
|
|
@@ -5662,7 +5920,7 @@ var init_inlineChunk = __esm({
|
|
|
5662
5920
|
const scriptTests = [];
|
|
5663
5921
|
const styleTests = [];
|
|
5664
5922
|
if (inlineScripts) {
|
|
5665
|
-
scriptTests.push(inlineScripts === true ?
|
|
5923
|
+
scriptTests.push(inlineScripts === true ? import_shared38.JS_REGEX : inlineScripts);
|
|
5666
5924
|
}
|
|
5667
5925
|
if (inlineStyles) {
|
|
5668
5926
|
styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
|
|
@@ -5674,7 +5932,7 @@ var init_inlineChunk = __esm({
|
|
|
5674
5932
|
{
|
|
5675
5933
|
styleTests,
|
|
5676
5934
|
scriptTests,
|
|
5677
|
-
distPath:
|
|
5935
|
+
distPath: pick(config.output.distPath, ["js", "css"])
|
|
5678
5936
|
}
|
|
5679
5937
|
]);
|
|
5680
5938
|
});
|
|
@@ -5693,7 +5951,7 @@ function pluginBundleAnalyzer() {
|
|
|
5693
5951
|
name: "rsbuild:bundle-analyzer",
|
|
5694
5952
|
setup(api) {
|
|
5695
5953
|
api.modifyRsbuildConfig((config) => {
|
|
5696
|
-
if ((0,
|
|
5954
|
+
if ((0, import_shared39.isProd)() || !isUseAnalyzer(config)) {
|
|
5697
5955
|
return;
|
|
5698
5956
|
}
|
|
5699
5957
|
config.dev ||= {};
|
|
@@ -5718,11 +5976,11 @@ function pluginBundleAnalyzer() {
|
|
|
5718
5976
|
}
|
|
5719
5977
|
};
|
|
5720
5978
|
}
|
|
5721
|
-
var
|
|
5979
|
+
var import_shared39, isUseAnalyzer;
|
|
5722
5980
|
var init_bundleAnalyzer = __esm({
|
|
5723
5981
|
"src/plugins/bundleAnalyzer.ts"() {
|
|
5724
5982
|
"use strict";
|
|
5725
|
-
|
|
5983
|
+
import_shared39 = require("@rsbuild/shared");
|
|
5726
5984
|
isUseAnalyzer = (config) => process.env.BUNDLE_ANALYZE || config.performance?.bundleAnalyze;
|
|
5727
5985
|
}
|
|
5728
5986
|
});
|
|
@@ -5732,11 +5990,12 @@ var rsdoctor_exports = {};
|
|
|
5732
5990
|
__export(rsdoctor_exports, {
|
|
5733
5991
|
pluginRsdoctor: () => pluginRsdoctor
|
|
5734
5992
|
});
|
|
5735
|
-
var
|
|
5993
|
+
var import_shared40, pluginRsdoctor;
|
|
5736
5994
|
var init_rsdoctor = __esm({
|
|
5737
5995
|
"src/plugins/rsdoctor.ts"() {
|
|
5738
5996
|
"use strict";
|
|
5739
|
-
|
|
5997
|
+
import_shared40 = require("@rsbuild/shared");
|
|
5998
|
+
init_logger();
|
|
5740
5999
|
pluginRsdoctor = () => ({
|
|
5741
6000
|
name: "rsbuild:rsdoctor",
|
|
5742
6001
|
setup(api) {
|
|
@@ -5753,8 +6012,8 @@ var init_rsdoctor = __esm({
|
|
|
5753
6012
|
});
|
|
5754
6013
|
module2 = await import(path13);
|
|
5755
6014
|
} catch (err) {
|
|
5756
|
-
|
|
5757
|
-
`\`process.env.RSDOCTOR\` enabled, please install ${
|
|
6015
|
+
import_rslog.logger.warn(
|
|
6016
|
+
`\`process.env.RSDOCTOR\` enabled, please install ${import_shared40.color.bold(import_shared40.color.yellow(packageName))} package.`
|
|
5758
6017
|
);
|
|
5759
6018
|
return;
|
|
5760
6019
|
}
|
|
@@ -5775,7 +6034,7 @@ var init_rsdoctor = __esm({
|
|
|
5775
6034
|
isAutoRegister = true;
|
|
5776
6035
|
}
|
|
5777
6036
|
if (isAutoRegister) {
|
|
5778
|
-
|
|
6037
|
+
import_rslog.logger.info(`${import_shared40.color.bold(import_shared40.color.yellow(packageName))} enabled.`);
|
|
5779
6038
|
}
|
|
5780
6039
|
});
|
|
5781
6040
|
}
|
|
@@ -5971,7 +6230,7 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
|
|
|
5971
6230
|
);
|
|
5972
6231
|
const sortedFilteredFiles = filteredFiles.sort();
|
|
5973
6232
|
const links = [];
|
|
5974
|
-
const publicPath = (0,
|
|
6233
|
+
const publicPath = (0, import_shared41.getPublicPathFromCompiler)(compilation.compiler);
|
|
5975
6234
|
const { crossOriginLoading } = compilation.compiler.options.output;
|
|
5976
6235
|
for (const file of sortedFilteredFiles) {
|
|
5977
6236
|
const href = ensureAssetPrefix(file, publicPath);
|
|
@@ -6002,11 +6261,11 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
|
|
|
6002
6261
|
}
|
|
6003
6262
|
return links;
|
|
6004
6263
|
}
|
|
6005
|
-
var
|
|
6264
|
+
var import_shared41, defaultOptions, HtmlPreloadOrPrefetchPlugin;
|
|
6006
6265
|
var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
6007
6266
|
"src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
|
|
6008
6267
|
"use strict";
|
|
6009
|
-
|
|
6268
|
+
import_shared41 = require("@rsbuild/shared");
|
|
6010
6269
|
init_helpers();
|
|
6011
6270
|
init_pluginHelper();
|
|
6012
6271
|
init_helpers2();
|
|
@@ -6029,7 +6288,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
|
6029
6288
|
apply(compiler) {
|
|
6030
6289
|
compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
|
|
6031
6290
|
getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
|
|
6032
|
-
`HTML${
|
|
6291
|
+
`HTML${upperFirst(this.type)}Plugin`,
|
|
6033
6292
|
(htmlPluginData) => {
|
|
6034
6293
|
this.resourceHints = generateLinks(
|
|
6035
6294
|
this.options,
|
|
@@ -6042,7 +6301,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
|
|
|
6042
6301
|
}
|
|
6043
6302
|
);
|
|
6044
6303
|
getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
|
|
6045
|
-
`HTML${
|
|
6304
|
+
`HTML${upperFirst(this.type)}Plugin`,
|
|
6046
6305
|
(htmlPluginData) => {
|
|
6047
6306
|
if (this.resourceHints) {
|
|
6048
6307
|
htmlPluginData.assetTags.styles = [
|
|
@@ -6067,11 +6326,11 @@ var resourceHints_exports = {};
|
|
|
6067
6326
|
__export(resourceHints_exports, {
|
|
6068
6327
|
pluginResourceHints: () => pluginResourceHints
|
|
6069
6328
|
});
|
|
6070
|
-
var
|
|
6329
|
+
var import_shared42, generateLinks2, pluginResourceHints;
|
|
6071
6330
|
var init_resourceHints = __esm({
|
|
6072
6331
|
"src/plugins/resourceHints.ts"() {
|
|
6073
6332
|
"use strict";
|
|
6074
|
-
|
|
6333
|
+
import_shared42 = require("@rsbuild/shared");
|
|
6075
6334
|
generateLinks2 = (options, rel) => options.map((option) => ({
|
|
6076
6335
|
tag: "link",
|
|
6077
6336
|
attrs: {
|
|
@@ -6106,7 +6365,7 @@ var init_resourceHints = __esm({
|
|
|
6106
6365
|
const {
|
|
6107
6366
|
performance: { preload, prefetch }
|
|
6108
6367
|
} = config;
|
|
6109
|
-
if ((0,
|
|
6368
|
+
if ((0, import_shared42.isHtmlDisabled)(config, target)) {
|
|
6110
6369
|
return;
|
|
6111
6370
|
}
|
|
6112
6371
|
const HTMLCount = chain.entryPoints.values().length;
|
|
@@ -6169,12 +6428,12 @@ var server_exports = {};
|
|
|
6169
6428
|
__export(server_exports, {
|
|
6170
6429
|
pluginServer: () => pluginServer
|
|
6171
6430
|
});
|
|
6172
|
-
var import_node_path25,
|
|
6431
|
+
var import_node_path25, import_shared43, pluginServer;
|
|
6173
6432
|
var init_server = __esm({
|
|
6174
6433
|
"src/plugins/server.ts"() {
|
|
6175
6434
|
"use strict";
|
|
6176
6435
|
import_node_path25 = require("path");
|
|
6177
|
-
|
|
6436
|
+
import_shared43 = require("@rsbuild/shared");
|
|
6178
6437
|
init_config();
|
|
6179
6438
|
pluginServer = () => ({
|
|
6180
6439
|
name: "rsbuild:server",
|
|
@@ -6188,11 +6447,11 @@ var init_server = __esm({
|
|
|
6188
6447
|
continue;
|
|
6189
6448
|
}
|
|
6190
6449
|
const normalizedPath = (0, import_node_path25.isAbsolute)(name) ? name : (0, import_node_path25.join)(api.context.rootPath, name);
|
|
6191
|
-
if (!
|
|
6450
|
+
if (!import_shared43.fse.existsSync(normalizedPath)) {
|
|
6192
6451
|
continue;
|
|
6193
6452
|
}
|
|
6194
6453
|
try {
|
|
6195
|
-
await
|
|
6454
|
+
await import_shared43.fse.copy(normalizedPath, api.context.distPath, {
|
|
6196
6455
|
// dereference symlinks
|
|
6197
6456
|
dereference: true
|
|
6198
6457
|
});
|
|
@@ -6359,18 +6618,18 @@ function pluginModuleFederation() {
|
|
|
6359
6618
|
chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
|
|
6360
6619
|
}
|
|
6361
6620
|
const publicPath = chain.output.get("publicPath");
|
|
6362
|
-
if (publicPath ===
|
|
6621
|
+
if (publicPath === import_shared44.DEFAULT_ASSET_PREFIX) {
|
|
6363
6622
|
chain.output.set("publicPath", "auto");
|
|
6364
6623
|
}
|
|
6365
6624
|
});
|
|
6366
6625
|
}
|
|
6367
6626
|
};
|
|
6368
6627
|
}
|
|
6369
|
-
var
|
|
6628
|
+
var import_shared44, import_core8, PatchSplitChunksPlugin;
|
|
6370
6629
|
var init_moduleFederation = __esm({
|
|
6371
6630
|
"src/plugins/moduleFederation.ts"() {
|
|
6372
6631
|
"use strict";
|
|
6373
|
-
|
|
6632
|
+
import_shared44 = require("@rsbuild/shared");
|
|
6374
6633
|
import_core8 = require("@rspack/core");
|
|
6375
6634
|
PatchSplitChunksPlugin = class {
|
|
6376
6635
|
constructor(name) {
|
|
@@ -6438,25 +6697,25 @@ __export(rspackProfile_exports, {
|
|
|
6438
6697
|
pluginRspackProfile: () => pluginRspackProfile,
|
|
6439
6698
|
stopProfiler: () => stopProfiler
|
|
6440
6699
|
});
|
|
6441
|
-
var import_node_inspector, import_node_path26,
|
|
6700
|
+
var import_node_inspector, import_node_path26, import_shared45, import_core9, stopProfiler, pluginRspackProfile;
|
|
6442
6701
|
var init_rspackProfile = __esm({
|
|
6443
6702
|
"src/plugins/rspackProfile.ts"() {
|
|
6444
6703
|
"use strict";
|
|
6445
6704
|
import_node_inspector = __toESM(require("inspector"));
|
|
6446
6705
|
import_node_path26 = __toESM(require("path"));
|
|
6447
|
-
|
|
6448
|
-
import_shared53 = require("@rsbuild/shared");
|
|
6706
|
+
import_shared45 = require("@rsbuild/shared");
|
|
6449
6707
|
import_core9 = require("@rspack/core");
|
|
6708
|
+
init_logger();
|
|
6450
6709
|
stopProfiler = (output, profileSession) => {
|
|
6451
6710
|
if (!profileSession) {
|
|
6452
6711
|
return;
|
|
6453
6712
|
}
|
|
6454
6713
|
profileSession.post("Profiler.stop", (error, param) => {
|
|
6455
6714
|
if (error) {
|
|
6456
|
-
|
|
6715
|
+
import_rslog.logger.error("Failed to generate JS CPU profile:", error);
|
|
6457
6716
|
return;
|
|
6458
6717
|
}
|
|
6459
|
-
|
|
6718
|
+
import_shared45.fse.writeFileSync(output, JSON.stringify(param.profile));
|
|
6460
6719
|
});
|
|
6461
6720
|
};
|
|
6462
6721
|
pluginRspackProfile = () => ({
|
|
@@ -6482,7 +6741,7 @@ var init_rspackProfile = __esm({
|
|
|
6482
6741
|
const cpuProfilePath = import_node_path26.default.join(profileDir, "jscpuprofile.json");
|
|
6483
6742
|
const loggingFilePath = import_node_path26.default.join(profileDir, "logging.json");
|
|
6484
6743
|
const onStart = () => {
|
|
6485
|
-
|
|
6744
|
+
import_shared45.fse.ensureDirSync(profileDir);
|
|
6486
6745
|
if (enableProfileTrace) {
|
|
6487
6746
|
import_core9.rspack.experimental_registerGlobalTrace(
|
|
6488
6747
|
"trace",
|
|
@@ -6506,7 +6765,7 @@ var init_rspackProfile = __esm({
|
|
|
6506
6765
|
logging: "verbose",
|
|
6507
6766
|
loggingTrace: true
|
|
6508
6767
|
});
|
|
6509
|
-
|
|
6768
|
+
import_shared45.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
|
|
6510
6769
|
}
|
|
6511
6770
|
});
|
|
6512
6771
|
api.onExit(() => {
|
|
@@ -6514,7 +6773,7 @@ var init_rspackProfile = __esm({
|
|
|
6514
6773
|
import_core9.rspack.experimental_cleanupGlobalTrace();
|
|
6515
6774
|
}
|
|
6516
6775
|
stopProfiler(cpuProfilePath, profileSession);
|
|
6517
|
-
|
|
6776
|
+
import_rslog.logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
6518
6777
|
});
|
|
6519
6778
|
}
|
|
6520
6779
|
});
|
|
@@ -6526,16 +6785,16 @@ var lazyCompilation_exports = {};
|
|
|
6526
6785
|
__export(lazyCompilation_exports, {
|
|
6527
6786
|
pluginLazyCompilation: () => pluginLazyCompilation
|
|
6528
6787
|
});
|
|
6529
|
-
var
|
|
6788
|
+
var pluginLazyCompilation;
|
|
6530
6789
|
var init_lazyCompilation = __esm({
|
|
6531
6790
|
"src/plugins/lazyCompilation.ts"() {
|
|
6532
6791
|
"use strict";
|
|
6533
|
-
|
|
6792
|
+
init_helpers();
|
|
6534
6793
|
pluginLazyCompilation = () => ({
|
|
6535
6794
|
name: "rsbuild:lazy-compilation",
|
|
6536
6795
|
setup(api) {
|
|
6537
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
6538
|
-
if (
|
|
6796
|
+
api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
|
|
6797
|
+
if (isProd7 || target !== "web") {
|
|
6539
6798
|
return;
|
|
6540
6799
|
}
|
|
6541
6800
|
const config = api.getNormalizedConfig();
|
|
@@ -6576,7 +6835,7 @@ var init_lazyCompilation = __esm({
|
|
|
6576
6835
|
if (!name || isExcludedModule(name)) {
|
|
6577
6836
|
return false;
|
|
6578
6837
|
}
|
|
6579
|
-
if (
|
|
6838
|
+
if (isRegExp(test)) {
|
|
6580
6839
|
return name ? test.test(name) : false;
|
|
6581
6840
|
}
|
|
6582
6841
|
return test(module2);
|
|
@@ -6598,18 +6857,20 @@ var sri_exports = {};
|
|
|
6598
6857
|
__export(sri_exports, {
|
|
6599
6858
|
pluginSri: () => pluginSri
|
|
6600
6859
|
});
|
|
6601
|
-
var import_node_crypto2,
|
|
6860
|
+
var import_node_crypto2, import_shared46, getAssetName, pluginSri;
|
|
6602
6861
|
var init_sri = __esm({
|
|
6603
6862
|
"src/plugins/sri.ts"() {
|
|
6604
6863
|
"use strict";
|
|
6605
6864
|
import_node_crypto2 = __toESM(require("crypto"));
|
|
6606
|
-
|
|
6865
|
+
import_shared46 = require("@rsbuild/shared");
|
|
6607
6866
|
init_constants();
|
|
6867
|
+
init_helpers();
|
|
6868
|
+
init_logger();
|
|
6608
6869
|
getAssetName = (url2, assetPrefix) => {
|
|
6609
6870
|
if (url2.startsWith(assetPrefix)) {
|
|
6610
|
-
return
|
|
6871
|
+
return removeLeadingSlash(url2.replace(assetPrefix, ""));
|
|
6611
6872
|
}
|
|
6612
|
-
return
|
|
6873
|
+
return removeLeadingSlash(url2);
|
|
6613
6874
|
};
|
|
6614
6875
|
pluginSri = () => ({
|
|
6615
6876
|
name: "rsbuild:sri",
|
|
@@ -6618,7 +6879,7 @@ var init_sri = __esm({
|
|
|
6618
6879
|
const getAlgorithm = () => {
|
|
6619
6880
|
const config = api.getNormalizedConfig();
|
|
6620
6881
|
const { sri } = config.security;
|
|
6621
|
-
const enable = sri.enable === "auto" ? (0,
|
|
6882
|
+
const enable = sri.enable === "auto" ? (0, import_shared46.isProd)() : sri.enable;
|
|
6622
6883
|
if (!enable) {
|
|
6623
6884
|
return null;
|
|
6624
6885
|
}
|
|
@@ -6685,7 +6946,7 @@ var init_sri = __esm({
|
|
|
6685
6946
|
`integrity="${integrity}"`
|
|
6686
6947
|
);
|
|
6687
6948
|
} else {
|
|
6688
|
-
|
|
6949
|
+
import_rslog.logger.debug(
|
|
6689
6950
|
`[rsbuild:sri] failed to generate integrity for ${assetName}.`
|
|
6690
6951
|
);
|
|
6691
6952
|
replacedHtml = replacedHtml.replace(
|
|
@@ -6738,7 +6999,7 @@ var init_sri = __esm({
|
|
|
6738
6999
|
}
|
|
6739
7000
|
api.modifyBundlerChain((chain, { target }) => {
|
|
6740
7001
|
const config = api.getNormalizedConfig();
|
|
6741
|
-
if ((0,
|
|
7002
|
+
if ((0, import_shared46.isHtmlDisabled)(config, target)) {
|
|
6742
7003
|
return;
|
|
6743
7004
|
}
|
|
6744
7005
|
const algorithm = getAlgorithm();
|
|
@@ -6757,11 +7018,11 @@ var nonce_exports = {};
|
|
|
6757
7018
|
__export(nonce_exports, {
|
|
6758
7019
|
pluginNonce: () => pluginNonce
|
|
6759
7020
|
});
|
|
6760
|
-
var
|
|
7021
|
+
var pluginNonce;
|
|
6761
7022
|
var init_nonce = __esm({
|
|
6762
7023
|
"src/plugins/nonce.ts"() {
|
|
6763
7024
|
"use strict";
|
|
6764
|
-
|
|
7025
|
+
init_helpers();
|
|
6765
7026
|
pluginNonce = () => ({
|
|
6766
7027
|
name: "rsbuild:nonce",
|
|
6767
7028
|
setup(api) {
|
|
@@ -6770,7 +7031,7 @@ var init_nonce = __esm({
|
|
|
6770
7031
|
if (!nonce) {
|
|
6771
7032
|
return;
|
|
6772
7033
|
}
|
|
6773
|
-
|
|
7034
|
+
applyToCompiler(compiler, (compiler2) => {
|
|
6774
7035
|
const { plugins } = compiler2.options;
|
|
6775
7036
|
const hasHTML = plugins.some(
|
|
6776
7037
|
(plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
|
|
@@ -6778,7 +7039,7 @@ var init_nonce = __esm({
|
|
|
6778
7039
|
if (!hasHTML) {
|
|
6779
7040
|
return;
|
|
6780
7041
|
}
|
|
6781
|
-
const injectCode =
|
|
7042
|
+
const injectCode = createVirtualModule(
|
|
6782
7043
|
`__webpack_nonce__ = "${nonce}";`
|
|
6783
7044
|
);
|
|
6784
7045
|
new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
|
|
@@ -6816,8 +7077,8 @@ __export(prodServer_exports, {
|
|
|
6816
7077
|
startProdServer: () => startProdServer
|
|
6817
7078
|
});
|
|
6818
7079
|
async function startProdServer(context, config, { getPortSilently } = {}) {
|
|
6819
|
-
if (!(0,
|
|
6820
|
-
(0,
|
|
7080
|
+
if (!(0, import_shared47.getNodeEnv)()) {
|
|
7081
|
+
(0, import_shared47.setNodeEnv)("production");
|
|
6821
7082
|
}
|
|
6822
7083
|
const { port, host, https } = await getServerConfig({
|
|
6823
7084
|
config,
|
|
@@ -6885,13 +7146,14 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
|
|
|
6885
7146
|
);
|
|
6886
7147
|
});
|
|
6887
7148
|
}
|
|
6888
|
-
var import_node_path27,
|
|
7149
|
+
var import_node_path27, import_shared47, RsbuildProdServer;
|
|
6889
7150
|
var init_prodServer = __esm({
|
|
6890
7151
|
"src/server/prodServer.ts"() {
|
|
6891
7152
|
"use strict";
|
|
6892
7153
|
import_node_path27 = require("path");
|
|
6893
|
-
|
|
7154
|
+
import_shared47 = require("@rsbuild/shared");
|
|
6894
7155
|
init_constants();
|
|
7156
|
+
init_logger();
|
|
6895
7157
|
init_helper();
|
|
6896
7158
|
init_httpServer();
|
|
6897
7159
|
init_middlewares();
|
|
@@ -6910,7 +7172,7 @@ var init_prodServer = __esm({
|
|
|
6910
7172
|
}
|
|
6911
7173
|
async applyDefaultMiddlewares() {
|
|
6912
7174
|
const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
|
|
6913
|
-
if (
|
|
7175
|
+
if (import_rslog.logger.level === "verbose") {
|
|
6914
7176
|
this.middlewares.use(await getRequestLoggerMiddleware());
|
|
6915
7177
|
}
|
|
6916
7178
|
if (compress) {
|
|
@@ -7076,9 +7338,9 @@ async function createRsbuild(options = {}) {
|
|
|
7076
7338
|
);
|
|
7077
7339
|
const pluginAPI = getPluginAPI({ context, pluginManager });
|
|
7078
7340
|
context.pluginAPI = pluginAPI;
|
|
7079
|
-
|
|
7341
|
+
import_rslog.logger.debug("add default plugins");
|
|
7080
7342
|
await applyDefaultPlugins(pluginManager, context);
|
|
7081
|
-
|
|
7343
|
+
import_rslog.logger.debug("add default plugins done");
|
|
7082
7344
|
const provider = rsbuildConfig.provider || await getRspackProvider();
|
|
7083
7345
|
const providerInstance = await provider({
|
|
7084
7346
|
context,
|
|
@@ -7092,13 +7354,13 @@ async function createRsbuild(options = {}) {
|
|
|
7092
7354
|
return startProdServer2(context, config, options2);
|
|
7093
7355
|
};
|
|
7094
7356
|
const rsbuild = {
|
|
7095
|
-
...
|
|
7357
|
+
...pick(pluginManager, [
|
|
7096
7358
|
"addPlugins",
|
|
7097
7359
|
"getPlugins",
|
|
7098
7360
|
"removePlugins",
|
|
7099
7361
|
"isPluginExists"
|
|
7100
7362
|
]),
|
|
7101
|
-
...
|
|
7363
|
+
...pick(pluginAPI, [
|
|
7102
7364
|
"onBeforeBuild",
|
|
7103
7365
|
"onBeforeCreateCompiler",
|
|
7104
7366
|
"onBeforeStartDevServer",
|
|
@@ -7114,7 +7376,7 @@ async function createRsbuild(options = {}) {
|
|
|
7114
7376
|
"getRsbuildConfig",
|
|
7115
7377
|
"getNormalizedConfig"
|
|
7116
7378
|
]),
|
|
7117
|
-
...
|
|
7379
|
+
...pick(providerInstance, [
|
|
7118
7380
|
"build",
|
|
7119
7381
|
"initConfigs",
|
|
7120
7382
|
"inspectConfig",
|
|
@@ -7131,14 +7393,15 @@ async function createRsbuild(options = {}) {
|
|
|
7131
7393
|
}
|
|
7132
7394
|
return rsbuild;
|
|
7133
7395
|
}
|
|
7134
|
-
var
|
|
7396
|
+
var getRspackProvider, pickRsbuildConfig;
|
|
7135
7397
|
var init_createRsbuild = __esm({
|
|
7136
7398
|
"src/createRsbuild.ts"() {
|
|
7137
7399
|
"use strict";
|
|
7138
|
-
import_shared58 = require("@rsbuild/shared");
|
|
7139
7400
|
init_createContext();
|
|
7401
|
+
init_helpers();
|
|
7140
7402
|
init_initPlugins();
|
|
7141
7403
|
init_internal();
|
|
7404
|
+
init_logger();
|
|
7142
7405
|
init_pluginHelper();
|
|
7143
7406
|
init_pluginManager();
|
|
7144
7407
|
getRspackProvider = async () => {
|
|
@@ -7156,9 +7419,10 @@ var init_createRsbuild = __esm({
|
|
|
7156
7419
|
"security",
|
|
7157
7420
|
"performance",
|
|
7158
7421
|
"moduleFederation",
|
|
7422
|
+
"environments",
|
|
7159
7423
|
"_privateMeta"
|
|
7160
7424
|
];
|
|
7161
|
-
return
|
|
7425
|
+
return pick(rsbuildConfig, keys);
|
|
7162
7426
|
};
|
|
7163
7427
|
}
|
|
7164
7428
|
});
|
|
@@ -7177,7 +7441,7 @@ async function init({
|
|
|
7177
7441
|
cwd: root,
|
|
7178
7442
|
mode: cliOptions?.envMode
|
|
7179
7443
|
});
|
|
7180
|
-
if ((0,
|
|
7444
|
+
if ((0, import_shared48.isDev)()) {
|
|
7181
7445
|
onBeforeRestartServer(envs.cleanup);
|
|
7182
7446
|
}
|
|
7183
7447
|
const { content: config, filePath: configFilePath } = await loadConfig({
|
|
@@ -7217,19 +7481,20 @@ async function init({
|
|
|
7217
7481
|
});
|
|
7218
7482
|
} catch (err) {
|
|
7219
7483
|
if (isRestart) {
|
|
7220
|
-
|
|
7484
|
+
import_rslog.logger.error(err);
|
|
7221
7485
|
} else {
|
|
7222
7486
|
throw err;
|
|
7223
7487
|
}
|
|
7224
7488
|
}
|
|
7225
7489
|
}
|
|
7226
|
-
var
|
|
7490
|
+
var import_shared48, commonOpts;
|
|
7227
7491
|
var init_init = __esm({
|
|
7228
7492
|
"src/cli/init.ts"() {
|
|
7229
7493
|
"use strict";
|
|
7230
|
-
|
|
7494
|
+
import_shared48 = require("@rsbuild/shared");
|
|
7231
7495
|
init_config();
|
|
7232
7496
|
init_loadEnv();
|
|
7497
|
+
init_logger();
|
|
7233
7498
|
init_restart();
|
|
7234
7499
|
commonOpts = {};
|
|
7235
7500
|
}
|
|
@@ -7237,7 +7502,7 @@ var init_init = __esm({
|
|
|
7237
7502
|
|
|
7238
7503
|
// src/cli/commands.ts
|
|
7239
7504
|
function runCli() {
|
|
7240
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.
|
|
7505
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.9");
|
|
7241
7506
|
const devCommand = import_commander.program.command("dev");
|
|
7242
7507
|
const buildCommand = import_commander.program.command("build");
|
|
7243
7508
|
const previewCommand = import_commander.program.command("preview");
|
|
@@ -7251,8 +7516,8 @@ function runCli() {
|
|
|
7251
7516
|
const rsbuild = await init({ cliOptions: options });
|
|
7252
7517
|
await rsbuild?.startDevServer();
|
|
7253
7518
|
} catch (err) {
|
|
7254
|
-
|
|
7255
|
-
|
|
7519
|
+
import_rslog.logger.error("Failed to start dev server.");
|
|
7520
|
+
import_rslog.logger.error(err);
|
|
7256
7521
|
process.exit(1);
|
|
7257
7522
|
}
|
|
7258
7523
|
});
|
|
@@ -7263,8 +7528,8 @@ function runCli() {
|
|
|
7263
7528
|
watch: options.watch
|
|
7264
7529
|
});
|
|
7265
7530
|
} catch (err) {
|
|
7266
|
-
|
|
7267
|
-
|
|
7531
|
+
import_rslog.logger.error("Failed to build.");
|
|
7532
|
+
import_rslog.logger.error(err);
|
|
7268
7533
|
process.exit(1);
|
|
7269
7534
|
}
|
|
7270
7535
|
});
|
|
@@ -7275,14 +7540,14 @@ function runCli() {
|
|
|
7275
7540
|
const { distPath } = rsbuild.context;
|
|
7276
7541
|
if (!(0, import_node_fs5.existsSync)(distPath)) {
|
|
7277
7542
|
throw new Error(
|
|
7278
|
-
`The output directory ${
|
|
7543
|
+
`The output directory ${import_shared49.color.yellow(
|
|
7279
7544
|
distPath
|
|
7280
7545
|
)} does not exist, please build the project before previewing.`
|
|
7281
7546
|
);
|
|
7282
7547
|
}
|
|
7283
7548
|
if (isEmptyDir(distPath)) {
|
|
7284
7549
|
throw new Error(
|
|
7285
|
-
`The output directory ${
|
|
7550
|
+
`The output directory ${import_shared49.color.yellow(
|
|
7286
7551
|
distPath
|
|
7287
7552
|
)} is empty, please build the project before previewing.`
|
|
7288
7553
|
);
|
|
@@ -7290,8 +7555,8 @@ function runCli() {
|
|
|
7290
7555
|
}
|
|
7291
7556
|
await rsbuild?.preview();
|
|
7292
7557
|
} catch (err) {
|
|
7293
|
-
|
|
7294
|
-
|
|
7558
|
+
import_rslog.logger.error("Failed to start preview server.");
|
|
7559
|
+
import_rslog.logger.error(err);
|
|
7295
7560
|
process.exit(1);
|
|
7296
7561
|
}
|
|
7297
7562
|
});
|
|
@@ -7305,22 +7570,23 @@ function runCli() {
|
|
|
7305
7570
|
writeToDisk: true
|
|
7306
7571
|
});
|
|
7307
7572
|
} catch (err) {
|
|
7308
|
-
|
|
7309
|
-
|
|
7573
|
+
import_rslog.logger.error("Failed to inspect config.");
|
|
7574
|
+
import_rslog.logger.error(err);
|
|
7310
7575
|
process.exit(1);
|
|
7311
7576
|
}
|
|
7312
7577
|
});
|
|
7313
7578
|
import_commander.program.parse();
|
|
7314
7579
|
}
|
|
7315
|
-
var import_node_fs5, import_node_path28,
|
|
7580
|
+
var import_node_fs5, import_node_path28, import_shared49, import_commander, applyCommonOptions, applyServerOptions;
|
|
7316
7581
|
var init_commands = __esm({
|
|
7317
7582
|
"src/cli/commands.ts"() {
|
|
7318
7583
|
"use strict";
|
|
7319
7584
|
import_node_fs5 = require("fs");
|
|
7320
7585
|
import_node_path28 = require("path");
|
|
7321
|
-
|
|
7586
|
+
import_shared49 = require("@rsbuild/shared");
|
|
7322
7587
|
import_commander = require("../compiled/commander/index.js");
|
|
7323
7588
|
init_helpers();
|
|
7589
|
+
init_logger();
|
|
7324
7590
|
init_init();
|
|
7325
7591
|
applyCommonOptions = (command) => {
|
|
7326
7592
|
command.option(
|
|
@@ -7350,21 +7616,22 @@ function prepareCli() {
|
|
|
7350
7616
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
7351
7617
|
console.log();
|
|
7352
7618
|
}
|
|
7353
|
-
|
|
7619
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.7.9"}`}
|
|
7354
7620
|
`);
|
|
7355
7621
|
}
|
|
7356
|
-
var import_shared61;
|
|
7357
7622
|
var init_prepare = __esm({
|
|
7358
7623
|
"src/cli/prepare.ts"() {
|
|
7359
7624
|
"use strict";
|
|
7360
|
-
|
|
7625
|
+
init_logger();
|
|
7361
7626
|
}
|
|
7362
7627
|
});
|
|
7363
7628
|
|
|
7364
7629
|
// src/internal.ts
|
|
7365
7630
|
var internal_exports = {};
|
|
7366
7631
|
__export(internal_exports, {
|
|
7632
|
+
TARGET_ID_MAP: () => TARGET_ID_MAP,
|
|
7367
7633
|
applySwcDecoratorConfig: () => applySwcDecoratorConfig,
|
|
7634
|
+
chainToConfig: () => chainToConfig,
|
|
7368
7635
|
createDevServer: () => createDevServer,
|
|
7369
7636
|
createPluginManager: () => createPluginManager,
|
|
7370
7637
|
formatStats: () => formatStats,
|
|
@@ -7376,6 +7643,8 @@ __export(internal_exports, {
|
|
|
7376
7643
|
initHooks: () => initHooks,
|
|
7377
7644
|
initPlugins: () => initPlugins,
|
|
7378
7645
|
initRsbuildConfig: () => initRsbuildConfig,
|
|
7646
|
+
modifyBundlerChain: () => modifyBundlerChain,
|
|
7647
|
+
onCompileDone: () => onCompileDone,
|
|
7379
7648
|
outputInspectConfigFiles: () => outputInspectConfigFiles,
|
|
7380
7649
|
prepareCli: () => prepareCli,
|
|
7381
7650
|
runCli: () => runCli,
|
|
@@ -7394,10 +7663,12 @@ var init_internal = __esm({
|
|
|
7394
7663
|
init_pluginHelper();
|
|
7395
7664
|
init_helpers();
|
|
7396
7665
|
init_rspackConfig();
|
|
7666
|
+
init_configChain();
|
|
7397
7667
|
init_swc();
|
|
7398
7668
|
init_minimize();
|
|
7399
7669
|
init_devMiddleware();
|
|
7400
7670
|
init_devServer();
|
|
7671
|
+
init_constants();
|
|
7401
7672
|
}
|
|
7402
7673
|
});
|
|
7403
7674
|
|
|
@@ -7412,7 +7683,7 @@ __export(src_exports, {
|
|
|
7412
7683
|
ensureAssetPrefix: () => ensureAssetPrefix,
|
|
7413
7684
|
loadConfig: () => loadConfig,
|
|
7414
7685
|
loadEnv: () => loadEnv,
|
|
7415
|
-
logger: () =>
|
|
7686
|
+
logger: () => import_rslog.logger,
|
|
7416
7687
|
mergeRsbuildConfig: () => mergeRsbuildConfig,
|
|
7417
7688
|
rspack: () => import_core10.rspack,
|
|
7418
7689
|
version: () => version
|
|
@@ -7423,11 +7694,11 @@ init_internal();
|
|
|
7423
7694
|
init_loadEnv();
|
|
7424
7695
|
init_createRsbuild();
|
|
7425
7696
|
init_config();
|
|
7426
|
-
|
|
7697
|
+
init_logger();
|
|
7427
7698
|
init_mergeConfig();
|
|
7428
7699
|
init_helpers();
|
|
7429
7700
|
init_constants();
|
|
7430
|
-
var version = "0.7.
|
|
7701
|
+
var version = "0.7.9";
|
|
7431
7702
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7432
7703
|
0 && (module.exports = {
|
|
7433
7704
|
PLUGIN_CSS_NAME,
|