@rsbuild/core 0.7.7 → 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.
Files changed (40) hide show
  1. package/bin/rsbuild.js +1 -2
  2. package/compiled/css-loader/index.js +23 -23
  3. package/compiled/jiti/index.d.ts +1 -0
  4. package/compiled/jiti/index.js +391 -0
  5. package/compiled/jiti/license +21 -0
  6. package/compiled/jiti/package.json +1 -0
  7. package/compiled/launch-editor-middleware/index.js +21 -15
  8. package/compiled/launch-editor-middleware/package.json +1 -1
  9. package/compiled/postcss-load-config/index.js +1 -1
  10. package/compiled/postcss-loader/index.js +14 -14
  11. package/compiled/rslog/index.d.ts +66 -0
  12. package/compiled/rslog/index.js +334 -0
  13. package/compiled/rslog/license +21 -0
  14. package/compiled/rslog/package.json +1 -0
  15. package/compiled/rspack-manifest-plugin/index.js +4 -4
  16. package/compiled/semver/index.d.ts +1 -0
  17. package/compiled/semver/index.js +2585 -0
  18. package/compiled/semver/license +15 -0
  19. package/compiled/semver/package.json +1 -0
  20. package/compiled/webpack-dev-middleware/index.js +280 -10
  21. package/compiled/ws/index.js +80 -57
  22. package/compiled/ws/package.json +1 -1
  23. package/dist/index.cjs +1082 -762
  24. package/dist/index.js +866 -601
  25. package/dist-types/configChain.d.ts +10 -0
  26. package/dist-types/constants.d.ts +2 -0
  27. package/dist-types/createContext.d.ts +1 -1
  28. package/dist-types/helpers.d.ts +22 -3
  29. package/dist-types/index.d.ts +2 -1
  30. package/dist-types/initPlugins.d.ts +1 -1
  31. package/dist-types/internal.d.ts +4 -2
  32. package/dist-types/logger.d.ts +4 -0
  33. package/dist-types/provider/initConfigs.d.ts +1 -1
  34. package/dist-types/server/devMiddleware.d.ts +11 -1
  35. package/dist-types/server/helper.d.ts +1 -0
  36. package/dist-types/server/proxy.d.ts +1 -1
  37. package/dist-types/server/socketServer.d.ts +1 -1
  38. package/dist-types/types.d.ts +1 -2
  39. package/package.json +8 -5
  40. package/dist-types/server/index.d.ts +0 -2
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 = import_shared.color.bold(
178
- import_shared.color.red(isTerserError ? "Minify error: " : "Compile error: ")
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
- ${import_shared.color.yellow(`For more details, please setting 'stats.errors: true' `)}`;
224
+ ${import_shared2.color.yellow(`For more details, please setting 'stats.errors: true' `)}`;
183
225
  }
184
- const tip = import_shared.color.yellow(
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 ((0, import_shared.isMultiCompiler)(compiler)) {
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, import_shared.isProd)() || (0, import_shared.isDebug)()
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 = import_shared.color.bold(import_shared.color.yellow("Compile Warning: \n"));
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 = import_shared2.fse.readdirSync(path13);
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 import_shared2.fse.promises.access(file, import_shared2.fse.constants.F_OK).then(() => true).catch(() => false);
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];
319
+ }
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
+ );
239
345
  }
240
- var import_node_path2, import_shared, import_shared2, rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists;
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
- ${import_shared.color.yellow(tips.join("\n"))}`;
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 ? (0, import_shared.addTrailingSlash)(publicPath) : (0, import_shared.removeTailingSlash)(publicPath);
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(import_shared.DEFAULT_ASSET_PREFIX, withSlash);
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 import_shared2.fse.statSync(filePath, { throwIfNoEntry: false })?.isFile();
481
+ return import_shared3.fse.statSync(filePath, { throwIfNoEntry: false })?.isFile();
372
482
  } catch (_) {
373
483
  return false;
374
484
  }
@@ -381,15 +491,87 @@ ${import_shared.color.yellow(tips.join("\n"))}`;
381
491
  }
382
492
  return false;
383
493
  };
494
+ urlJoin = (base, path13) => {
495
+ const fullUrl = new URL(base);
496
+ fullUrl.pathname = import_node_path2.posix.join(fullUrl.pathname, path13);
497
+ return fullUrl.toString();
498
+ };
499
+ canParse = (url2) => {
500
+ try {
501
+ new URL(url2);
502
+ return true;
503
+ } catch {
504
+ return false;
505
+ }
506
+ };
507
+ ensureAssetPrefix = (url2, assetPrefix) => {
508
+ if (url2.startsWith("//")) {
509
+ return url2;
510
+ }
511
+ if (canParse(url2)) {
512
+ return url2;
513
+ }
514
+ if (assetPrefix.startsWith("http")) {
515
+ return urlJoin(assetPrefix, url2);
516
+ }
517
+ if (assetPrefix.startsWith("//")) {
518
+ return urlJoin(`https:${assetPrefix}`, url2).replace("https:", "");
519
+ }
520
+ return import_node_path2.posix.join(assetPrefix, url2);
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
+ };
384
566
  }
385
567
  });
386
568
 
387
569
  // src/mergeConfig.ts
388
- var import_shared3, OVERRIDE_PATH, isOverridePath, merge, mergeRsbuildConfig;
570
+ var import_shared4, OVERRIDE_PATH, isOverridePath, merge, mergeRsbuildConfig;
389
571
  var init_mergeConfig = __esm({
390
572
  "src/mergeConfig.ts"() {
391
573
  "use strict";
392
- import_shared3 = require("@rsbuild/shared");
574
+ import_shared4 = require("@rsbuild/shared");
393
575
  OVERRIDE_PATH = [
394
576
  "performance.removeConsole",
395
577
  "output.inlineScripts",
@@ -415,12 +597,12 @@ var init_mergeConfig = __esm({
415
597
  }
416
598
  const pair = [x, y];
417
599
  if (pair.some(Array.isArray)) {
418
- return [...(0, import_shared3.castArray)(x), ...(0, import_shared3.castArray)(y)];
600
+ return [...(0, import_shared4.castArray)(x), ...(0, import_shared4.castArray)(y)];
419
601
  }
420
- if (pair.some(import_shared3.isFunction)) {
602
+ if (pair.some(import_shared4.isFunction)) {
421
603
  return pair;
422
604
  }
423
- if (!(0, import_shared3.isPlainObject)(x) || !(0, import_shared3.isPlainObject)(y)) {
605
+ if (!(0, import_shared4.isPlainObject)(x) || !(0, import_shared4.isPlainObject)(y)) {
424
606
  return y;
425
607
  }
426
608
  const merged = {};
@@ -447,13 +629,14 @@ var init_mergeConfig = __esm({
447
629
  });
448
630
 
449
631
  // src/server/restart.ts
450
- var import_node_path3, import_shared4, cleaners, onBeforeRestartServer, clearConsole, restartDevServer;
632
+ var import_node_path3, import_shared5, cleaners, onBeforeRestartServer, clearConsole, restartDevServer;
451
633
  var init_restart = __esm({
452
634
  "src/server/restart.ts"() {
453
635
  "use strict";
454
636
  import_node_path3 = __toESM(require("path"));
455
- import_shared4 = require("@rsbuild/shared");
637
+ import_shared5 = require("@rsbuild/shared");
456
638
  init_init();
639
+ init_logger();
457
640
  cleaners = [];
458
641
  onBeforeRestartServer = (cleaner) => {
459
642
  cleaners.push(cleaner);
@@ -466,7 +649,7 @@ var init_restart = __esm({
466
649
  restartDevServer = async ({ filePath }) => {
467
650
  clearConsole();
468
651
  const filename = import_node_path3.default.basename(filePath);
469
- import_shared4.logger.info(`Restart because ${import_shared4.color.yellow(filename)} is changed.
652
+ import_rslog.logger.info(`Restart because ${import_shared5.color.yellow(filename)} is changed.
470
653
  `);
471
654
  for (const cleaner of cleaners) {
472
655
  await cleaner();
@@ -515,7 +698,7 @@ async function watchFiles(files) {
515
698
  // If watching fails due to read permissions, the errors will be suppressed silently.
516
699
  ignorePermissionErrors: true
517
700
  });
518
- const callback = (0, import_shared5.debounce)(
701
+ const callback = debounce(
519
702
  async (filePath) => {
520
703
  watcher.close();
521
704
  await restartDevServer({ filePath });
@@ -544,7 +727,7 @@ async function loadConfig({
544
727
  return config;
545
728
  };
546
729
  try {
547
- const { default: jiti } = await import("@rsbuild/shared/jiti");
730
+ const { default: jiti } = await import("../compiled/jiti/index.js");
548
731
  const loadConfig2 = jiti(__filename, {
549
732
  esmResolve: true,
550
733
  // disable require cache to support restart CLI and read the new config
@@ -555,22 +738,22 @@ async function loadConfig({
555
738
  if (typeof configExport === "function") {
556
739
  const command = process.argv[2];
557
740
  const params = {
558
- env: (0, import_shared5.getNodeEnv)(),
741
+ env: (0, import_shared6.getNodeEnv)(),
559
742
  command,
560
- envMode: envMode || (0, import_shared5.getNodeEnv)()
743
+ envMode: envMode || (0, import_shared6.getNodeEnv)()
561
744
  };
562
745
  const result = await configExport(params);
563
746
  if (result === void 0) {
564
- throw new Error("Rsbuild config function must return a config object.");
747
+ throw new Error("The config function must return a config object.");
565
748
  }
566
749
  return {
567
750
  content: applyMetaInfo(result),
568
751
  filePath: configFilePath
569
752
  };
570
753
  }
571
- if (!(0, import_shared5.isObject)(configExport)) {
754
+ if (!(0, import_shared6.isObject)(configExport)) {
572
755
  throw new Error(
573
- `Rsbuild config must be an object or a function that returns an object, get ${import_shared5.color.yellow(
756
+ `The config must be an object or a function that returns an object, get ${import_shared6.color.yellow(
574
757
  configExport
575
758
  )}`
576
759
  );
@@ -580,7 +763,7 @@ async function loadConfig({
580
763
  filePath: configFilePath
581
764
  };
582
765
  } catch (err) {
583
- import_shared5.logger.error(`Failed to load file: ${import_shared5.color.dim(configFilePath)}`);
766
+ import_rslog.logger.error(`Failed to load file: ${import_shared6.color.dim(configFilePath)}`);
584
767
  throw err;
585
768
  }
586
769
  }
@@ -602,27 +785,27 @@ async function outputInspectConfigFiles({
602
785
  const suffix = rsbuildConfig.output.targets[index];
603
786
  const outputFile = `${configType}.config.${suffix}.mjs`;
604
787
  let outputFilePath = (0, import_node_path4.join)(outputPath, outputFile);
605
- if (import_shared5.fse.existsSync(outputFilePath)) {
788
+ if (import_shared6.fse.existsSync(outputFilePath)) {
606
789
  outputFilePath = outputFilePath.replace(/\.mjs$/, `.${Date.now()}.mjs`);
607
790
  }
608
791
  return {
609
792
  path: outputFilePath,
610
- label: `${(0, import_shared5.upperFirst)(configType)} Config (${suffix})`,
793
+ label: `${upperFirst(configType)} Config (${suffix})`,
611
794
  content
612
795
  };
613
796
  })
614
797
  ];
615
798
  await Promise.all(
616
799
  files.map(
617
- (item) => import_shared5.fse.outputFile(item.path, `export default ${item.content}`)
800
+ (item) => import_shared6.fse.outputFile(item.path, `export default ${item.content}`)
618
801
  )
619
802
  );
620
803
  const fileInfos = files.map(
621
- (item) => ` - ${import_shared5.color.bold(import_shared5.color.yellow(item.label))}: ${import_shared5.color.underline(
804
+ (item) => ` - ${import_shared6.color.bold(import_shared6.color.yellow(item.label))}: ${import_shared6.color.underline(
622
805
  item.path
623
806
  )}`
624
807
  ).join("\n");
625
- import_shared5.logger.success(
808
+ import_rslog.logger.success(
626
809
  `Inspect config succeed, open following files to view the content:
627
810
 
628
811
  ${fileInfos}
@@ -630,24 +813,25 @@ ${fileInfos}
630
813
  );
631
814
  }
632
815
  async function stringifyConfig(config, verbose) {
633
- const stringify = import_shared5.RspackChain.toString;
816
+ const stringify = import_shared6.RspackChain.toString;
634
817
  return stringify(config, { verbose });
635
818
  }
636
- var import_node_fs, import_node_path4, import_shared5, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath, normalizePublicDirs;
819
+ var import_node_fs, import_node_path4, import_shared6, getDefaultDevConfig, getDefaultServerConfig, getDefaultSourceConfig, getDefaultHtmlConfig, getDefaultSecurityConfig, getDefaultToolsConfig, getDefaultPerformanceConfig, getDefaultOutputConfig, createDefaultConfig, withDefaultConfig, normalizeConfig, resolveConfigPath, normalizePublicDirs;
637
820
  var init_config = __esm({
638
821
  "src/config.ts"() {
639
822
  "use strict";
640
823
  import_node_fs = __toESM(require("fs"));
641
824
  import_node_path4 = require("path");
642
- import_shared5 = require("@rsbuild/shared");
825
+ import_shared6 = require("@rsbuild/shared");
643
826
  init_constants();
644
827
  init_helpers();
828
+ init_logger();
645
829
  init_mergeConfig();
646
830
  init_restart();
647
831
  getDefaultDevConfig = () => ({
648
832
  hmr: true,
649
833
  liveReload: true,
650
- assetPrefix: import_shared5.DEFAULT_ASSET_PREFIX,
834
+ assetPrefix: import_shared6.DEFAULT_ASSET_PREFIX,
651
835
  startUrl: false,
652
836
  client: {
653
837
  overlay: true
@@ -722,7 +906,7 @@ var init_config = __esm({
722
906
  server: SERVER_DIST_DIR,
723
907
  worker: SERVICE_WORKER_DIST_DIR
724
908
  },
725
- assetPrefix: import_shared5.DEFAULT_ASSET_PREFIX,
909
+ assetPrefix: import_shared6.DEFAULT_ASSET_PREFIX,
726
910
  filename: {},
727
911
  charset: "ascii",
728
912
  polyfill: "usage",
@@ -782,7 +966,7 @@ var init_config = __esm({
782
966
  if (import_node_fs.default.existsSync(customConfigPath)) {
783
967
  return customConfigPath;
784
968
  }
785
- import_shared5.logger.warn(`Cannot find config file: ${import_shared5.color.dim(customConfigPath)}
969
+ import_rslog.logger.warn(`Cannot find config file: ${import_shared6.color.dim(customConfigPath)}
786
970
  `);
787
971
  }
788
972
  const CONFIG_FILES = [
@@ -832,7 +1016,7 @@ var init_config = __esm({
832
1016
  // src/loadEnv.ts
833
1017
  function loadEnv({
834
1018
  cwd = process.cwd(),
835
- mode = (0, import_shared6.getNodeEnv)(),
1019
+ mode = (0, import_shared7.getNodeEnv)(),
836
1020
  prefixes = ["PUBLIC_"]
837
1021
  } = {}) {
838
1022
  if (mode === "local") {
@@ -882,13 +1066,13 @@ function loadEnv({
882
1066
  publicVars
883
1067
  };
884
1068
  }
885
- var import_node_fs2, import_node_path5, import_shared6, import_dotenv, import_dotenv_expand;
1069
+ var import_node_fs2, import_node_path5, import_shared7, import_dotenv, import_dotenv_expand;
886
1070
  var init_loadEnv = __esm({
887
1071
  "src/loadEnv.ts"() {
888
1072
  "use strict";
889
1073
  import_node_fs2 = __toESM(require("fs"));
890
1074
  import_node_path5 = require("path");
891
- import_shared6 = require("@rsbuild/shared");
1075
+ import_shared7 = require("@rsbuild/shared");
892
1076
  import_dotenv = require("../compiled/dotenv/index.js");
893
1077
  import_dotenv_expand = require("../compiled/dotenv-expand/index.js");
894
1078
  init_helpers();
@@ -901,7 +1085,7 @@ function createAsyncHook() {
901
1085
  const postGroup = [];
902
1086
  const defaultGroup = [];
903
1087
  const tap = (cb) => {
904
- if ((0, import_shared7.isFunction)(cb)) {
1088
+ if ((0, import_shared8.isFunction)(cb)) {
905
1089
  defaultGroup.push(cb);
906
1090
  } else if (cb.order === "pre") {
907
1091
  preGroup.push(cb.handler);
@@ -948,11 +1132,11 @@ function initHooks() {
948
1132
  modifyRsbuildConfig: createAsyncHook()
949
1133
  };
950
1134
  }
951
- var import_shared7;
1135
+ var import_shared8;
952
1136
  var init_initHooks = __esm({
953
1137
  "src/initHooks.ts"() {
954
1138
  "use strict";
955
- import_shared7 = require("@rsbuild/shared");
1139
+ import_shared8 = require("@rsbuild/shared");
956
1140
  }
957
1141
  });
958
1142
 
@@ -966,17 +1150,18 @@ function getEntryObject(config, target) {
966
1150
  if (!config.source?.entry) {
967
1151
  return {};
968
1152
  }
969
- return (0, import_shared8.reduceConfigsMergeContext)({
1153
+ return (0, import_shared9.reduceConfigsMergeContext)({
970
1154
  initial: {},
971
1155
  config: config.source?.entry,
972
1156
  ctx: { target }
973
1157
  });
974
1158
  }
975
- var import_shared8, pluginEntry;
1159
+ var import_shared9, pluginEntry;
976
1160
  var init_entry = __esm({
977
1161
  "src/plugins/entry.ts"() {
978
1162
  "use strict";
979
- import_shared8 = require("@rsbuild/shared");
1163
+ import_shared9 = require("@rsbuild/shared");
1164
+ init_helpers();
980
1165
  pluginEntry = () => ({
981
1166
  name: "rsbuild:entry",
982
1167
  setup(api) {
@@ -993,18 +1178,18 @@ var init_entry = __esm({
993
1178
  };
994
1179
  preEntry.forEach(addEntry);
995
1180
  if (injectCoreJsEntry) {
996
- addEntry((0, import_shared8.createVirtualModule)('import "core-js";'));
1181
+ addEntry(createVirtualModule('import "core-js";'));
997
1182
  }
998
- (0, import_shared8.castArray)(entry[entryName]).forEach(addEntry);
1183
+ (0, import_shared9.castArray)(entry[entryName]).forEach(addEntry);
999
1184
  }
1000
1185
  }
1001
1186
  );
1002
1187
  api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
1003
1188
  if (bundlerConfigs.every((config) => !config.entry)) {
1004
1189
  throw new Error(
1005
- `Could not find any entry module, please make sure that ${import_shared8.color.cyan(
1190
+ `Could not find any entry module, please make sure that ${import_shared9.color.cyan(
1006
1191
  "src/index.(ts|js|tsx|jsx|mjs|cjs)"
1007
- )} exists, or customize entry through the ${import_shared8.color.cyan(
1192
+ )} exists, or customize entry through the ${import_shared9.color.cyan(
1008
1193
  "source.entry"
1009
1194
  )} configuration.`
1010
1195
  );
@@ -1020,7 +1205,7 @@ function getAbsolutePath(root, filepath) {
1020
1205
  return (0, import_node_path6.isAbsolute)(filepath) ? filepath : (0, import_node_path6.join)(root, filepath);
1021
1206
  }
1022
1207
  function getAbsoluteDistPath(cwd, config) {
1023
- const dirRoot = (0, import_shared9.getDistPath)(config, "root");
1208
+ const dirRoot = config.output?.distPath?.root ?? ROOT_DIST_DIR;
1024
1209
  return getAbsolutePath(cwd, dirRoot);
1025
1210
  }
1026
1211
  async function createContextByConfig(options, bundlerType, config = {}) {
@@ -1032,7 +1217,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
1032
1217
  return {
1033
1218
  entry: getEntryObject(config, "web"),
1034
1219
  targets: config.output?.targets || [],
1035
- version: "0.7.7",
1220
+ version: "0.7.9",
1036
1221
  rootPath,
1037
1222
  distPath,
1038
1223
  cachePath,
@@ -1074,7 +1259,7 @@ function createPublicContext(context) {
1074
1259
  return void 0;
1075
1260
  },
1076
1261
  set(_, prop) {
1077
- import_shared9.logger.error(
1262
+ import_rslog.logger.error(
1078
1263
  `Context is readonly, you can not assign to the "context.${prop}" prop.`
1079
1264
  );
1080
1265
  return true;
@@ -1095,23 +1280,23 @@ async function createContext(options, userRsbuildConfig, bundlerType) {
1095
1280
  originalConfig: userRsbuildConfig
1096
1281
  };
1097
1282
  }
1098
- var import_node_path6, import_shared9;
1283
+ var import_node_path6;
1099
1284
  var init_createContext = __esm({
1100
1285
  "src/createContext.ts"() {
1101
1286
  "use strict";
1102
1287
  import_node_path6 = require("path");
1103
- import_shared9 = require("@rsbuild/shared");
1104
1288
  init_config();
1289
+ init_constants();
1105
1290
  init_initHooks();
1291
+ init_logger();
1106
1292
  init_entry();
1107
1293
  }
1108
1294
  });
1109
1295
 
1110
1296
  // src/initPlugins.ts
1111
1297
  function getHTMLPathByEntry(entryName, config) {
1112
- const htmlPath = (0, import_shared10.getDistPath)(config, "html");
1113
1298
  const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
1114
- return (0, import_shared10.removeLeadingSlash)(`${htmlPath}/${filename}`);
1299
+ return removeLeadingSlash(`${config.output.distPath.html}/${filename}`);
1115
1300
  }
1116
1301
  function applyTransformPlugin(chain, transformer) {
1117
1302
  const name = "RsbuildTransformPlugin";
@@ -1228,14 +1413,14 @@ function getPluginAPI({
1228
1413
  modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap
1229
1414
  };
1230
1415
  }
1231
- var import_node_path7, import_shared10;
1416
+ var import_node_path7;
1232
1417
  var init_initPlugins = __esm({
1233
1418
  "src/initPlugins.ts"() {
1234
1419
  "use strict";
1235
1420
  import_node_path7 = require("path");
1236
- import_shared10 = require("@rsbuild/shared");
1237
1421
  init_constants();
1238
1422
  init_createContext();
1423
+ init_helpers();
1239
1424
  }
1240
1425
  });
1241
1426
 
@@ -1276,18 +1461,18 @@ function validatePlugin(plugin) {
1276
1461
  `Expect Rsbuild plugin instance to be an object, but got ${type}.`
1277
1462
  );
1278
1463
  }
1279
- if ((0, import_shared11.isFunction)(plugin.setup)) {
1464
+ if ((0, import_shared10.isFunction)(plugin.setup)) {
1280
1465
  return;
1281
1466
  }
1282
- if ((0, import_shared11.isFunction)(plugin.apply)) {
1467
+ if ((0, import_shared10.isFunction)(plugin.apply)) {
1283
1468
  const { name = "SomeWebpackPlugin" } = plugin.constructor || {};
1284
1469
  const messages = [
1285
- `${import_shared11.color.yellow(
1470
+ `${import_shared10.color.yellow(
1286
1471
  name
1287
- )} looks like a Webpack or Rspack plugin, please use ${import_shared11.color.yellow(
1472
+ )} looks like a Webpack or Rspack plugin, please use ${import_shared10.color.yellow(
1288
1473
  "`tools.rspack`"
1289
1474
  )} to register it:`,
1290
- import_shared11.color.green(`
1475
+ import_shared10.color.green(`
1291
1476
  // rsbuild.config.ts
1292
1477
  export default {
1293
1478
  tools: {
@@ -1314,13 +1499,13 @@ function createPluginManager() {
1314
1499
  }
1315
1500
  validatePlugin(newPlugin);
1316
1501
  if (plugins.find((item) => item.name === newPlugin.name)) {
1317
- import_shared11.logger.warn(
1502
+ import_rslog.logger.warn(
1318
1503
  `Rsbuild plugin "${newPlugin.name}" registered multiple times.`
1319
1504
  );
1320
1505
  } else if (before) {
1321
1506
  const index = plugins.findIndex((item) => item.name === before);
1322
1507
  if (index === -1) {
1323
- import_shared11.logger.warn(`Plugin "${before}" does not exist.`);
1508
+ import_rslog.logger.warn(`Plugin "${before}" does not exist.`);
1324
1509
  plugins.push(newPlugin);
1325
1510
  } else {
1326
1511
  plugins.splice(index, 0, newPlugin);
@@ -1345,7 +1530,7 @@ async function initPlugins({
1345
1530
  pluginAPI,
1346
1531
  pluginManager
1347
1532
  }) {
1348
- (0, import_shared11.debug)("init plugins");
1533
+ import_rslog.logger.debug("init plugins");
1349
1534
  const plugins = pluginDagSort(pluginManager.getPlugins());
1350
1535
  const removedPlugins = plugins.reduce((ret, plugin) => {
1351
1536
  if (plugin.remove) {
@@ -1359,13 +1544,14 @@ async function initPlugins({
1359
1544
  }
1360
1545
  await plugin.setup(pluginAPI);
1361
1546
  }
1362
- (0, import_shared11.debug)("init plugins done");
1547
+ import_rslog.logger.debug("init plugins done");
1363
1548
  }
1364
- var import_shared11, pluginDagSort;
1549
+ var import_shared10, pluginDagSort;
1365
1550
  var init_pluginManager = __esm({
1366
1551
  "src/pluginManager.ts"() {
1367
1552
  "use strict";
1368
- import_shared11 = require("@rsbuild/shared");
1553
+ import_shared10 = require("@rsbuild/shared");
1554
+ init_logger();
1369
1555
  pluginDagSort = (plugins) => {
1370
1556
  let allLines = [];
1371
1557
  function getPlugin(name) {
@@ -1436,9 +1622,9 @@ async function inspectConfig({
1436
1622
  inspectOptions = {}
1437
1623
  }) {
1438
1624
  if (inspectOptions.env) {
1439
- (0, import_shared12.setNodeEnv)(inspectOptions.env);
1440
- } else if (!(0, import_shared12.getNodeEnv)()) {
1441
- (0, import_shared12.setNodeEnv)("development");
1625
+ (0, import_shared11.setNodeEnv)(inspectOptions.env);
1626
+ } else if (!(0, import_shared11.getNodeEnv)()) {
1627
+ (0, import_shared11.setNodeEnv)("development");
1442
1628
  }
1443
1629
  const rspackConfigs = bundlerConfigs || (await initConfigs({
1444
1630
  context,
@@ -1483,20 +1669,81 @@ async function inspectConfig({
1483
1669
  }
1484
1670
  };
1485
1671
  }
1486
- var import_node_path8, import_shared12;
1672
+ var import_node_path8, import_shared11;
1487
1673
  var init_inspectConfig = __esm({
1488
1674
  "src/provider/inspectConfig.ts"() {
1489
1675
  "use strict";
1490
1676
  import_node_path8 = require("path");
1491
- import_shared12 = require("@rsbuild/shared");
1677
+ import_shared11 = require("@rsbuild/shared");
1492
1678
  init_config();
1493
1679
  init_initConfigs();
1494
1680
  }
1495
1681
  });
1496
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
+
1497
1744
  // src/provider/rspackConfig.ts
1498
1745
  async function modifyRspackConfig(context, rspackConfig, utils) {
1499
- (0, import_shared13.debug)("modify Rspack config");
1746
+ import_rslog.logger.debug("modify Rspack config");
1500
1747
  let [modifiedConfig] = await context.hooks.modifyRspackConfig.call(
1501
1748
  rspackConfig,
1502
1749
  utils
@@ -1509,7 +1756,7 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
1509
1756
  mergeFn: utils.mergeConfig
1510
1757
  });
1511
1758
  }
1512
- (0, import_shared13.debug)("modify Rspack config done");
1759
+ import_rslog.logger.debug("modify Rspack config done");
1513
1760
  return modifiedConfig;
1514
1761
  }
1515
1762
  async function getConfigUtils(config, chainUtils) {
@@ -1577,7 +1824,7 @@ async function generateRspackConfig({
1577
1824
  ProvidePlugin,
1578
1825
  HotModuleReplacementPlugin
1579
1826
  } = import_core2.rspack;
1580
- const chain = await (0, import_shared13.modifyBundlerChain)(context, {
1827
+ const chain = await modifyBundlerChain(context, {
1581
1828
  ...chainUtils,
1582
1829
  bundler: {
1583
1830
  BannerPlugin,
@@ -1587,7 +1834,7 @@ async function generateRspackConfig({
1587
1834
  HotModuleReplacementPlugin
1588
1835
  }
1589
1836
  });
1590
- let rspackConfig = (0, import_shared13.chainToConfig)(chain);
1837
+ let rspackConfig = chainToConfig(chain);
1591
1838
  rspackConfig = await modifyRspackConfig(
1592
1839
  context,
1593
1840
  rspackConfig,
@@ -1601,19 +1848,21 @@ var init_rspackConfig = __esm({
1601
1848
  "use strict";
1602
1849
  import_shared13 = require("@rsbuild/shared");
1603
1850
  import_core2 = require("@rspack/core");
1851
+ init_configChain();
1852
+ init_logger();
1604
1853
  init_pluginHelper();
1605
1854
  }
1606
1855
  });
1607
1856
 
1608
1857
  // src/provider/initConfigs.ts
1609
1858
  async function modifyRsbuildConfig(context) {
1610
- (0, import_shared14.debug)("modify Rsbuild config");
1859
+ import_rslog.logger.debug("modify Rsbuild config");
1611
1860
  const [modified] = await context.hooks.modifyRsbuildConfig.call(
1612
1861
  context.config,
1613
1862
  { mergeRsbuildConfig }
1614
1863
  );
1615
1864
  context.config = modified;
1616
- (0, import_shared14.debug)("modify Rsbuild config done");
1865
+ import_rslog.logger.debug("modify Rsbuild config done");
1617
1866
  }
1618
1867
  async function initRsbuildConfig({
1619
1868
  context,
@@ -1641,7 +1890,7 @@ async function initConfigs({
1641
1890
  const rspackConfigs = await Promise.all(
1642
1891
  targets.map((target) => generateRspackConfig({ target, context }))
1643
1892
  );
1644
- if ((0, import_shared14.isDebug)()) {
1893
+ if (isDebug()) {
1645
1894
  const inspect = () => {
1646
1895
  const inspectOptions = {
1647
1896
  verbose: true,
@@ -1662,13 +1911,12 @@ async function initConfigs({
1662
1911
  rspackConfigs
1663
1912
  };
1664
1913
  }
1665
- var import_shared14;
1666
1914
  var init_initConfigs = __esm({
1667
1915
  "src/provider/initConfigs.ts"() {
1668
1916
  "use strict";
1669
- import_shared14 = require("@rsbuild/shared");
1670
1917
  init_config();
1671
1918
  init_createContext();
1919
+ init_logger();
1672
1920
  init_mergeConfig();
1673
1921
  init_pluginManager();
1674
1922
  init_inspectConfig();
@@ -1680,6 +1928,8 @@ var init_initConfigs = __esm({
1680
1928
  var devMiddleware_exports = {};
1681
1929
  __export(devMiddleware_exports, {
1682
1930
  getDevMiddleware: () => getDevMiddleware,
1931
+ isClientCompiler: () => isClientCompiler,
1932
+ isNodeCompiler: () => isNodeCompiler,
1683
1933
  setupServerHooks: () => setupServerHooks
1684
1934
  });
1685
1935
  function applyHMREntry({
@@ -1688,7 +1938,7 @@ function applyHMREntry({
1688
1938
  clientConfig = {},
1689
1939
  liveReload = true
1690
1940
  }) {
1691
- if (!(0, import_shared15.isClientCompiler)(compiler)) {
1941
+ if (!isClientCompiler(compiler)) {
1692
1942
  return;
1693
1943
  }
1694
1944
  new compiler.webpack.DefinePlugin({
@@ -1701,13 +1951,27 @@ function applyHMREntry({
1701
1951
  }).apply(compiler);
1702
1952
  }
1703
1953
  }
1704
- var import_shared15, setupServerHooks, getDevMiddleware;
1954
+ var isClientCompiler, isNodeCompiler, setupServerHooks, getDevMiddleware;
1705
1955
  var init_devMiddleware = __esm({
1706
1956
  "src/server/devMiddleware.ts"() {
1707
1957
  "use strict";
1708
- import_shared15 = require("@rsbuild/shared");
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
+ };
1709
1973
  setupServerHooks = (compiler, hookCallbacks) => {
1710
- if ((0, import_shared15.isNodeCompiler)(compiler)) {
1974
+ if (isNodeCompiler(compiler)) {
1711
1975
  return;
1712
1976
  }
1713
1977
  const { compile, invalid, done } = compiler.hooks;
@@ -1730,7 +1994,7 @@ var init_devMiddleware = __esm({
1730
1994
  }
1731
1995
  setupServerHooks(compiler, callbacks);
1732
1996
  };
1733
- (0, import_shared15.applyToCompiler)(multiCompiler, setupCompiler);
1997
+ applyToCompiler(multiCompiler, setupCompiler);
1734
1998
  return webpackDevMiddleware(multiCompiler, restOptions);
1735
1999
  };
1736
2000
  };
@@ -1747,13 +2011,13 @@ async function createCompiler({
1747
2011
  context,
1748
2012
  rspackConfigs
1749
2013
  }) {
1750
- (0, import_shared16.debug)("create compiler");
2014
+ import_rslog.logger.debug("create compiler");
1751
2015
  await context.hooks.onBeforeCreateCompiler.call({
1752
2016
  bundlerConfigs: rspackConfigs
1753
2017
  });
1754
2018
  if (!await isSatisfyRspackVersion(import_core3.rspack.rspackVersion)) {
1755
2019
  throw new Error(
1756
- `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared16.color.green(
2020
+ `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared14.color.green(
1757
2021
  rspackMinVersion
1758
2022
  )}`
1759
2023
  );
@@ -1764,18 +2028,18 @@ async function createCompiler({
1764
2028
  let isCompiling = false;
1765
2029
  const logRspackVersion = () => {
1766
2030
  if (!isVersionLogged) {
1767
- (0, import_shared16.debug)(`Use Rspack v${import_core3.rspack.rspackVersion}`);
2031
+ import_rslog.logger.debug(`Use Rspack v${import_core3.rspack.rspackVersion}`);
1768
2032
  isVersionLogged = true;
1769
2033
  }
1770
2034
  };
1771
2035
  compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
1772
2036
  logRspackVersion();
1773
2037
  if (!isCompiling) {
1774
- import_shared16.logger.start("Compiling...");
2038
+ import_rslog.logger.start("Compiling...");
1775
2039
  }
1776
2040
  isCompiling = true;
1777
2041
  });
1778
- if ((0, import_shared16.isProd)()) {
2042
+ if ((0, import_shared14.isProd)()) {
1779
2043
  compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
1780
2044
  }
1781
2045
  const done = async (stats) => {
@@ -1785,10 +2049,10 @@ async function createCompiler({
1785
2049
  });
1786
2050
  const printTime = (c, index) => {
1787
2051
  if (c.time) {
1788
- const time = (0, import_shared16.prettyTime)(c.time / 1e3);
2052
+ const time = (0, import_shared14.prettyTime)(c.time / 1e3);
1789
2053
  const target = context.targets[index];
1790
- const name = import_shared16.TARGET_ID_MAP[target || "web"];
1791
- import_shared16.logger.ready(`${name} compiled in ${time}`);
2054
+ const name = TARGET_ID_MAP[target || "web"];
2055
+ import_rslog.logger.ready(`${name} compiled in ${time}`);
1792
2056
  }
1793
2057
  };
1794
2058
  if (!stats.hasErrors()) {
@@ -1802,12 +2066,12 @@ async function createCompiler({
1802
2066
  }
1803
2067
  const { message, level } = formatStats(stats, getStatsOptions(compiler));
1804
2068
  if (level === "error") {
1805
- import_shared16.logger.error(message);
2069
+ import_rslog.logger.error(message);
1806
2070
  }
1807
2071
  if (level === "warning") {
1808
- import_shared16.logger.warn(message);
2072
+ import_rslog.logger.warn(message);
1809
2073
  }
1810
- if ((0, import_shared16.isDev)()) {
2074
+ if ((0, import_shared14.isDev)()) {
1811
2075
  await context.hooks.onDevCompileDone.call({
1812
2076
  isFirstCompile,
1813
2077
  stats
@@ -1816,14 +2080,14 @@ async function createCompiler({
1816
2080
  isCompiling = false;
1817
2081
  isFirstCompile = false;
1818
2082
  };
1819
- (0, import_shared16.onCompileDone)(
2083
+ onCompileDone(
1820
2084
  compiler,
1821
2085
  done,
1822
2086
  // @ts-expect-error type mismatch
1823
2087
  import_core3.rspack.MultiStats
1824
2088
  );
1825
2089
  await context.hooks.onAfterCreateCompiler.call({ compiler });
1826
- (0, import_shared16.debug)("create compiler done");
2090
+ import_rslog.logger.debug("create compiler done");
1827
2091
  return compiler;
1828
2092
  }
1829
2093
  async function createDevMiddleware(options, customCompiler) {
@@ -1843,25 +2107,28 @@ async function createDevMiddleware(options, customCompiler) {
1843
2107
  compiler
1844
2108
  };
1845
2109
  }
1846
- var import_shared16, import_core3;
2110
+ var import_shared14, import_core3;
1847
2111
  var init_createCompiler = __esm({
1848
2112
  "src/provider/createCompiler.ts"() {
1849
2113
  "use strict";
1850
- import_shared16 = require("@rsbuild/shared");
2114
+ import_shared14 = require("@rsbuild/shared");
1851
2115
  import_core3 = require("@rspack/core");
2116
+ init_constants();
1852
2117
  init_helpers();
2118
+ init_logger();
1853
2119
  init_initConfigs();
1854
2120
  }
1855
2121
  });
1856
2122
 
1857
2123
  // src/server/middlewares.ts
1858
- var import_node_path9, import_node_url, import_shared17, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
2124
+ var import_node_path9, import_node_url, import_shared15, faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
1859
2125
  var init_middlewares = __esm({
1860
2126
  "src/server/middlewares.ts"() {
1861
2127
  "use strict";
1862
2128
  import_node_path9 = __toESM(require("path"));
1863
2129
  import_node_url = require("url");
1864
- import_shared17 = require("@rsbuild/shared");
2130
+ import_shared15 = require("@rsbuild/shared");
2131
+ init_logger();
1865
2132
  faviconFallbackMiddleware = (req, res, next) => {
1866
2133
  if (req.url === "/favicon.ico") {
1867
2134
  res.statusCode = 204;
@@ -1872,16 +2139,16 @@ var init_middlewares = __esm({
1872
2139
  };
1873
2140
  getStatusCodeColor = (status) => {
1874
2141
  if (status >= 500) {
1875
- return import_shared17.color.red;
2142
+ return import_shared15.color.red;
1876
2143
  }
1877
2144
  if (status >= 400) {
1878
- return import_shared17.color.yellow;
2145
+ return import_shared15.color.yellow;
1879
2146
  }
1880
2147
  if (status >= 300) {
1881
- return import_shared17.color.cyan;
2148
+ return import_shared15.color.cyan;
1882
2149
  }
1883
2150
  if (status >= 200) {
1884
- return import_shared17.color.green;
2151
+ return import_shared15.color.green;
1885
2152
  }
1886
2153
  return (res) => res;
1887
2154
  };
@@ -1896,8 +2163,8 @@ var init_middlewares = __esm({
1896
2163
  const statusColor = getStatusCodeColor(status);
1897
2164
  const endAt = process.hrtime();
1898
2165
  const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
1899
- (0, import_shared17.debug)(
1900
- `${statusColor(status)} ${method} ${import_shared17.color.gray(url2)} ${import_shared17.color.gray(
2166
+ import_rslog.logger.debug(
2167
+ `${statusColor(status)} ${method} ${import_shared15.color.gray(url2)} ${import_shared15.color.gray(
1901
2168
  `${totalTime.toFixed(3)} ms`
1902
2169
  )}`
1903
2170
  );
@@ -1926,8 +2193,8 @@ var init_middlewares = __esm({
1926
2193
  try {
1927
2194
  pathname = (0, import_node_url.parse)(url2, false, true).pathname;
1928
2195
  } catch (err) {
1929
- import_shared17.logger.error(
1930
- new Error(`Invalid URL: ${import_shared17.color.yellow(url2)}`, { cause: err })
2196
+ import_rslog.logger.error(
2197
+ new Error(`Invalid URL: ${import_shared15.color.yellow(url2)}`, { cause: err })
1931
2198
  );
1932
2199
  return next();
1933
2200
  }
@@ -1939,10 +2206,10 @@ var init_middlewares = __esm({
1939
2206
  });
1940
2207
  };
1941
2208
  const rewrite = (newUrl, isFallback = false) => {
1942
- if (isFallback && (0, import_shared17.isDebug)()) {
1943
- (0, import_shared17.debug)(
1944
- `${req.method} ${import_shared17.color.gray(
1945
- `${req.url} ${import_shared17.color.yellow("fallback")} to ${newUrl}`
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}`
1946
2213
  )}`
1947
2214
  );
1948
2215
  }
@@ -2008,18 +2275,18 @@ function formatProxyOptions(proxyOptions) {
2008
2275
  ret.push(opts);
2009
2276
  }
2010
2277
  }
2011
- const handleError = (err) => import_shared18.logger.error(err);
2278
+ const handleError = (err) => import_rslog.logger.error(err);
2012
2279
  for (const opts of ret) {
2013
2280
  opts.onError ??= handleError;
2014
2281
  }
2015
2282
  return ret;
2016
2283
  }
2017
- var import_shared18, import_http_proxy_middleware, createProxyMiddleware;
2284
+ var import_http_proxy_middleware, createProxyMiddleware;
2018
2285
  var init_proxy = __esm({
2019
2286
  "src/server/proxy.ts"() {
2020
2287
  "use strict";
2021
- import_shared18 = require("@rsbuild/shared");
2022
2288
  import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
2289
+ init_logger();
2023
2290
  createProxyMiddleware = (proxyOptions) => {
2024
2291
  const formattedOptionsList = formatProxyOptions(proxyOptions);
2025
2292
  const proxyMiddlewares = [];
@@ -2059,14 +2326,14 @@ var init_proxy = __esm({
2059
2326
  });
2060
2327
 
2061
2328
  // src/server/getDevMiddlewares.ts
2062
- var import_node_path10, import_node_url2, import_shared19, applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
2329
+ var import_node_path10, import_node_url2, applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
2063
2330
  var init_getDevMiddlewares = __esm({
2064
2331
  "src/server/getDevMiddlewares.ts"() {
2065
2332
  "use strict";
2066
2333
  import_node_path10 = require("path");
2067
2334
  import_node_url2 = __toESM(require("url"));
2068
- import_shared19 = require("@rsbuild/shared");
2069
2335
  init_config();
2336
+ init_logger();
2070
2337
  init_middlewares();
2071
2338
  applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
2072
2339
  const setupMiddlewares = dev.setupMiddlewares || [];
@@ -2184,7 +2451,7 @@ var init_getDevMiddlewares = __esm({
2184
2451
  getMiddlewares = async (options) => {
2185
2452
  const middlewares = [];
2186
2453
  const { compileMiddlewareAPI } = options;
2187
- if ((0, import_shared19.isDebug)()) {
2454
+ if (import_rslog.logger.level === "verbose") {
2188
2455
  middlewares.push(await getRequestLoggerMiddleware());
2189
2456
  }
2190
2457
  const { before, after } = applySetupMiddlewares(
@@ -2212,8 +2479,8 @@ var init_getDevMiddlewares = __esm({
2212
2479
  function getURLMessages(urls, routes) {
2213
2480
  if (routes.length === 1) {
2214
2481
  return urls.map(
2215
- ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared20.color.cyan(
2216
- (0, import_shared20.normalizeUrl)(`${url2}${routes[0].pathname}`)
2482
+ ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${import_shared16.color.cyan(
2483
+ normalizeUrl(`${url2}${routes[0].pathname}`)
2217
2484
  )}
2218
2485
  `
2219
2486
  ).join("");
@@ -2227,9 +2494,9 @@ function getURLMessages(urls, routes) {
2227
2494
  message += ` ${`> ${label}`}
2228
2495
  `;
2229
2496
  for (const r of routes) {
2230
- message += ` ${import_shared20.color.dim("-")} ${import_shared20.color.dim(
2497
+ message += ` ${import_shared16.color.dim("-")} ${import_shared16.color.dim(
2231
2498
  r.entryName.padEnd(maxNameLength + 4)
2232
- )}${import_shared20.color.cyan((0, import_shared20.normalizeUrl)(`${url2}${r.pathname}`))}
2499
+ )}${import_shared16.color.cyan(normalizeUrl(`${url2}${r.pathname}`))}
2233
2500
  `;
2234
2501
  }
2235
2502
  });
@@ -2246,7 +2513,7 @@ function printServerURLs({
2246
2513
  return;
2247
2514
  }
2248
2515
  let urls = originalUrls;
2249
- if ((0, import_shared20.isFunction)(printUrls)) {
2516
+ if ((0, import_shared16.isFunction)(printUrls)) {
2250
2517
  const newUrls = printUrls({
2251
2518
  urls: urls.map((item) => item.url),
2252
2519
  port,
@@ -2270,17 +2537,19 @@ function printServerURLs({
2270
2537
  return;
2271
2538
  }
2272
2539
  const message = getURLMessages(urls, routes);
2273
- import_shared20.logger.log(message);
2540
+ import_rslog.logger.log(message);
2274
2541
  return message;
2275
2542
  }
2276
- var import_node_net, import_node_os, import_shared20, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
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;
2277
2544
  var init_helper = __esm({
2278
2545
  "src/server/helper.ts"() {
2279
2546
  "use strict";
2280
2547
  import_node_net = __toESM(require("net"));
2281
2548
  import_node_os = __toESM(require("os"));
2282
- import_shared20 = require("@rsbuild/shared");
2549
+ import_shared16 = require("@rsbuild/shared");
2283
2550
  init_constants();
2551
+ init_logger();
2552
+ normalizeUrl = (url2) => url2.replace(/([^:]\/)\/+/g, "$1");
2284
2553
  formatPrefix = (prefix) => {
2285
2554
  if (!prefix) {
2286
2555
  return "/";
@@ -2343,8 +2612,8 @@ var init_helper = __esm({
2343
2612
  );
2344
2613
  }
2345
2614
  if (!silent) {
2346
- import_shared20.logger.info(
2347
- `Port ${original} is in use, ${import_shared20.color.yellow(`using port ${port}.`)}
2615
+ import_rslog.logger.info(
2616
+ `Port ${original} is in use, ${import_shared16.color.yellow(`using port ${port}.`)}
2348
2617
  `
2349
2618
  );
2350
2619
  }
@@ -2381,7 +2650,7 @@ var init_helper = __esm({
2381
2650
  writeToDisk: false,
2382
2651
  liveReload: true
2383
2652
  };
2384
- const devConfig = config.dev ? (0, import_shared20.deepmerge)(defaultDevConfig, config.dev) : defaultDevConfig;
2653
+ const devConfig = config.dev ? (0, import_shared16.deepmerge)(defaultDevConfig, config.dev) : defaultDevConfig;
2385
2654
  return devConfig;
2386
2655
  };
2387
2656
  getIpv4Interfaces = () => {
@@ -2567,12 +2836,12 @@ var init_watchFiles = __esm({
2567
2836
  });
2568
2837
 
2569
2838
  // src/server/socketServer.ts
2570
- var import_shared21, SocketServer;
2839
+ var SocketServer;
2571
2840
  var init_socketServer = __esm({
2572
2841
  "src/server/socketServer.ts"() {
2573
2842
  "use strict";
2574
- import_shared21 = require("@rsbuild/shared");
2575
2843
  init_helpers();
2844
+ init_logger();
2576
2845
  SocketServer = class {
2577
2846
  constructor(options) {
2578
2847
  __publicField(this, "wsServer");
@@ -2598,7 +2867,7 @@ var init_socketServer = __esm({
2598
2867
  path: this.options.client?.path
2599
2868
  });
2600
2869
  this.wsServer.on("error", (err) => {
2601
- import_shared21.logger.error(err);
2870
+ import_rslog.logger.error(err);
2602
2871
  });
2603
2872
  this.timer = setInterval(() => {
2604
2873
  for (const socket of this.wsServer.clients) {
@@ -2819,10 +3088,10 @@ async function createDevServer(options, createDevMiddleware2, config, {
2819
3088
  getPortSilently,
2820
3089
  runCompile = true
2821
3090
  } = {}) {
2822
- if (!(0, import_shared22.getNodeEnv)()) {
2823
- (0, import_shared22.setNodeEnv)("development");
3091
+ if (!(0, import_shared17.getNodeEnv)()) {
3092
+ (0, import_shared17.setNodeEnv)("development");
2824
3093
  }
2825
- (0, import_shared22.debug)("create dev server");
3094
+ import_rslog.logger.debug("create dev server");
2826
3095
  const serverConfig = config.server;
2827
3096
  const { port, host, https } = await getServerConfig({
2828
3097
  config,
@@ -2849,7 +3118,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2849
3118
  customCompiler
2850
3119
  );
2851
3120
  const { CompilerDevMiddleware: CompilerDevMiddleware2 } = await Promise.resolve().then(() => (init_compilerDevMiddleware(), compilerDevMiddleware_exports));
2852
- const publicPaths = (0, import_shared22.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared22.getPublicPathFromCompiler) : [(0, import_shared22.getPublicPathFromCompiler)(compiler)];
3121
+ const publicPaths = isMultiCompiler(compiler) ? compiler.compilers.map(import_shared17.getPublicPathFromCompiler) : [(0, import_shared17.getPublicPathFromCompiler)(compiler)];
2853
3122
  const compilerDevMiddleware = new CompilerDevMiddleware2({
2854
3123
  dev: devConfig,
2855
3124
  server: serverConfig,
@@ -2857,7 +3126,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2857
3126
  devMiddleware
2858
3127
  });
2859
3128
  await compilerDevMiddleware.init();
2860
- outputFileSystem = ((0, import_shared22.isMultiCompiler)(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || import_node_fs3.default;
3129
+ outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || import_node_fs3.default;
2861
3130
  return {
2862
3131
  middleware: compilerDevMiddleware.middleware,
2863
3132
  sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
@@ -2921,7 +3190,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2921
3190
  serverConfig,
2922
3191
  middlewares
2923
3192
  });
2924
- (0, import_shared22.debug)("listen dev server");
3193
+ import_rslog.logger.debug("listen dev server");
2925
3194
  return new Promise((resolve) => {
2926
3195
  httpServer.listen(
2927
3196
  {
@@ -2934,7 +3203,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2934
3203
  }
2935
3204
  middlewares.use(notFoundMiddleware);
2936
3205
  httpServer.on("upgrade", devMiddlewares.onUpgrade);
2937
- (0, import_shared22.debug)("listen dev server done");
3206
+ import_rslog.logger.debug("listen dev server done");
2938
3207
  await server.afterListen();
2939
3208
  const closeServer = async () => {
2940
3209
  await server.close();
@@ -2965,16 +3234,18 @@ async function createDevServer(options, createDevMiddleware2, config, {
2965
3234
  await fileWatcher?.close();
2966
3235
  }
2967
3236
  };
2968
- (0, import_shared22.debug)("create dev server done");
3237
+ import_rslog.logger.debug("create dev server done");
2969
3238
  return server;
2970
3239
  }
2971
- var import_node_fs3, import_shared22;
3240
+ var import_node_fs3, import_shared17;
2972
3241
  var init_devServer = __esm({
2973
3242
  "src/server/devServer.ts"() {
2974
3243
  "use strict";
2975
3244
  import_node_fs3 = __toESM(require("fs"));
2976
- import_shared22 = require("@rsbuild/shared");
3245
+ import_shared17 = require("@rsbuild/shared");
2977
3246
  init_constants();
3247
+ init_helpers();
3248
+ init_logger();
2978
3249
  init_getDevMiddlewares();
2979
3250
  init_helper();
2980
3251
  init_httpServer();
@@ -2984,230 +3255,60 @@ var init_devServer = __esm({
2984
3255
  }
2985
3256
  });
2986
3257
 
2987
- // src/server/prodServer.ts
2988
- var prodServer_exports = {};
2989
- __export(prodServer_exports, {
2990
- RsbuildProdServer: () => RsbuildProdServer,
2991
- startProdServer: () => startProdServer
3258
+ // src/provider/build.ts
3259
+ var build_exports = {};
3260
+ __export(build_exports, {
3261
+ build: () => build
2992
3262
  });
2993
- async function startProdServer(context, config, { getPortSilently } = {}) {
2994
- if (!(0, import_shared23.getNodeEnv)()) {
2995
- (0, import_shared23.setNodeEnv)("production");
2996
- }
2997
- const { port, host, https } = await getServerConfig({
2998
- config,
2999
- getPortSilently
3000
- });
3001
- const { default: connect } = await import("../compiled/connect/index.js");
3002
- const middlewares = connect();
3003
- const serverConfig = config.server;
3004
- const server = new RsbuildProdServer(
3005
- {
3006
- pwd: context.rootPath,
3007
- output: {
3008
- path: config.output.distPath.root || ROOT_DIST_DIR,
3009
- assetPrefix: config.output.assetPrefix
3010
- },
3011
- serverConfig
3012
- },
3013
- middlewares
3014
- );
3015
- await context.hooks.onBeforeStartProdServer.call();
3016
- const httpServer = await createHttpServer({
3017
- serverConfig,
3018
- middlewares: server.middlewares
3019
- });
3020
- await server.onInit(httpServer);
3021
- return new Promise((resolve) => {
3022
- httpServer.listen(
3023
- {
3024
- host,
3025
- port
3026
- },
3027
- async () => {
3028
- const routes = formatRoutes(
3029
- context.entry,
3030
- config.output.distPath.html,
3031
- config.html.outputStructure
3032
- );
3033
- await context.hooks.onAfterStartProdServer.call({
3034
- port,
3035
- routes
3036
- });
3037
- const protocol = https ? "https" : "http";
3038
- const urls = getAddressUrls({ protocol, port, host });
3039
- printServerURLs({
3040
- urls,
3041
- port,
3042
- routes,
3043
- protocol,
3044
- printUrls: serverConfig.printUrls
3263
+ var import_shared18, import_core4, build;
3264
+ var init_build = __esm({
3265
+ "src/provider/build.ts"() {
3266
+ "use strict";
3267
+ import_shared18 = require("@rsbuild/shared");
3268
+ import_core4 = require("@rspack/core");
3269
+ init_helpers();
3270
+ init_logger();
3271
+ init_createCompiler();
3272
+ init_initConfigs();
3273
+ build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
3274
+ if (!(0, import_shared18.getNodeEnv)()) {
3275
+ (0, import_shared18.setNodeEnv)(mode);
3276
+ }
3277
+ const { context } = initOptions;
3278
+ let compiler;
3279
+ let bundlerConfigs;
3280
+ if (customCompiler) {
3281
+ compiler = customCompiler;
3282
+ } else {
3283
+ const { rspackConfigs } = await initConfigs(initOptions);
3284
+ compiler = await createCompiler({
3285
+ context,
3286
+ rspackConfigs
3045
3287
  });
3046
- const onClose = () => {
3047
- server.close();
3048
- httpServer.close();
3049
- };
3050
- resolve({
3051
- port,
3052
- urls: urls.map((item) => item.url),
3053
- server: {
3054
- close: async () => {
3055
- onClose();
3056
- }
3288
+ bundlerConfigs = rspackConfigs;
3289
+ }
3290
+ let isFirstCompile = true;
3291
+ await context.hooks.onBeforeBuild.call({
3292
+ bundlerConfigs
3293
+ });
3294
+ const onDone = async (stats) => {
3295
+ const p = context.hooks.onAfterBuild.call({ isFirstCompile, stats });
3296
+ isFirstCompile = false;
3297
+ await p;
3298
+ };
3299
+ onCompileDone(
3300
+ compiler,
3301
+ onDone,
3302
+ // @ts-expect-error type mismatch
3303
+ import_core4.rspack.MultiStats
3304
+ );
3305
+ if (watch) {
3306
+ compiler.watch({}, (err) => {
3307
+ if (err) {
3308
+ import_rslog.logger.error(err);
3057
3309
  }
3058
3310
  });
3059
- }
3060
- );
3061
- });
3062
- }
3063
- var import_node_path11, import_shared23, RsbuildProdServer;
3064
- var init_prodServer = __esm({
3065
- "src/server/prodServer.ts"() {
3066
- "use strict";
3067
- import_node_path11 = require("path");
3068
- import_shared23 = require("@rsbuild/shared");
3069
- init_constants();
3070
- init_helper();
3071
- init_httpServer();
3072
- init_middlewares();
3073
- RsbuildProdServer = class {
3074
- constructor(options, middlewares) {
3075
- __publicField(this, "app");
3076
- __publicField(this, "options");
3077
- __publicField(this, "middlewares");
3078
- this.options = options;
3079
- this.middlewares = middlewares;
3080
- }
3081
- // Complete the preparation of services
3082
- async onInit(app) {
3083
- this.app = app;
3084
- await this.applyDefaultMiddlewares();
3085
- }
3086
- async applyDefaultMiddlewares() {
3087
- const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
3088
- if ((0, import_shared23.isDebug)()) {
3089
- this.middlewares.use(await getRequestLoggerMiddleware());
3090
- }
3091
- if (compress) {
3092
- const { default: compression } = await import("../compiled/http-compression/index.js");
3093
- this.middlewares.use((req, res, next) => {
3094
- compression({
3095
- gzip: true,
3096
- brotli: false
3097
- })(req, res, next);
3098
- });
3099
- }
3100
- if (headers) {
3101
- this.middlewares.use((_req, res, next) => {
3102
- for (const [key, value] of Object.entries(headers)) {
3103
- res.setHeader(key, value);
3104
- }
3105
- next();
3106
- });
3107
- }
3108
- if (proxy) {
3109
- const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
3110
- const { middlewares, upgrade } = createProxyMiddleware2(proxy);
3111
- for (const middleware of middlewares) {
3112
- this.middlewares.use(middleware);
3113
- }
3114
- this.app.on("upgrade", upgrade);
3115
- }
3116
- this.applyStaticAssetMiddleware();
3117
- if (historyApiFallback) {
3118
- const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
3119
- const historyApiFallbackMiddleware = connectHistoryApiFallback(
3120
- historyApiFallback === true ? {} : historyApiFallback
3121
- );
3122
- this.middlewares.use(historyApiFallbackMiddleware);
3123
- await this.applyStaticAssetMiddleware();
3124
- }
3125
- this.middlewares.use(faviconFallbackMiddleware);
3126
- }
3127
- async applyStaticAssetMiddleware() {
3128
- const {
3129
- output: { path: path13, assetPrefix },
3130
- serverConfig: { htmlFallback },
3131
- pwd
3132
- } = this.options;
3133
- const { default: sirv } = await import("../compiled/sirv/index.js");
3134
- const assetMiddleware = sirv((0, import_node_path11.join)(pwd, path13), {
3135
- etag: true,
3136
- dev: true,
3137
- ignores: ["favicon.ico"],
3138
- single: htmlFallback === "index"
3139
- });
3140
- this.middlewares.use((req, res, next) => {
3141
- const url2 = req.url;
3142
- if (assetPrefix && url2?.startsWith(assetPrefix)) {
3143
- req.url = url2.slice(assetPrefix.length);
3144
- assetMiddleware(req, res, (...args) => {
3145
- req.url = url2;
3146
- next(...args);
3147
- });
3148
- } else {
3149
- assetMiddleware(req, res, next);
3150
- }
3151
- });
3152
- }
3153
- close() {
3154
- }
3155
- };
3156
- }
3157
- });
3158
-
3159
- // src/provider/build.ts
3160
- var build_exports = {};
3161
- __export(build_exports, {
3162
- build: () => build
3163
- });
3164
- var import_shared24, import_core4, build;
3165
- var init_build = __esm({
3166
- "src/provider/build.ts"() {
3167
- "use strict";
3168
- import_shared24 = require("@rsbuild/shared");
3169
- import_core4 = require("@rspack/core");
3170
- init_createCompiler();
3171
- init_initConfigs();
3172
- build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
3173
- if (!(0, import_shared24.getNodeEnv)()) {
3174
- (0, import_shared24.setNodeEnv)(mode);
3175
- }
3176
- const { context } = initOptions;
3177
- let compiler;
3178
- let bundlerConfigs;
3179
- if (customCompiler) {
3180
- compiler = customCompiler;
3181
- } else {
3182
- const { rspackConfigs } = await initConfigs(initOptions);
3183
- compiler = await createCompiler({
3184
- context,
3185
- rspackConfigs
3186
- });
3187
- bundlerConfigs = rspackConfigs;
3188
- }
3189
- let isFirstCompile = true;
3190
- await context.hooks.onBeforeBuild.call({
3191
- bundlerConfigs
3192
- });
3193
- const onDone = async (stats) => {
3194
- const p = context.hooks.onAfterBuild.call({ isFirstCompile, stats });
3195
- isFirstCompile = false;
3196
- await p;
3197
- };
3198
- (0, import_shared24.onCompileDone)(
3199
- compiler,
3200
- onDone,
3201
- // @ts-expect-error type mismatch
3202
- import_core4.rspack.MultiStats
3203
- );
3204
- if (watch) {
3205
- compiler.watch({}, (err) => {
3206
- if (err) {
3207
- import_shared24.logger.error(err);
3208
- }
3209
- });
3210
- return;
3311
+ return;
3211
3312
  }
3212
3313
  await new Promise((resolve, reject) => {
3213
3314
  compiler.run((err, stats) => {
@@ -3217,7 +3318,7 @@ var init_build = __esm({
3217
3318
  } else {
3218
3319
  compiler.close((closeErr) => {
3219
3320
  if (closeErr) {
3220
- import_shared24.logger.error(closeErr);
3321
+ import_rslog.logger.error(closeErr);
3221
3322
  }
3222
3323
  resolve({ stats });
3223
3324
  });
@@ -3281,11 +3382,6 @@ var init_provider = __esm({
3281
3382
  );
3282
3383
  return server.listen();
3283
3384
  },
3284
- async preview(options) {
3285
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
3286
- const config = await initRsbuildConfig({ context, pluginManager });
3287
- return startProdServer2(context, config, options);
3288
- },
3289
3385
  async build(options) {
3290
3386
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
3291
3387
  return build2({ context, pluginManager, rsbuildOptions }, options);
@@ -3317,22 +3413,30 @@ var basic_exports = {};
3317
3413
  __export(basic_exports, {
3318
3414
  pluginBasic: () => pluginBasic
3319
3415
  });
3320
- var import_node_path12, import_shared25, pluginBasic;
3416
+ var import_node_path11, import_shared19, getJsSourceMap, pluginBasic;
3321
3417
  var init_basic = __esm({
3322
3418
  "src/plugins/basic.ts"() {
3323
3419
  "use strict";
3324
- import_node_path12 = __toESM(require("path"));
3325
- import_shared25 = require("@rsbuild/shared");
3420
+ import_node_path11 = __toESM(require("path"));
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
+ };
3326
3430
  pluginBasic = () => ({
3327
3431
  name: "rsbuild:basic",
3328
3432
  setup(api) {
3329
3433
  api.modifyBundlerChain(
3330
- (chain, { env, isProd: isProd6, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3434
+ (chain, { env, isProd: isProd7, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3331
3435
  const config = api.getNormalizedConfig();
3332
- chain.name(import_shared25.TARGET_ID_MAP[target]);
3333
- chain.devtool((0, import_shared25.getJsSourceMap)(config));
3436
+ chain.name(TARGET_ID_MAP[target]);
3437
+ chain.devtool(getJsSourceMap(config));
3334
3438
  chain.context(api.context.rootPath);
3335
- chain.mode(isProd6 ? "production" : "development");
3439
+ chain.mode(isProd7 ? "production" : "development");
3336
3440
  chain.merge({
3337
3441
  infrastructureLogging: {
3338
3442
  // Using `error` level to avoid `cache.PackFileCacheStrategy` logs
@@ -3345,15 +3449,15 @@ var init_basic = __esm({
3345
3449
  exportsPresence: "error"
3346
3450
  }
3347
3451
  });
3348
- const isMinimize = isProd6 && config.output.minify !== false;
3452
+ const isMinimize = isProd7 && config.output.minify !== false;
3349
3453
  chain.optimization.minimize(isMinimize);
3350
- const usingHMR = (0, import_shared25.isUsingHMR)(config, { target, isProd: isProd6 });
3454
+ const usingHMR = (0, import_shared19.isUsingHMR)(config, { target, isProd: isProd7 });
3351
3455
  if (usingHMR) {
3352
3456
  chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
3353
3457
  }
3354
3458
  if (env === "development") {
3355
3459
  chain.output.devtoolModuleFilenameTemplate(
3356
- (info) => import_node_path12.default.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
3460
+ (info) => import_node_path11.default.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
3357
3461
  );
3358
3462
  }
3359
3463
  process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
@@ -3371,15 +3475,15 @@ __export(cache_exports, {
3371
3475
  pluginCache: () => pluginCache
3372
3476
  });
3373
3477
  async function validateCache(cacheDirectory, buildDependencies) {
3374
- const configFile = (0, import_node_path13.join)(cacheDirectory, "buildDependencies.json");
3478
+ const configFile = (0, import_node_path12.join)(cacheDirectory, "buildDependencies.json");
3375
3479
  if (await isFileExists(configFile)) {
3376
- const prevBuildDependencies = await import_shared26.fse.readJSON(configFile);
3480
+ const prevBuildDependencies = await import_shared20.fse.readJSON(configFile);
3377
3481
  if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
3378
3482
  return;
3379
3483
  }
3380
- await import_shared26.fse.remove(cacheDirectory);
3484
+ await import_shared20.fse.remove(cacheDirectory);
3381
3485
  }
3382
- await import_shared26.fse.outputJSON(configFile, buildDependencies);
3486
+ await import_shared20.fse.outputJSON(configFile, buildDependencies);
3383
3487
  }
3384
3488
  function getDigestHash(digest) {
3385
3489
  const fsHash = import_node_crypto.default.createHash("md5");
@@ -3388,13 +3492,13 @@ function getDigestHash(digest) {
3388
3492
  }
3389
3493
  function getCacheDirectory({ cacheDirectory }, context) {
3390
3494
  if (cacheDirectory) {
3391
- return (0, import_node_path13.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, import_node_path13.join)(context.rootPath, cacheDirectory);
3495
+ return (0, import_node_path12.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, import_node_path12.join)(context.rootPath, cacheDirectory);
3392
3496
  }
3393
- return (0, import_node_path13.join)(context.cachePath, context.bundlerType);
3497
+ return (0, import_node_path12.join)(context.cachePath, context.bundlerType);
3394
3498
  }
3395
3499
  async function getBuildDependencies(context, config) {
3396
- const rootPackageJson = (0, import_node_path13.join)(context.rootPath, "package.json");
3397
- const browserslistConfig = (0, import_node_path13.join)(context.rootPath, ".browserslistrc");
3500
+ const rootPackageJson = (0, import_node_path12.join)(context.rootPath, "package.json");
3501
+ const browserslistConfig = (0, import_node_path12.join)(context.rootPath, ".browserslistrc");
3398
3502
  const buildDependencies = {};
3399
3503
  if (await isFileExists(rootPackageJson)) {
3400
3504
  buildDependencies.packageJson = [rootPackageJson];
@@ -3410,7 +3514,7 @@ async function getBuildDependencies(context, config) {
3410
3514
  }
3411
3515
  const tailwindExts = ["ts", "js", "cjs", "mjs"];
3412
3516
  const configs = tailwindExts.map(
3413
- (ext) => (0, import_node_path13.join)(context.rootPath, `tailwind.config.${ext}`)
3517
+ (ext) => (0, import_node_path12.join)(context.rootPath, `tailwind.config.${ext}`)
3414
3518
  );
3415
3519
  const tailwindConfig = findExists(configs);
3416
3520
  if (tailwindConfig) {
@@ -3418,13 +3522,13 @@ async function getBuildDependencies(context, config) {
3418
3522
  }
3419
3523
  return buildDependencies;
3420
3524
  }
3421
- var import_node_crypto, import_node_path13, import_shared26, pluginCache;
3525
+ var import_node_crypto, import_node_path12, import_shared20, pluginCache;
3422
3526
  var init_cache = __esm({
3423
3527
  "src/plugins/cache.ts"() {
3424
3528
  "use strict";
3425
3529
  import_node_crypto = __toESM(require("crypto"));
3426
- import_node_path13 = require("path");
3427
- import_shared26 = require("@rsbuild/shared");
3530
+ import_node_path12 = require("path");
3531
+ import_shared20 = require("@rsbuild/shared");
3428
3532
  init_helpers();
3429
3533
  pluginCache = () => ({
3430
3534
  name: "rsbuild:cache",
@@ -3464,11 +3568,11 @@ var target_exports = {};
3464
3568
  __export(target_exports, {
3465
3569
  pluginTarget: () => pluginTarget
3466
3570
  });
3467
- var import_shared27, pluginTarget;
3571
+ var import_shared21, pluginTarget;
3468
3572
  var init_target = __esm({
3469
3573
  "src/plugins/target.ts"() {
3470
3574
  "use strict";
3471
- import_shared27 = require("@rsbuild/shared");
3575
+ import_shared21 = require("@rsbuild/shared");
3472
3576
  pluginTarget = () => ({
3473
3577
  name: "rsbuild:target",
3474
3578
  setup(api) {
@@ -3480,12 +3584,12 @@ var init_target = __esm({
3480
3584
  return;
3481
3585
  }
3482
3586
  const config = api.getNormalizedConfig();
3483
- const browserslist = await (0, import_shared27.getBrowserslistWithDefault)(
3587
+ const browserslist = await (0, import_shared21.getBrowserslistWithDefault)(
3484
3588
  api.context.rootPath,
3485
3589
  config,
3486
3590
  target
3487
3591
  );
3488
- const esVersion = (0, import_shared27.browserslistToESVersion)(browserslist);
3592
+ const esVersion = (0, import_shared21.browserslistToESVersion)(browserslist);
3489
3593
  if (target === "web-worker" || target === "service-worker") {
3490
3594
  chain.target(["webworker", `es${esVersion}`]);
3491
3595
  return;
@@ -3529,16 +3633,16 @@ async function applyCSSRule({
3529
3633
  rule,
3530
3634
  config,
3531
3635
  context,
3532
- utils: { target, isProd: isProd6, CHAIN_ID: CHAIN_ID3 },
3636
+ utils: { target, isProd: isProd7, CHAIN_ID: CHAIN_ID3 },
3533
3637
  importLoaders = 1
3534
3638
  }) {
3535
- const browserslist = await (0, import_shared28.getBrowserslistWithDefault)(
3639
+ const browserslist = await (0, import_shared22.getBrowserslistWithDefault)(
3536
3640
  context.rootPath,
3537
3641
  config,
3538
3642
  target
3539
3643
  );
3540
3644
  const enableExtractCSS = isUseCssExtract(config, target);
3541
- const localIdentName = getCSSModulesLocalIdentName(config, isProd6);
3645
+ const localIdentName = getCSSModulesLocalIdentName(config, isProd7);
3542
3646
  const cssLoaderOptions = getCSSLoaderOptions({
3543
3647
  config,
3544
3648
  importLoaders,
@@ -3549,14 +3653,14 @@ async function applyCSSRule({
3549
3653
  if (enableExtractCSS) {
3550
3654
  rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
3551
3655
  } else {
3552
- const styleLoaderOptions = (0, import_shared28.reduceConfigs)({
3656
+ const styleLoaderOptions = (0, import_shared22.reduceConfigs)({
3553
3657
  initial: {},
3554
3658
  config: config.tools.styleLoader
3555
3659
  });
3556
3660
  rule.use(CHAIN_ID3.USE.STYLE).loader(getCompiledPath("style-loader")).options(styleLoaderOptions).end();
3557
3661
  }
3558
3662
  } else {
3559
- rule.use(CHAIN_ID3.USE.IGNORE_CSS).loader(import_node_path14.default.join(LOADER_PATH, "ignoreCssLoader.cjs")).end();
3663
+ rule.use(CHAIN_ID3.USE.IGNORE_CSS).loader(import_node_path13.default.join(LOADER_PATH, "ignoreCssLoader.cjs")).end();
3560
3664
  }
3561
3665
  rule.use(CHAIN_ID3.USE.CSS).loader(getCompiledPath("css-loader")).options(cssLoaderOptions).end();
3562
3666
  if (target === "web") {
@@ -3570,19 +3674,19 @@ async function applyCSSRule({
3570
3674
  rule.merge({ sideEffects: true });
3571
3675
  rule.resolve.preferRelative(true);
3572
3676
  }
3573
- var import_node_path14, import_shared28, enableNativeCss, isUseCssExtract, getCSSModulesLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCSSLoaderOptions, pluginCss;
3677
+ var import_node_path13, import_shared22, enableNativeCss, isUseCssExtract, getCSSModulesLocalIdentName, normalizeCssLoaderOptions, userPostcssrcCache, applyAutoprefixer, getPostcssLoaderOptions, getCSSLoaderOptions, pluginCss;
3574
3678
  var init_css = __esm({
3575
3679
  "src/plugins/css.ts"() {
3576
3680
  "use strict";
3577
- import_node_path14 = __toESM(require("path"));
3578
- import_shared28 = require("@rsbuild/shared");
3681
+ import_node_path13 = __toESM(require("path"));
3682
+ import_shared22 = require("@rsbuild/shared");
3579
3683
  init_constants();
3580
3684
  init_helpers();
3581
3685
  init_pluginHelper();
3582
3686
  enableNativeCss = (config) => !config.output.injectStyles;
3583
3687
  isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
3584
- getCSSModulesLocalIdentName = (config, isProd6) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3585
- (isProd6 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
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]");
3586
3690
  normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
3587
3691
  if (options.modules && exportOnlyLocals) {
3588
3692
  let { modules } = options;
@@ -3609,17 +3713,17 @@ var init_css = __esm({
3609
3713
  userPostcssrcCache = /* @__PURE__ */ new Map();
3610
3714
  applyAutoprefixer = async (plugins, browserslist, config) => {
3611
3715
  const pluginObjects = plugins.map(
3612
- (plugin) => (0, import_shared28.isFunction)(plugin) ? plugin({}) : plugin
3716
+ (plugin) => (0, import_shared22.isFunction)(plugin) ? plugin({}) : plugin
3613
3717
  );
3614
3718
  const hasAutoprefixer = pluginObjects.some((pluginObject) => {
3615
- if ((0, import_shared28.isPlainObject)(pluginObject) && "postcssPlugin" in pluginObject) {
3719
+ if ((0, import_shared22.isPlainObject)(pluginObject) && "postcssPlugin" in pluginObject) {
3616
3720
  return pluginObject.postcssPlugin === "autoprefixer";
3617
3721
  }
3618
3722
  return false;
3619
3723
  });
3620
3724
  if (!hasAutoprefixer) {
3621
3725
  const { default: autoprefixer } = await import("@rsbuild/shared/autoprefixer");
3622
- const autoprefixerOptions = (0, import_shared28.reduceConfigs)({
3726
+ const autoprefixerOptions = (0, import_shared22.reduceConfigs)({
3623
3727
  initial: {
3624
3728
  flexbox: "no-2009",
3625
3729
  overrideBrowserslist: browserslist
@@ -3659,7 +3763,7 @@ var init_css = __esm({
3659
3763
  },
3660
3764
  sourceMap: config.output.sourceMap.css
3661
3765
  };
3662
- const mergedConfig = (0, import_shared28.reduceConfigsWithContext)({
3766
+ const mergedConfig = (0, import_shared22.reduceConfigsWithContext)({
3663
3767
  initial: defaultPostcssConfig,
3664
3768
  config: config.tools.postcss,
3665
3769
  ctx: utils
@@ -3686,10 +3790,10 @@ var init_css = __esm({
3686
3790
  },
3687
3791
  sourceMap: config.output.sourceMap.css
3688
3792
  };
3689
- const mergedCssLoaderOptions = (0, import_shared28.reduceConfigs)({
3793
+ const mergedCssLoaderOptions = (0, import_shared22.reduceConfigs)({
3690
3794
  initial: defaultOptions2,
3691
3795
  config: config.tools.cssLoader,
3692
- mergeFn: import_shared28.deepmerge
3796
+ mergeFn: import_shared22.deepmerge
3693
3797
  });
3694
3798
  const cssLoaderOptions = normalizeCssLoaderOptions(
3695
3799
  mergedCssLoaderOptions,
@@ -3729,13 +3833,13 @@ __export(output_exports, {
3729
3833
  pluginOutput: () => pluginOutput
3730
3834
  });
3731
3835
  function getPublicPath({
3732
- isProd: isProd6,
3836
+ isProd: isProd7,
3733
3837
  config,
3734
3838
  context
3735
3839
  }) {
3736
3840
  const { dev, output } = config;
3737
- let publicPath = import_shared29.DEFAULT_ASSET_PREFIX;
3738
- if (isProd6) {
3841
+ let publicPath = import_shared23.DEFAULT_ASSET_PREFIX;
3842
+ if (isProd7) {
3739
3843
  if (typeof output.assetPrefix === "string") {
3740
3844
  publicPath = output.assetPrefix;
3741
3845
  }
@@ -3754,12 +3858,12 @@ function getPublicPath({
3754
3858
  }
3755
3859
  return formatPublicPath(publicPath);
3756
3860
  }
3757
- var import_node_path15, import_shared29, import_core5, pluginOutput;
3861
+ var import_node_path14, import_shared23, import_core5, pluginOutput;
3758
3862
  var init_output = __esm({
3759
3863
  "src/plugins/output.ts"() {
3760
3864
  "use strict";
3761
- import_node_path15 = require("path");
3762
- import_shared29 = require("@rsbuild/shared");
3865
+ import_node_path14 = require("path");
3866
+ import_shared23 = require("@rsbuild/shared");
3763
3867
  import_core5 = require("@rspack/core");
3764
3868
  init_constants();
3765
3869
  init_helpers();
@@ -3769,38 +3873,38 @@ var init_output = __esm({
3769
3873
  name: "rsbuild:output",
3770
3874
  setup(api) {
3771
3875
  api.modifyBundlerChain(
3772
- async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd6, isServer, isServiceWorker }) => {
3876
+ async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd7, isServer, isServiceWorker }) => {
3773
3877
  const config = api.getNormalizedConfig();
3774
3878
  const publicPath = getPublicPath({
3775
3879
  config,
3776
- isProd: isProd6,
3880
+ isProd: isProd7,
3777
3881
  context: api.context
3778
3882
  });
3779
- const jsPath = (0, import_shared29.getDistPath)(config, "js");
3780
- const jsAsyncPath = (0, import_shared29.getDistPath)(config, "jsAsync");
3781
- const jsFilename = (0, import_shared29.getFilename)(config, "js", isProd6);
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);
3782
3886
  const isJsFilenameFn = typeof jsFilename === "function";
3783
3887
  chain.output.path(api.context.distPath).filename(
3784
3888
  isJsFilenameFn ? (...args) => {
3785
3889
  const name = jsFilename(...args);
3786
- return import_node_path15.posix.join(jsPath, name);
3787
- } : import_node_path15.posix.join(jsPath, jsFilename)
3890
+ return import_node_path14.posix.join(jsPath, name);
3891
+ } : import_node_path14.posix.join(jsPath, jsFilename)
3788
3892
  ).chunkFilename(
3789
3893
  isJsFilenameFn ? (...args) => {
3790
3894
  const name = jsFilename(...args);
3791
- return import_node_path15.posix.join(jsAsyncPath, name);
3792
- } : import_node_path15.posix.join(jsAsyncPath, jsFilename)
3895
+ return import_node_path14.posix.join(jsAsyncPath, name);
3896
+ } : import_node_path14.posix.join(jsAsyncPath, jsFilename)
3793
3897
  ).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3794
3898
  if (isServer) {
3795
- const serverPath = (0, import_shared29.getDistPath)(config, "server");
3796
- chain.output.path(import_node_path15.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3899
+ const serverPath = config.output.distPath.server;
3900
+ chain.output.path(import_node_path14.posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3797
3901
  ...chain.output.get("library") || {},
3798
3902
  type: "commonjs2"
3799
3903
  });
3800
3904
  }
3801
3905
  if (isServiceWorker) {
3802
- const workerPath = (0, import_shared29.getDistPath)(config, "worker");
3803
- const filename = import_node_path15.posix.join(workerPath, "[name].js");
3906
+ const workerPath = config.output.distPath.worker;
3907
+ const filename = import_node_path14.posix.join(workerPath, "[name].js");
3804
3908
  chain.output.filename(filename).chunkFilename(filename);
3805
3909
  }
3806
3910
  if (config.output.copy && api.context.bundlerType === "rspack") {
@@ -3810,13 +3914,13 @@ var init_output = __esm({
3810
3914
  }
3811
3915
  if (isUseCssExtract(config, target)) {
3812
3916
  const extractPluginOptions = config.tools.cssExtract.pluginOptions;
3813
- const cssPath = (0, import_shared29.getDistPath)(config, "css");
3814
- const cssFilename = (0, import_shared29.getFilename)(config, "css", isProd6);
3815
- const cssAsyncPath = (0, import_shared29.getDistPath)(config, "cssAsync");
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");
3816
3920
  chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
3817
3921
  {
3818
- filename: import_node_path15.posix.join(cssPath, cssFilename),
3819
- chunkFilename: import_node_path15.posix.join(cssAsyncPath, cssFilename),
3922
+ filename: import_node_path14.posix.join(cssPath, cssFilename),
3923
+ chunkFilename: import_node_path14.posix.join(cssAsyncPath, cssFilename),
3820
3924
  ...extractPluginOptions
3821
3925
  }
3822
3926
  ]);
@@ -3861,13 +3965,13 @@ function applyAlias({
3861
3965
  if (!alias) {
3862
3966
  return;
3863
3967
  }
3864
- const mergedAlias = (0, import_shared30.reduceConfigsWithContext)({
3968
+ const mergedAlias = (0, import_shared24.reduceConfigsWithContext)({
3865
3969
  initial: {},
3866
3970
  config: alias,
3867
3971
  ctx: { target }
3868
3972
  });
3869
3973
  for (const name of Object.keys(mergedAlias)) {
3870
- const values = (0, import_shared30.castArray)(mergedAlias[name]);
3974
+ const values = (0, import_shared24.castArray)(mergedAlias[name]);
3871
3975
  const formattedValues = values.map((value) => {
3872
3976
  if (typeof value === "string" && value.startsWith(".")) {
3873
3977
  return ensureAbsolutePath(rootPath, value);
@@ -3880,11 +3984,11 @@ function applyAlias({
3880
3984
  );
3881
3985
  }
3882
3986
  }
3883
- var import_shared30, pluginResolve;
3987
+ var import_shared24, pluginResolve;
3884
3988
  var init_resolve = __esm({
3885
3989
  "src/plugins/resolve.ts"() {
3886
3990
  "use strict";
3887
- import_shared30 = require("@rsbuild/shared");
3991
+ import_shared24 = require("@rsbuild/shared");
3888
3992
  init_helpers();
3889
3993
  pluginResolve = () => ({
3890
3994
  name: "rsbuild:resolve",
@@ -3932,7 +4036,7 @@ async function printHeader(longestFileLength, longestLabelLength) {
3932
4036
  }
3933
4037
  return `${prev + curLabel} `;
3934
4038
  }, " ");
3935
- import_shared32.logger.log(import_shared32.color.bold(import_shared32.color.blue(headerRow)));
4039
+ import_rslog.logger.log(import_shared26.color.bold(import_shared26.color.blue(headerRow)));
3936
4040
  }
3937
4041
  async function printFileSizes(config, stats, rootPath) {
3938
4042
  if (config.detail === false && config.total === false) {
@@ -3941,13 +4045,13 @@ async function printFileSizes(config, stats, rootPath) {
3941
4045
  const { default: gzipSize } = await import("@rsbuild/shared/gzip-size");
3942
4046
  const formatAsset = (asset, distPath, distFolder) => {
3943
4047
  const fileName = asset.name.split("?")[0];
3944
- const contents = import_shared31.fse.readFileSync(import_node_path16.default.join(distPath, fileName));
4048
+ const contents = import_shared25.fse.readFileSync(import_node_path15.default.join(distPath, fileName));
3945
4049
  const size = contents.length;
3946
4050
  const gzippedSize = gzipSize.sync(contents);
3947
4051
  return {
3948
4052
  size,
3949
- folder: import_node_path16.default.join(distFolder, import_node_path16.default.dirname(fileName)),
3950
- name: import_node_path16.default.basename(fileName),
4053
+ folder: import_node_path15.default.join(distFolder, import_node_path15.default.dirname(fileName)),
4054
+ name: import_node_path15.default.basename(fileName),
3951
4055
  gzippedSize,
3952
4056
  sizeLabel: calcFileSize(size),
3953
4057
  gzipSizeLabel: getAssetColor(gzippedSize)(calcFileSize(gzippedSize))
@@ -3974,7 +4078,7 @@ async function printFileSizes(config, stats, rootPath) {
3974
4078
  const filteredAssets = origin.assets.filter(
3975
4079
  (asset) => filterAsset(asset.name)
3976
4080
  );
3977
- const distFolder = import_node_path16.default.relative(rootPath, distPath);
4081
+ const distFolder = import_node_path15.default.relative(rootPath, distPath);
3978
4082
  return filteredAssets.map(
3979
4083
  (asset) => formatAsset(asset, distPath, distFolder)
3980
4084
  );
@@ -3983,10 +4087,10 @@ async function printFileSizes(config, stats, rootPath) {
3983
4087
  return;
3984
4088
  }
3985
4089
  assets.sort((a, b) => a.size - b.size);
3986
- import_shared32.logger.info("Production file sizes:\n");
4090
+ import_rslog.logger.info("Production file sizes:\n");
3987
4091
  const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
3988
4092
  const longestFileLength = Math.max(
3989
- ...assets.map((a) => (a.folder + import_node_path16.default.sep + a.name).length)
4093
+ ...assets.map((a) => (a.folder + import_node_path15.default.sep + a.name).length)
3990
4094
  );
3991
4095
  if (config.detail !== false) {
3992
4096
  printHeader(longestFileLength, longestLabelLength);
@@ -3996,7 +4100,7 @@ async function printFileSizes(config, stats, rootPath) {
3996
4100
  for (const asset of assets) {
3997
4101
  let { sizeLabel } = asset;
3998
4102
  const { name, folder, gzipSizeLabel } = asset;
3999
- const fileNameLength = (folder + import_node_path16.default.sep + name).length;
4103
+ const fileNameLength = (folder + import_node_path15.default.sep + name).length;
4000
4104
  const sizeLength = sizeLabel.length;
4001
4105
  totalSize += asset.size;
4002
4106
  totalGzipSize += asset.gzippedSize;
@@ -4005,60 +4109,61 @@ async function printFileSizes(config, stats, rootPath) {
4005
4109
  const rightPadding = " ".repeat(longestLabelLength - sizeLength);
4006
4110
  sizeLabel += rightPadding;
4007
4111
  }
4008
- let fileNameLabel = import_shared32.color.dim(asset.folder + import_node_path16.default.sep) + coloringAssetName(asset.name);
4112
+ let fileNameLabel = import_shared26.color.dim(asset.folder + import_node_path15.default.sep) + coloringAssetName(asset.name);
4009
4113
  if (fileNameLength < longestFileLength) {
4010
4114
  const rightPadding = " ".repeat(longestFileLength - fileNameLength);
4011
4115
  fileNameLabel += rightPadding;
4012
4116
  }
4013
- import_shared32.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
4117
+ import_rslog.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
4014
4118
  }
4015
4119
  }
4016
4120
  if (config.total !== false) {
4017
- const totalSizeLabel = `${import_shared32.color.bold(
4018
- import_shared32.color.blue("Total size:")
4121
+ const totalSizeLabel = `${import_shared26.color.bold(
4122
+ import_shared26.color.blue("Total size:")
4019
4123
  )} ${calcFileSize(totalSize)}`;
4020
- const gzippedSizeLabel = `${import_shared32.color.bold(
4021
- import_shared32.color.blue("Gzipped size:")
4124
+ const gzippedSizeLabel = `${import_shared26.color.bold(
4125
+ import_shared26.color.blue("Gzipped size:")
4022
4126
  )} ${calcFileSize(totalGzipSize)}`;
4023
- import_shared32.logger.log(`
4127
+ import_rslog.logger.log(`
4024
4128
  ${totalSizeLabel}
4025
4129
  ${gzippedSizeLabel}
4026
4130
  `);
4027
4131
  }
4028
4132
  }
4029
- var import_node_path16, import_shared31, import_shared32, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
4133
+ var import_node_path15, import_shared25, import_shared26, filterAsset, getAssetColor, calcFileSize, coloringAssetName, pluginFileSize;
4030
4134
  var init_fileSize = __esm({
4031
4135
  "src/plugins/fileSize.ts"() {
4032
4136
  "use strict";
4033
- import_node_path16 = __toESM(require("path"));
4034
- import_shared31 = require("@rsbuild/shared");
4035
- import_shared32 = require("@rsbuild/shared");
4137
+ import_node_path15 = __toESM(require("path"));
4138
+ import_shared25 = require("@rsbuild/shared");
4139
+ import_shared26 = require("@rsbuild/shared");
4036
4140
  init_constants();
4141
+ init_logger();
4037
4142
  filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
4038
4143
  getAssetColor = (size) => {
4039
4144
  if (size > 300 * 1e3) {
4040
- return import_shared32.color.red;
4145
+ return import_shared26.color.red;
4041
4146
  }
4042
4147
  if (size > 100 * 1e3) {
4043
- return import_shared32.color.yellow;
4148
+ return import_shared26.color.yellow;
4044
4149
  }
4045
- return import_shared32.color.green;
4150
+ return import_shared26.color.green;
4046
4151
  };
4047
4152
  calcFileSize = (len) => {
4048
4153
  const val = len / 1e3;
4049
4154
  return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
4050
4155
  };
4051
4156
  coloringAssetName = (assetName) => {
4052
- if (import_shared31.JS_REGEX.test(assetName)) {
4053
- return import_shared32.color.cyan(assetName);
4157
+ if (import_shared25.JS_REGEX.test(assetName)) {
4158
+ return import_shared26.color.cyan(assetName);
4054
4159
  }
4055
4160
  if (CSS_REGEX.test(assetName)) {
4056
- return import_shared32.color.yellow(assetName);
4161
+ return import_shared26.color.yellow(assetName);
4057
4162
  }
4058
4163
  if (HTML_REGEX.test(assetName)) {
4059
- return import_shared32.color.green(assetName);
4164
+ return import_shared26.color.green(assetName);
4060
4165
  }
4061
- return import_shared32.color.magenta(assetName);
4166
+ return import_shared26.color.magenta(assetName);
4062
4167
  };
4063
4168
  pluginFileSize = () => ({
4064
4169
  name: "rsbuild:file-size",
@@ -4080,8 +4185,8 @@ var init_fileSize = __esm({
4080
4185
  api.context.rootPath
4081
4186
  );
4082
4187
  } catch (err) {
4083
- import_shared32.logger.warn("Failed to print file size.");
4084
- import_shared32.logger.warn(err);
4188
+ import_rslog.logger.warn("Failed to print file size.");
4189
+ import_rslog.logger.warn(err);
4085
4190
  }
4086
4191
  }
4087
4192
  });
@@ -4095,18 +4200,19 @@ var cleanOutput_exports = {};
4095
4200
  __export(cleanOutput_exports, {
4096
4201
  pluginCleanOutput: () => pluginCleanOutput
4097
4202
  });
4098
- var import_node_path17, import_shared33, emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
4203
+ var import_node_path16, import_shared27, emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
4099
4204
  var init_cleanOutput = __esm({
4100
4205
  "src/plugins/cleanOutput.ts"() {
4101
4206
  "use strict";
4102
- import_node_path17 = require("path");
4103
- import_shared33 = require("@rsbuild/shared");
4207
+ import_node_path16 = require("path");
4208
+ import_shared27 = require("@rsbuild/shared");
4209
+ init_logger();
4104
4210
  emptyDir = async (dir) => {
4105
- if (await import_shared33.fse.pathExists(dir)) {
4106
- await import_shared33.fse.emptyDir(dir);
4211
+ if (await import_shared27.fse.pathExists(dir)) {
4212
+ await import_shared27.fse.emptyDir(dir);
4107
4213
  }
4108
4214
  };
4109
- addTrailingSep = (dir) => dir.endsWith(import_node_path17.sep) ? dir : dir + import_node_path17.sep;
4215
+ addTrailingSep = (dir) => dir.endsWith(import_node_path16.sep) ? dir : dir + import_node_path16.sep;
4110
4216
  isStrictSubdir = (parent, child) => {
4111
4217
  const parentDir = addTrailingSep(parent);
4112
4218
  const childDir = addTrailingSep(child);
@@ -4122,14 +4228,14 @@ var init_cleanOutput = __esm({
4122
4228
  if (cleanDistPath === void 0) {
4123
4229
  cleanDistPath = isStrictSubdir(rootPath, distPath);
4124
4230
  if (!cleanDistPath) {
4125
- import_shared33.logger.warn(
4231
+ import_rslog.logger.warn(
4126
4232
  "The dist path is not a subdir of root path, Rsbuild will not empty it."
4127
4233
  );
4128
- import_shared33.logger.warn(
4129
- `Please set ${import_shared33.color.yellow("`output.cleanDistPath`")} config manually.`
4234
+ import_rslog.logger.warn(
4235
+ `Please set ${import_shared27.color.yellow("`output.cleanDistPath`")} config manually.`
4130
4236
  );
4131
- import_shared33.logger.warn(`Current root path: ${import_shared33.color.dim(rootPath)}`);
4132
- import_shared33.logger.warn(`Current dist path: ${import_shared33.color.dim(distPath)}`);
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)}`);
4133
4239
  }
4134
4240
  }
4135
4241
  if (cleanDistPath) {
@@ -4156,13 +4262,13 @@ function getRegExpForExts(exts) {
4156
4262
  "i"
4157
4263
  );
4158
4264
  }
4159
- var import_node_path18, import_shared34, chainStaticAssetRule, pluginAsset;
4265
+ var import_node_path17, chainStaticAssetRule, pluginAsset;
4160
4266
  var init_asset = __esm({
4161
4267
  "src/plugins/asset.ts"() {
4162
4268
  "use strict";
4163
- import_node_path18 = __toESM(require("path"));
4164
- import_shared34 = require("@rsbuild/shared");
4269
+ import_node_path17 = __toESM(require("path"));
4165
4270
  init_constants();
4271
+ init_helpers();
4166
4272
  chainStaticAssetRule = ({
4167
4273
  emit,
4168
4274
  rule,
@@ -4187,12 +4293,12 @@ var init_asset = __esm({
4187
4293
  pluginAsset = () => ({
4188
4294
  name: "rsbuild:asset",
4189
4295
  setup(api) {
4190
- api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
4296
+ api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
4191
4297
  const config = api.getNormalizedConfig();
4192
4298
  const createAssetRule = (assetType, exts, emit2) => {
4193
4299
  const regExp = getRegExpForExts(exts);
4194
- const distDir = (0, import_shared34.getDistPath)(config, assetType);
4195
- const filename = (0, import_shared34.getFilename)(config, assetType, isProd6);
4300
+ const distDir = config.output.distPath[assetType];
4301
+ const filename = getFilename(config, assetType, isProd7);
4196
4302
  const { dataUriLimit } = config.output;
4197
4303
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
4198
4304
  const rule = chain.module.rule(assetType).test(regExp);
@@ -4200,7 +4306,7 @@ var init_asset = __esm({
4200
4306
  emit: emit2,
4201
4307
  rule,
4202
4308
  maxSize,
4203
- filename: import_node_path18.default.posix.join(distDir, filename),
4309
+ filename: import_node_path17.default.posix.join(distDir, filename),
4204
4310
  assetType
4205
4311
  });
4206
4312
  };
@@ -4226,24 +4332,24 @@ __export(minimize_exports, {
4226
4332
  parseMinifyOptions: () => parseMinifyOptions,
4227
4333
  pluginMinimize: () => pluginMinimize
4228
4334
  });
4229
- var import_shared35, import_core6, getSwcMinimizerOptions, parseMinifyOptions, pluginMinimize;
4335
+ var import_shared28, import_core6, getSwcMinimizerOptions, parseMinifyOptions, pluginMinimize;
4230
4336
  var init_minimize = __esm({
4231
4337
  "src/plugins/minimize.ts"() {
4232
4338
  "use strict";
4233
- import_shared35 = require("@rsbuild/shared");
4339
+ import_shared28 = require("@rsbuild/shared");
4234
4340
  import_core6 = require("@rspack/core");
4235
4341
  getSwcMinimizerOptions = (config) => {
4236
4342
  const options = {};
4237
4343
  const { removeConsole } = config.performance;
4238
4344
  if (removeConsole === true) {
4239
4345
  options.compress = {
4240
- ...(0, import_shared35.isObject)(options.compress) ? options.compress : {},
4346
+ ...(0, import_shared28.isObject)(options.compress) ? options.compress : {},
4241
4347
  drop_console: true
4242
4348
  };
4243
4349
  } else if (Array.isArray(removeConsole)) {
4244
4350
  const pureFuncs = removeConsole.map((method) => `console.${method}`);
4245
4351
  options.compress = {
4246
- ...(0, import_shared35.isObject)(options.compress) ? options.compress : {},
4352
+ ...(0, import_shared28.isObject)(options.compress) ? options.compress : {},
4247
4353
  pure_funcs: pureFuncs
4248
4354
  };
4249
4355
  }
@@ -4266,13 +4372,13 @@ var init_minimize = __esm({
4266
4372
  options.format.asciiOnly = config.output.charset === "ascii";
4267
4373
  const jsOptions = parseMinifyOptions(config).jsOptions;
4268
4374
  if (jsOptions) {
4269
- return (0, import_shared35.deepmerge)(options, jsOptions);
4375
+ return (0, import_shared28.deepmerge)(options, jsOptions);
4270
4376
  }
4271
4377
  return options;
4272
4378
  };
4273
- parseMinifyOptions = (config, isProd6 = true) => {
4379
+ parseMinifyOptions = (config, isProd7 = true) => {
4274
4380
  const minify = config.output.minify;
4275
- if (minify === false || !isProd6) {
4381
+ if (minify === false || !isProd7) {
4276
4382
  return {
4277
4383
  minifyJs: false,
4278
4384
  minifyCss: false,
@@ -4304,19 +4410,19 @@ var init_minimize = __esm({
4304
4410
  if (api.context.bundlerType === "webpack") {
4305
4411
  return;
4306
4412
  }
4307
- api.modifyBundlerChain(async (chain, { isProd: isProd6 }) => {
4413
+ api.modifyBundlerChain(async (chain, { isProd: isProd7 }) => {
4308
4414
  const config = api.getNormalizedConfig();
4309
- const isMinimize = isProd6 && config.output.minify !== false;
4415
+ const isMinimize = isProd7 && config.output.minify !== false;
4310
4416
  if (!isMinimize) {
4311
4417
  return;
4312
4418
  }
4313
4419
  const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = import_core6.rspack;
4314
4420
  const { minifyJs, minifyCss } = parseMinifyOptions(config);
4315
4421
  if (minifyJs) {
4316
- chain.optimization.minimizer(import_shared35.CHAIN_ID.MINIMIZER.JS).use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]).end();
4422
+ chain.optimization.minimizer(import_shared28.CHAIN_ID.MINIMIZER.JS).use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]).end();
4317
4423
  }
4318
4424
  if (minifyCss) {
4319
- chain.optimization.minimizer(import_shared35.CHAIN_ID.MINIMIZER.CSS).use(SwcCssMinimizerRspackPlugin, []).end();
4425
+ chain.optimization.minimizer(import_shared28.CHAIN_ID.MINIMIZER.CSS).use(SwcCssMinimizerRspackPlugin, []).end();
4320
4426
  }
4321
4427
  });
4322
4428
  }
@@ -4333,11 +4439,12 @@ __export(HtmlBasicPlugin_exports, {
4333
4439
  VOID_TAGS: () => VOID_TAGS,
4334
4440
  hasTitle: () => hasTitle
4335
4441
  });
4336
- var import_shared36, VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
4442
+ var import_shared29, VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
4337
4443
  var init_HtmlBasicPlugin = __esm({
4338
4444
  "src/rspack/HtmlBasicPlugin.ts"() {
4339
4445
  "use strict";
4340
- import_shared36 = require("@rsbuild/shared");
4446
+ import_shared29 = require("@rsbuild/shared");
4447
+ init_helpers();
4341
4448
  init_pluginHelper();
4342
4449
  VOID_TAGS = [
4343
4450
  "area",
@@ -4412,9 +4519,9 @@ var init_HtmlBasicPlugin = __esm({
4412
4519
  if (typeof optPublicPath === "function") {
4413
4520
  filename = optPublicPath(filename, data.publicPath);
4414
4521
  } else if (typeof optPublicPath === "string") {
4415
- filename = (0, import_shared36.withPublicPath)(filename, optPublicPath);
4522
+ filename = ensureAssetPrefix(filename, optPublicPath);
4416
4523
  } else if (optPublicPath !== false) {
4417
- filename = (0, import_shared36.withPublicPath)(filename, data.publicPath);
4524
+ filename = ensureAssetPrefix(filename, data.publicPath);
4418
4525
  }
4419
4526
  const optHash = tag.hash ?? tagConfig.hash;
4420
4527
  if (typeof optHash === "function") {
@@ -4448,7 +4555,7 @@ var init_HtmlBasicPlugin = __esm({
4448
4555
  publicPath: data.publicPath
4449
4556
  };
4450
4557
  for (const item of tagConfig.tags) {
4451
- if ((0, import_shared36.isFunction)(item)) {
4558
+ if ((0, import_shared29.isFunction)(item)) {
4452
4559
  tags = item(tags, utils) || tags;
4453
4560
  } else {
4454
4561
  tags.push(item);
@@ -4457,7 +4564,7 @@ var init_HtmlBasicPlugin = __esm({
4457
4564
  (tag1, tag2) => getTagPriority(tag1, tagConfig) - getTagPriority(tag2, tagConfig)
4458
4565
  );
4459
4566
  }
4460
- const [headTags, bodyTags] = (0, import_shared36.partition)(
4567
+ const [headTags, bodyTags] = partition(
4461
4568
  tags,
4462
4569
  (tag) => tag.head ?? HEAD_TAGS.includes(tag.tag)
4463
4570
  );
@@ -4539,13 +4646,14 @@ var HtmlAppIconPlugin_exports = {};
4539
4646
  __export(HtmlAppIconPlugin_exports, {
4540
4647
  HtmlAppIconPlugin: () => HtmlAppIconPlugin
4541
4648
  });
4542
- var import_node_fs4, import_node_path19, import_shared37, HtmlAppIconPlugin;
4649
+ var import_node_fs4, import_node_path18, import_shared30, HtmlAppIconPlugin;
4543
4650
  var init_HtmlAppIconPlugin = __esm({
4544
4651
  "src/rspack/HtmlAppIconPlugin.ts"() {
4545
4652
  "use strict";
4546
4653
  import_node_fs4 = __toESM(require("fs"));
4547
- import_node_path19 = require("path");
4548
- import_shared37 = require("@rsbuild/shared");
4654
+ import_node_path18 = require("path");
4655
+ import_shared30 = require("@rsbuild/shared");
4656
+ init_helpers();
4549
4657
  init_pluginHelper();
4550
4658
  HtmlAppIconPlugin = class {
4551
4659
  constructor(options) {
@@ -4562,17 +4670,17 @@ var init_HtmlAppIconPlugin = __esm({
4562
4670
  `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
4563
4671
  );
4564
4672
  }
4565
- const iconRelativePath = import_node_path19.posix.join(this.distDir, (0, import_node_path19.basename)(this.iconPath));
4673
+ const iconRelativePath = import_node_path18.posix.join(this.distDir, (0, import_node_path18.basename)(this.iconPath));
4566
4674
  compiler.hooks.compilation.tap(this.name, (compilation) => {
4567
4675
  getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
4568
- const publicPath = (0, import_shared37.getPublicPathFromCompiler)(compiler);
4676
+ const publicPath = (0, import_shared30.getPublicPathFromCompiler)(compiler);
4569
4677
  data.headTags.unshift({
4570
4678
  tagName: "link",
4571
4679
  voidTag: true,
4572
4680
  attributes: {
4573
4681
  rel: "apple-touch-icon",
4574
4682
  sizes: "180*180",
4575
- href: (0, import_shared37.withPublicPath)(iconRelativePath, publicPath)
4683
+ href: ensureAssetPrefix(iconRelativePath, publicPath)
4576
4684
  },
4577
4685
  meta: {}
4578
4686
  });
@@ -4645,8 +4753,8 @@ function getTerserMinifyOptions(config) {
4645
4753
  const finalOptions = applyRemoveConsole(options, config);
4646
4754
  return finalOptions;
4647
4755
  }
4648
- async function getHtmlMinifyOptions(isProd6, config) {
4649
- if (!isProd6 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4756
+ async function getHtmlMinifyOptions(isProd7, config) {
4757
+ if (!isProd7 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4650
4758
  return false;
4651
4759
  }
4652
4760
  const minifyJS = getTerserMinifyOptions(config);
@@ -4664,25 +4772,25 @@ async function getHtmlMinifyOptions(isProd6, config) {
4664
4772
  minifyURLs: true
4665
4773
  };
4666
4774
  const htmlMinifyOptions = parseMinifyOptions(config).htmlOptions;
4667
- return typeof htmlMinifyOptions === "object" ? (0, import_shared38.deepmerge)(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
4775
+ return typeof htmlMinifyOptions === "object" ? (0, import_shared31.deepmerge)(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
4668
4776
  }
4669
4777
  function getTitle(entryName, config) {
4670
- return (0, import_shared38.reduceConfigsMergeContext)({
4778
+ return (0, import_shared31.reduceConfigsMergeContext)({
4671
4779
  initial: "",
4672
4780
  config: config.html.title,
4673
4781
  ctx: { entryName }
4674
4782
  });
4675
4783
  }
4676
4784
  function getInject(entryName, config) {
4677
- return (0, import_shared38.reduceConfigsMergeContext)({
4785
+ return (0, import_shared31.reduceConfigsMergeContext)({
4678
4786
  initial: "head",
4679
4787
  config: config.html.inject,
4680
4788
  ctx: { entryName }
4681
4789
  });
4682
4790
  }
4683
4791
  async function getTemplate(entryName, config, rootPath) {
4684
- const DEFAULT_TEMPLATE = import_node_path20.default.resolve(STATIC_PATH, "template.html");
4685
- const templatePath = (0, import_shared38.reduceConfigsMergeContext)({
4792
+ const DEFAULT_TEMPLATE = import_node_path19.default.resolve(STATIC_PATH, "template.html");
4793
+ const templatePath = (0, import_shared31.reduceConfigsMergeContext)({
4686
4794
  initial: DEFAULT_TEMPLATE,
4687
4795
  config: config.html.template,
4688
4796
  ctx: { entryName }
@@ -4692,32 +4800,32 @@ async function getTemplate(entryName, config, rootPath) {
4692
4800
  templatePath
4693
4801
  };
4694
4802
  }
4695
- const absolutePath = (0, import_node_path20.isAbsolute)(templatePath) ? templatePath : import_node_path20.default.resolve(rootPath, templatePath);
4803
+ const absolutePath = (0, import_node_path19.isAbsolute)(templatePath) ? templatePath : import_node_path19.default.resolve(rootPath, templatePath);
4696
4804
  if (!existTemplatePath.includes(absolutePath)) {
4697
4805
  if (!await isFileExists(absolutePath)) {
4698
4806
  throw new Error(
4699
- `Failed to resolve HTML template, please check if the file exists: ${import_shared38.color.cyan(
4807
+ `Failed to resolve HTML template, please check if the file exists: ${import_shared31.color.cyan(
4700
4808
  absolutePath
4701
4809
  )}`
4702
4810
  );
4703
4811
  }
4704
4812
  existTemplatePath.push(absolutePath);
4705
4813
  }
4706
- const templateContent = await import_shared38.fse.readFile(absolutePath, "utf-8");
4814
+ const templateContent = await import_shared31.fse.readFile(absolutePath, "utf-8");
4707
4815
  return {
4708
4816
  templatePath: absolutePath,
4709
4817
  templateContent
4710
4818
  };
4711
4819
  }
4712
4820
  function getFavicon(entryName, config) {
4713
- return (0, import_shared38.reduceConfigsMergeContext)({
4821
+ return (0, import_shared31.reduceConfigsMergeContext)({
4714
4822
  initial: "",
4715
4823
  config: config.html.favicon,
4716
4824
  ctx: { entryName }
4717
4825
  });
4718
4826
  }
4719
4827
  function getMetaTags(entryName, config, templateContent) {
4720
- const metaTags = (0, import_shared38.reduceConfigsMergeContext)({
4828
+ const metaTags = (0, import_shared31.reduceConfigsMergeContext)({
4721
4829
  initial: {},
4722
4830
  config: config.html.meta,
4723
4831
  ctx: { entryName }
@@ -4745,7 +4853,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
4745
4853
  options: pluginOptions
4746
4854
  }
4747
4855
  };
4748
- return (0, import_shared38.reduceConfigsWithContext)({
4856
+ return (0, import_shared31.reduceConfigsWithContext)({
4749
4857
  initial: defaultOptions2,
4750
4858
  config: templateParameters,
4751
4859
  ctx: { entryName }
@@ -4755,7 +4863,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
4755
4863
  function getChunks(entryName, entryValue) {
4756
4864
  const chunks = [entryName];
4757
4865
  for (const item of entryValue) {
4758
- if (!(0, import_shared38.isPlainObject)(item)) {
4866
+ if (!(0, import_shared31.isPlainObject)(item)) {
4759
4867
  continue;
4760
4868
  }
4761
4869
  const { dependOn } = item;
@@ -4770,19 +4878,19 @@ function getChunks(entryName, entryValue) {
4770
4878
  }
4771
4879
  return chunks;
4772
4880
  }
4773
- var import_node_path20, import_shared38, existTemplatePath, getTagConfig, pluginHtml;
4881
+ var import_node_path19, import_shared31, existTemplatePath, getTagConfig, pluginHtml;
4774
4882
  var init_html = __esm({
4775
4883
  "src/plugins/html.ts"() {
4776
4884
  "use strict";
4777
- import_node_path20 = __toESM(require("path"));
4778
- import_shared38 = require("@rsbuild/shared");
4885
+ import_node_path19 = __toESM(require("path"));
4886
+ import_shared31 = require("@rsbuild/shared");
4779
4887
  init_constants();
4780
4888
  init_helpers();
4781
4889
  init_minimize();
4782
4890
  existTemplatePath = [];
4783
4891
  getTagConfig = (api) => {
4784
4892
  const config = api.getNormalizedConfig();
4785
- const tags = (0, import_shared38.castArray)(config.html.tags).filter(Boolean);
4893
+ const tags = (0, import_shared31.castArray)(config.html.tags).filter(Boolean);
4786
4894
  if (!tags.length) {
4787
4895
  return void 0;
4788
4896
  }
@@ -4797,12 +4905,12 @@ var init_html = __esm({
4797
4905
  name: "rsbuild:html",
4798
4906
  setup(api) {
4799
4907
  api.modifyBundlerChain(
4800
- async (chain, { HtmlPlugin, isProd: isProd6, CHAIN_ID: CHAIN_ID3, target }) => {
4908
+ async (chain, { HtmlPlugin, isProd: isProd7, CHAIN_ID: CHAIN_ID3, target }) => {
4801
4909
  const config = api.getNormalizedConfig();
4802
- if ((0, import_shared38.isHtmlDisabled)(config, target)) {
4910
+ if ((0, import_shared31.isHtmlDisabled)(config, target)) {
4803
4911
  return;
4804
4912
  }
4805
- const minify = await getHtmlMinifyOptions(isProd6, config);
4913
+ const minify = await getHtmlMinifyOptions(isProd7, config);
4806
4914
  const assetPrefix = getPublicPathFromChain(chain, false);
4807
4915
  const entries = chain.entryPoints.entries() || {};
4808
4916
  const entryNames = Object.keys(entries);
@@ -4851,13 +4959,13 @@ var init_html = __esm({
4851
4959
  pluginOptions.title = getTitle(entryName, config);
4852
4960
  const favicon = getFavicon(entryName, config);
4853
4961
  if (favicon) {
4854
- if ((0, import_shared38.isURL)(favicon)) {
4962
+ if (isURL(favicon)) {
4855
4963
  htmlInfo.favicon = favicon;
4856
4964
  } else {
4857
4965
  pluginOptions.favicon = favicon;
4858
4966
  }
4859
4967
  }
4860
- const finalOptions2 = (0, import_shared38.reduceConfigsWithContext)({
4968
+ const finalOptions2 = (0, import_shared31.reduceConfigsWithContext)({
4861
4969
  initial: pluginOptions,
4862
4970
  config: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
4863
4971
  ctx: { entryName, entryValue }
@@ -4878,8 +4986,8 @@ var init_html = __esm({
4878
4986
  }
4879
4987
  if (appIcon) {
4880
4988
  const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
4881
- const distDir = (0, import_shared38.getDistPath)(config, "image");
4882
- const iconPath = import_node_path20.default.isAbsolute(appIcon) ? appIcon : import_node_path20.default.join(api.context.rootPath, appIcon);
4989
+ const distDir = config.output.distPath.image;
4990
+ const iconPath = import_node_path19.default.isAbsolute(appIcon) ? appIcon : import_node_path19.default.join(api.context.rootPath, appIcon);
4883
4991
  chain.plugin(CHAIN_ID3.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
4884
4992
  }
4885
4993
  }
@@ -4913,23 +5021,22 @@ var wasm_exports = {};
4913
5021
  __export(wasm_exports, {
4914
5022
  pluginWasm: () => pluginWasm
4915
5023
  });
4916
- var import_node_path21, import_shared39, pluginWasm;
5024
+ var import_node_path20, pluginWasm;
4917
5025
  var init_wasm = __esm({
4918
5026
  "src/plugins/wasm.ts"() {
4919
5027
  "use strict";
4920
- import_node_path21 = require("path");
4921
- import_shared39 = require("@rsbuild/shared");
5028
+ import_node_path20 = require("path");
4922
5029
  pluginWasm = () => ({
4923
5030
  name: "rsbuild:wasm",
4924
5031
  setup(api) {
4925
5032
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
4926
5033
  const config = api.getNormalizedConfig();
4927
- const distPath = (0, import_shared39.getDistPath)(config, "wasm");
5034
+ const distPath = config.output.distPath.wasm;
4928
5035
  chain.experiments({
4929
5036
  ...chain.get("experiments"),
4930
5037
  asyncWebAssembly: true
4931
5038
  });
4932
- const wasmFilename = import_node_path21.posix.join(distPath, "[hash].module.wasm");
5039
+ const wasmFilename = import_node_path20.posix.join(distPath, "[hash].module.wasm");
4933
5040
  chain.output.merge({
4934
5041
  webassemblyModuleFilename: wasmFilename
4935
5042
  });
@@ -4977,15 +5084,15 @@ var nodeAddons_exports = {};
4977
5084
  __export(nodeAddons_exports, {
4978
5085
  pluginNodeAddons: () => pluginNodeAddons
4979
5086
  });
4980
- var import_node_path22, getFilename3, pluginNodeAddons;
5087
+ var import_node_path21, getFilename2, pluginNodeAddons;
4981
5088
  var init_nodeAddons = __esm({
4982
5089
  "src/plugins/nodeAddons.ts"() {
4983
5090
  "use strict";
4984
- import_node_path22 = __toESM(require("path"));
4985
- getFilename3 = (resourcePath) => {
5091
+ import_node_path21 = __toESM(require("path"));
5092
+ getFilename2 = (resourcePath) => {
4986
5093
  let basename2 = "";
4987
5094
  if (resourcePath) {
4988
- const parsed = import_node_path22.default.parse(resourcePath);
5095
+ const parsed = import_node_path21.default.parse(resourcePath);
4989
5096
  if (parsed.dir) {
4990
5097
  basename2 = parsed.name;
4991
5098
  }
@@ -5001,7 +5108,7 @@ var init_nodeAddons = __esm({
5001
5108
  api.transform(
5002
5109
  { test: /\.node$/, targets: ["node"], raw: true },
5003
5110
  ({ code, emitFile, resourcePath }) => {
5004
- const name = getFilename3(resourcePath);
5111
+ const name = getFilename2(resourcePath);
5005
5112
  if (name === null) {
5006
5113
  throw new Error(`Failed to load Node.js addon: "${resourcePath}"`);
5007
5114
  }
@@ -5026,11 +5133,11 @@ var define_exports = {};
5026
5133
  __export(define_exports, {
5027
5134
  pluginDefine: () => pluginDefine
5028
5135
  });
5029
- var import_shared40, pluginDefine;
5136
+ var import_shared32, pluginDefine;
5030
5137
  var init_define = __esm({
5031
5138
  "src/plugins/define.ts"() {
5032
5139
  "use strict";
5033
- import_shared40 = require("@rsbuild/shared");
5140
+ import_shared32 = require("@rsbuild/shared");
5034
5141
  init_helpers();
5035
5142
  pluginDefine = () => ({
5036
5143
  name: "rsbuild:define",
@@ -5038,7 +5145,7 @@ var init_define = __esm({
5038
5145
  api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID3, bundler }) => {
5039
5146
  const config = api.getNormalizedConfig();
5040
5147
  const builtinVars = {
5041
- "process.env.NODE_ENV": JSON.stringify((0, import_shared40.getNodeEnv)()),
5148
+ "process.env.NODE_ENV": JSON.stringify((0, import_shared32.getNodeEnv)()),
5042
5149
  "process.env.ASSET_PREFIX": JSON.stringify(
5043
5150
  getPublicPathFromChain(chain, false)
5044
5151
  )
@@ -5057,12 +5164,13 @@ var progress_exports = {};
5057
5164
  __export(progress_exports, {
5058
5165
  pluginProgress: () => pluginProgress
5059
5166
  });
5060
- var import_shared41, import_core7, pluginProgress;
5167
+ var import_shared33, import_core7, pluginProgress;
5061
5168
  var init_progress = __esm({
5062
5169
  "src/plugins/progress.ts"() {
5063
5170
  "use strict";
5064
- import_shared41 = require("@rsbuild/shared");
5171
+ import_shared33 = require("@rsbuild/shared");
5065
5172
  import_core7 = require("@rspack/core");
5173
+ init_constants();
5066
5174
  pluginProgress = () => ({
5067
5175
  name: "rsbuild:progress",
5068
5176
  setup(api) {
@@ -5072,11 +5180,11 @@ var init_progress = __esm({
5072
5180
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
5073
5181
  const config = api.getNormalizedConfig();
5074
5182
  const options = config.dev.progressBar ?? // enable progress bar in production by default
5075
- (0, import_shared41.isProd)();
5183
+ (0, import_shared33.isProd)();
5076
5184
  if (!options) {
5077
5185
  return;
5078
5186
  }
5079
- const prefix = options !== true && options.id !== void 0 ? options.id : import_shared41.TARGET_ID_MAP[target];
5187
+ const prefix = options !== true && options.id !== void 0 ? options.id : TARGET_ID_MAP[target];
5080
5188
  chain.plugin(CHAIN_ID3.PLUGIN.PROGRESS).use(import_core7.rspack.ProgressPlugin, [
5081
5189
  {
5082
5190
  prefix,
@@ -5110,14 +5218,14 @@ async function getDefaultSwcConfig(config, rootPath, target) {
5110
5218
  },
5111
5219
  isModule: "unknown",
5112
5220
  env: {
5113
- targets: await (0, import_shared42.getBrowserslistWithDefault)(rootPath, config, target)
5221
+ targets: await (0, import_shared34.getBrowserslistWithDefault)(rootPath, config, target)
5114
5222
  }
5115
5223
  };
5116
5224
  }
5117
5225
  async function applyCoreJs(swcConfig, polyfillMode) {
5118
5226
  const coreJsPath = require.resolve("core-js/package.json");
5119
- const version2 = (0, import_shared42.getCoreJsVersion)(coreJsPath);
5120
- const coreJsDir = import_node_path23.default.dirname(coreJsPath);
5227
+ const version2 = (0, import_shared34.getCoreJsVersion)(coreJsPath);
5228
+ const coreJsDir = import_node_path22.default.dirname(coreJsPath);
5121
5229
  swcConfig.env.coreJs = version2;
5122
5230
  if (polyfillMode === "usage") {
5123
5231
  swcConfig.env.shippedProposals = true;
@@ -5149,13 +5257,14 @@ function applySwcDecoratorConfig(swcConfig, config) {
5149
5257
  throw new Error("Unknown decorators version: ${version}");
5150
5258
  }
5151
5259
  }
5152
- var import_node_path23, import_shared42, builtinSwcLoaderName, pluginSwc;
5260
+ var import_node_path22, import_shared34, builtinSwcLoaderName, pluginSwc;
5153
5261
  var init_swc = __esm({
5154
5262
  "src/plugins/swc.ts"() {
5155
5263
  "use strict";
5156
- import_node_path23 = __toESM(require("path"));
5157
- import_shared42 = require("@rsbuild/shared");
5264
+ import_node_path22 = __toESM(require("path"));
5265
+ import_shared34 = require("@rsbuild/shared");
5158
5266
  init_constants();
5267
+ init_helpers();
5159
5268
  builtinSwcLoaderName = "builtin:swc-loader";
5160
5269
  pluginSwc = () => ({
5161
5270
  name: PLUGIN_SWC_NAME,
@@ -5167,11 +5276,11 @@ var init_swc = __esm({
5167
5276
  order: "pre",
5168
5277
  handler: async (chain, { CHAIN_ID: CHAIN_ID3, target }) => {
5169
5278
  const config = api.getNormalizedConfig();
5170
- const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared42.SCRIPT_REGEX).type("javascript/auto");
5279
+ const rule = chain.module.rule(CHAIN_ID3.RULE.JS).test(import_shared34.SCRIPT_REGEX).type("javascript/auto");
5171
5280
  const dataUriRule = chain.module.rule(CHAIN_ID3.RULE.JS_DATA_URI).mimetype({
5172
5281
  or: ["text/javascript", "application/javascript"]
5173
5282
  });
5174
- (0, import_shared42.applyScriptCondition)({
5283
+ (0, import_shared34.applyScriptCondition)({
5175
5284
  rule,
5176
5285
  chain,
5177
5286
  config,
@@ -5189,10 +5298,10 @@ var init_swc = __esm({
5189
5298
  if (swcConfig.jsc?.externalHelpers) {
5190
5299
  chain.resolve.alias.set(
5191
5300
  "@swc/helpers",
5192
- import_node_path23.default.dirname(require.resolve("@swc/helpers/package.json"))
5301
+ import_node_path22.default.dirname(require.resolve("@swc/helpers/package.json"))
5193
5302
  );
5194
5303
  }
5195
- if ((0, import_shared42.isWebTarget)(target)) {
5304
+ if (isWebTarget(target)) {
5196
5305
  const polyfillMode = config.output.polyfill;
5197
5306
  if (polyfillMode === "off") {
5198
5307
  swcConfig.env.mode = void 0;
@@ -5204,13 +5313,13 @@ var init_swc = __esm({
5204
5313
  }
5205
5314
  }
5206
5315
  }
5207
- const mergedSwcConfig = (0, import_shared42.reduceConfigs)({
5316
+ const mergedSwcConfig = (0, import_shared34.reduceConfigs)({
5208
5317
  initial: swcConfig,
5209
5318
  config: config.tools.swc,
5210
- mergeFn: import_shared42.deepmerge
5319
+ mergeFn: import_shared34.deepmerge
5211
5320
  });
5212
5321
  rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
5213
- dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared42.cloneDeep)(mergedSwcConfig));
5322
+ dataUriRule.resolve.set("fullySpecified", false).end().use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared34.cloneDeep)(mergedSwcConfig));
5214
5323
  }
5215
5324
  });
5216
5325
  }
@@ -5277,11 +5386,11 @@ function splitByExperience(ctx) {
5277
5386
  const { override, polyfill, defaultConfig, userDefinedCacheGroups } = ctx;
5278
5387
  const experienceCacheGroup = {};
5279
5388
  const packageRegExps = {
5280
- lodash: (0, import_shared43.createDependenciesRegExp)("lodash", "lodash-es"),
5281
- axios: (0, import_shared43.createDependenciesRegExp)("axios", /axios-.+/)
5389
+ lodash: (0, import_shared35.createDependenciesRegExp)("lodash", "lodash-es"),
5390
+ axios: (0, import_shared35.createDependenciesRegExp)("axios", /axios-.+/)
5282
5391
  };
5283
5392
  if (polyfill === "entry" || polyfill === "usage") {
5284
- packageRegExps.polyfill = (0, import_shared43.createDependenciesRegExp)(
5393
+ packageRegExps.polyfill = (0, import_shared35.createDependenciesRegExp)(
5285
5394
  "tslib",
5286
5395
  "core-js",
5287
5396
  "@babel/runtime",
@@ -5330,7 +5439,7 @@ function splitByModule(ctx) {
5330
5439
  // Core group
5331
5440
  vendors: {
5332
5441
  priority: -9,
5333
- test: import_shared43.NODE_MODULES_REGEX,
5442
+ test: import_shared35.NODE_MODULES_REGEX,
5334
5443
  name(module2) {
5335
5444
  return module2 ? getPackageNameFromModulePath(module2.context) : void 0;
5336
5445
  }
@@ -5373,7 +5482,7 @@ function singleVendor(ctx) {
5373
5482
  const { override, defaultConfig, userDefinedCacheGroups } = ctx;
5374
5483
  const singleVendorCacheGroup = {
5375
5484
  singleVendor: {
5376
- test: import_shared43.NODE_MODULES_REGEX,
5485
+ test: import_shared35.NODE_MODULES_REGEX,
5377
5486
  priority: 0,
5378
5487
  chunks: "all",
5379
5488
  name: "vendor",
@@ -5392,12 +5501,12 @@ function singleVendor(ctx) {
5392
5501
  }
5393
5502
  };
5394
5503
  }
5395
- var import_node_assert, import_shared43, MODULE_PATH_REGEX, SPLIT_STRATEGY_DISPATCHER, pluginSplitChunks;
5504
+ var import_node_assert, import_shared35, MODULE_PATH_REGEX, SPLIT_STRATEGY_DISPATCHER, pluginSplitChunks;
5396
5505
  var init_splitChunks = __esm({
5397
5506
  "src/plugins/splitChunks.ts"() {
5398
5507
  "use strict";
5399
5508
  import_node_assert = __toESM(require("assert"));
5400
- import_shared43 = require("@rsbuild/shared");
5509
+ import_shared35 = require("@rsbuild/shared");
5401
5510
  MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/;
5402
5511
  SPLIT_STRATEGY_DISPATCHER = {
5403
5512
  "split-by-experience": splitByExperience,
@@ -5480,10 +5589,10 @@ async function openBrowser(url2) {
5480
5589
  );
5481
5590
  return true;
5482
5591
  }
5483
- (0, import_shared44.debug)("Failed to find the target browser.");
5592
+ import_rslog.logger.debug("Failed to find the target browser.");
5484
5593
  } catch (err) {
5485
- (0, import_shared44.debug)("Failed to open start URL with apple script.");
5486
- import_shared44.logger.debug(err);
5594
+ import_rslog.logger.debug("Failed to open start URL with apple script.");
5595
+ import_rslog.logger.debug(err);
5487
5596
  }
5488
5597
  }
5489
5598
  try {
@@ -5491,13 +5600,13 @@ async function openBrowser(url2) {
5491
5600
  await open(url2);
5492
5601
  return true;
5493
5602
  } catch (err) {
5494
- import_shared44.logger.error("Failed to open start URL.");
5495
- import_shared44.logger.error(err);
5603
+ import_rslog.logger.error("Failed to open start URL.");
5604
+ import_rslog.logger.error(err);
5496
5605
  return false;
5497
5606
  }
5498
5607
  }
5499
5608
  function resolveUrl(str, base) {
5500
- if ((0, import_shared44.canParse)(str)) {
5609
+ if (canParse(str)) {
5501
5610
  return str;
5502
5611
  }
5503
5612
  try {
@@ -5555,14 +5664,16 @@ function pluginOpen() {
5555
5664
  }
5556
5665
  };
5557
5666
  }
5558
- var import_node_child_process, import_node_util, import_shared44, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
5667
+ var import_node_child_process, import_node_util, import_shared36, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePlaceholder, openedURLs, normalizeOpenConfig;
5559
5668
  var init_open = __esm({
5560
5669
  "src/plugins/open.ts"() {
5561
5670
  "use strict";
5562
5671
  import_node_child_process = require("child_process");
5563
5672
  import_node_util = require("util");
5564
- import_shared44 = require("@rsbuild/shared");
5673
+ import_shared36 = require("@rsbuild/shared");
5565
5674
  init_constants();
5675
+ init_helpers();
5676
+ init_logger();
5566
5677
  execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
5567
5678
  supportedChromiumBrowsers = [
5568
5679
  "Google Chrome Canary",
@@ -5600,7 +5711,7 @@ var init_open = __esm({
5600
5711
  return { targets: open, before: beforeStartUrl };
5601
5712
  }
5602
5713
  return {
5603
- targets: open.target ? (0, import_shared44.castArray)(open.target) : [],
5714
+ targets: open.target ? (0, import_shared36.castArray)(open.target) : [],
5604
5715
  before: open.before
5605
5716
  };
5606
5717
  };
@@ -5612,12 +5723,13 @@ var InlineChunkHtmlPlugin_exports = {};
5612
5723
  __export(InlineChunkHtmlPlugin_exports, {
5613
5724
  InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
5614
5725
  });
5615
- var import_node_path24, import_shared45, InlineChunkHtmlPlugin;
5726
+ var import_node_path23, import_shared37, InlineChunkHtmlPlugin;
5616
5727
  var init_InlineChunkHtmlPlugin = __esm({
5617
5728
  "src/rspack/InlineChunkHtmlPlugin.ts"() {
5618
5729
  "use strict";
5619
- import_node_path24 = require("path");
5620
- import_shared45 = require("@rsbuild/shared");
5730
+ import_node_path23 = require("path");
5731
+ import_shared37 = require("@rsbuild/shared");
5732
+ init_helpers();
5621
5733
  init_pluginHelper();
5622
5734
  InlineChunkHtmlPlugin = class {
5623
5735
  constructor({
@@ -5650,8 +5762,8 @@ var init_InlineChunkHtmlPlugin = __esm({
5650
5762
  const { devtool } = compilation.options;
5651
5763
  if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
5652
5764
  !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
5653
- const prefix = (0, import_shared45.addTrailingSlash)(
5654
- (0, import_node_path24.join)(publicPath, this.distPath[type] || "")
5765
+ const prefix = addTrailingSlash(
5766
+ (0, import_node_path23.join)(publicPath, this.distPath[type] || "")
5655
5767
  );
5656
5768
  return source.replace(
5657
5769
  /# sourceMappingURL=/,
@@ -5662,7 +5774,7 @@ var init_InlineChunkHtmlPlugin = __esm({
5662
5774
  }
5663
5775
  matchTests(name, source, tests) {
5664
5776
  return tests.some((test) => {
5665
- if ((0, import_shared45.isFunction)(test)) {
5777
+ if ((0, import_shared37.isFunction)(test)) {
5666
5778
  const size = source.length;
5667
5779
  return test({ name, size });
5668
5780
  }
@@ -5748,7 +5860,7 @@ var init_InlineChunkHtmlPlugin = __esm({
5748
5860
  }
5749
5861
  apply(compiler) {
5750
5862
  compiler.hooks.compilation.tap(this.name, (compilation) => {
5751
- const publicPath = (0, import_shared45.getPublicPathFromCompiler)(compiler);
5863
+ const publicPath = (0, import_shared37.getPublicPathFromCompiler)(compiler);
5752
5864
  const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
5753
5865
  const hooks = getHTMLPlugin().getHooks(compilation);
5754
5866
  hooks.alterAssetTagGroups.tap(this.name, (assets) => {
@@ -5788,18 +5900,19 @@ var inlineChunk_exports = {};
5788
5900
  __export(inlineChunk_exports, {
5789
5901
  pluginInlineChunk: () => pluginInlineChunk
5790
5902
  });
5791
- var import_shared46, pluginInlineChunk;
5903
+ var import_shared38, pluginInlineChunk;
5792
5904
  var init_inlineChunk = __esm({
5793
5905
  "src/plugins/inlineChunk.ts"() {
5794
5906
  "use strict";
5795
- import_shared46 = require("@rsbuild/shared");
5907
+ import_shared38 = require("@rsbuild/shared");
5796
5908
  init_constants();
5909
+ init_helpers();
5797
5910
  pluginInlineChunk = () => ({
5798
5911
  name: "rsbuild:inline-chunk",
5799
5912
  setup(api) {
5800
5913
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3, isDev: isDev3 }) => {
5801
5914
  const config = api.getNormalizedConfig();
5802
- if ((0, import_shared46.isHtmlDisabled)(config, target) || isDev3) {
5915
+ if ((0, import_shared38.isHtmlDisabled)(config, target) || isDev3) {
5803
5916
  return;
5804
5917
  }
5805
5918
  const { InlineChunkHtmlPlugin: InlineChunkHtmlPlugin2 } = await Promise.resolve().then(() => (init_InlineChunkHtmlPlugin(), InlineChunkHtmlPlugin_exports));
@@ -5807,7 +5920,7 @@ var init_inlineChunk = __esm({
5807
5920
  const scriptTests = [];
5808
5921
  const styleTests = [];
5809
5922
  if (inlineScripts) {
5810
- scriptTests.push(inlineScripts === true ? import_shared46.JS_REGEX : inlineScripts);
5923
+ scriptTests.push(inlineScripts === true ? import_shared38.JS_REGEX : inlineScripts);
5811
5924
  }
5812
5925
  if (inlineStyles) {
5813
5926
  styleTests.push(inlineStyles === true ? CSS_REGEX : inlineStyles);
@@ -5819,7 +5932,7 @@ var init_inlineChunk = __esm({
5819
5932
  {
5820
5933
  styleTests,
5821
5934
  scriptTests,
5822
- distPath: (0, import_shared46.pick)(config.output.distPath, ["js", "css"])
5935
+ distPath: pick(config.output.distPath, ["js", "css"])
5823
5936
  }
5824
5937
  ]);
5825
5938
  });
@@ -5838,7 +5951,7 @@ function pluginBundleAnalyzer() {
5838
5951
  name: "rsbuild:bundle-analyzer",
5839
5952
  setup(api) {
5840
5953
  api.modifyRsbuildConfig((config) => {
5841
- if ((0, import_shared47.isProd)() || !isUseAnalyzer(config)) {
5954
+ if ((0, import_shared39.isProd)() || !isUseAnalyzer(config)) {
5842
5955
  return;
5843
5956
  }
5844
5957
  config.dev ||= {};
@@ -5863,11 +5976,11 @@ function pluginBundleAnalyzer() {
5863
5976
  }
5864
5977
  };
5865
5978
  }
5866
- var import_shared47, isUseAnalyzer;
5979
+ var import_shared39, isUseAnalyzer;
5867
5980
  var init_bundleAnalyzer = __esm({
5868
5981
  "src/plugins/bundleAnalyzer.ts"() {
5869
5982
  "use strict";
5870
- import_shared47 = require("@rsbuild/shared");
5983
+ import_shared39 = require("@rsbuild/shared");
5871
5984
  isUseAnalyzer = (config) => process.env.BUNDLE_ANALYZE || config.performance?.bundleAnalyze;
5872
5985
  }
5873
5986
  });
@@ -5877,11 +5990,12 @@ var rsdoctor_exports = {};
5877
5990
  __export(rsdoctor_exports, {
5878
5991
  pluginRsdoctor: () => pluginRsdoctor
5879
5992
  });
5880
- var import_shared48, pluginRsdoctor;
5993
+ var import_shared40, pluginRsdoctor;
5881
5994
  var init_rsdoctor = __esm({
5882
5995
  "src/plugins/rsdoctor.ts"() {
5883
5996
  "use strict";
5884
- import_shared48 = require("@rsbuild/shared");
5997
+ import_shared40 = require("@rsbuild/shared");
5998
+ init_logger();
5885
5999
  pluginRsdoctor = () => ({
5886
6000
  name: "rsbuild:rsdoctor",
5887
6001
  setup(api) {
@@ -5898,8 +6012,8 @@ var init_rsdoctor = __esm({
5898
6012
  });
5899
6013
  module2 = await import(path13);
5900
6014
  } catch (err) {
5901
- import_shared48.logger.warn(
5902
- `\`process.env.RSDOCTOR\` enabled, please install ${import_shared48.color.bold(import_shared48.color.yellow(packageName))} package.`
6015
+ import_rslog.logger.warn(
6016
+ `\`process.env.RSDOCTOR\` enabled, please install ${import_shared40.color.bold(import_shared40.color.yellow(packageName))} package.`
5903
6017
  );
5904
6018
  return;
5905
6019
  }
@@ -5920,7 +6034,7 @@ var init_rsdoctor = __esm({
5920
6034
  isAutoRegister = true;
5921
6035
  }
5922
6036
  if (isAutoRegister) {
5923
- import_shared48.logger.info(`${import_shared48.color.bold(import_shared48.color.yellow(packageName))} enabled.`);
6037
+ import_rslog.logger.info(`${import_shared40.color.bold(import_shared40.color.yellow(packageName))} enabled.`);
5924
6038
  }
5925
6039
  });
5926
6040
  }
@@ -5981,7 +6095,7 @@ function determineAsValue({
5981
6095
  file
5982
6096
  }) {
5983
6097
  const url2 = new import_node_url3.URL(file || href, "https://example.com");
5984
- const extension = import_node_path25.default.extname(url2.pathname).slice(1);
6098
+ const extension = import_node_path24.default.extname(url2.pathname).slice(1);
5985
6099
  if (["css"].includes(extension)) {
5986
6100
  return "style";
5987
6101
  }
@@ -6002,11 +6116,11 @@ function determineAsValue({
6002
6116
  }
6003
6117
  return "script";
6004
6118
  }
6005
- var import_node_path25, import_node_url3;
6119
+ var import_node_path24, import_node_url3;
6006
6120
  var init_determineAsValue = __esm({
6007
6121
  "src/rspack/preload/helpers/determineAsValue.ts"() {
6008
6122
  "use strict";
6009
- import_node_path25 = __toESM(require("path"));
6123
+ import_node_path24 = __toESM(require("path"));
6010
6124
  import_node_url3 = require("url");
6011
6125
  init_constants();
6012
6126
  }
@@ -6116,10 +6230,10 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
6116
6230
  );
6117
6231
  const sortedFilteredFiles = filteredFiles.sort();
6118
6232
  const links = [];
6119
- const publicPath = (0, import_shared49.getPublicPathFromCompiler)(compilation.compiler);
6233
+ const publicPath = (0, import_shared41.getPublicPathFromCompiler)(compilation.compiler);
6120
6234
  const { crossOriginLoading } = compilation.compiler.options.output;
6121
6235
  for (const file of sortedFilteredFiles) {
6122
- const href = (0, import_shared49.withPublicPath)(file, publicPath);
6236
+ const href = ensureAssetPrefix(file, publicPath);
6123
6237
  const attributes = {
6124
6238
  href,
6125
6239
  rel: type
@@ -6147,11 +6261,12 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
6147
6261
  }
6148
6262
  return links;
6149
6263
  }
6150
- var import_shared49, defaultOptions, HtmlPreloadOrPrefetchPlugin;
6264
+ var import_shared41, defaultOptions, HtmlPreloadOrPrefetchPlugin;
6151
6265
  var init_HtmlPreloadOrPrefetchPlugin = __esm({
6152
6266
  "src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
6153
6267
  "use strict";
6154
- import_shared49 = require("@rsbuild/shared");
6268
+ import_shared41 = require("@rsbuild/shared");
6269
+ init_helpers();
6155
6270
  init_pluginHelper();
6156
6271
  init_helpers2();
6157
6272
  defaultOptions = {
@@ -6173,7 +6288,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6173
6288
  apply(compiler) {
6174
6289
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6175
6290
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6176
- `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6291
+ `HTML${upperFirst(this.type)}Plugin`,
6177
6292
  (htmlPluginData) => {
6178
6293
  this.resourceHints = generateLinks(
6179
6294
  this.options,
@@ -6186,7 +6301,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6186
6301
  }
6187
6302
  );
6188
6303
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6189
- `HTML${(0, import_shared49.upperFirst)(this.type)}Plugin`,
6304
+ `HTML${upperFirst(this.type)}Plugin`,
6190
6305
  (htmlPluginData) => {
6191
6306
  if (this.resourceHints) {
6192
6307
  htmlPluginData.assetTags.styles = [
@@ -6211,11 +6326,11 @@ var resourceHints_exports = {};
6211
6326
  __export(resourceHints_exports, {
6212
6327
  pluginResourceHints: () => pluginResourceHints
6213
6328
  });
6214
- var import_shared50, generateLinks2, pluginResourceHints;
6329
+ var import_shared42, generateLinks2, pluginResourceHints;
6215
6330
  var init_resourceHints = __esm({
6216
6331
  "src/plugins/resourceHints.ts"() {
6217
6332
  "use strict";
6218
- import_shared50 = require("@rsbuild/shared");
6333
+ import_shared42 = require("@rsbuild/shared");
6219
6334
  generateLinks2 = (options, rel) => options.map((option) => ({
6220
6335
  tag: "link",
6221
6336
  attrs: {
@@ -6250,7 +6365,7 @@ var init_resourceHints = __esm({
6250
6365
  const {
6251
6366
  performance: { preload, prefetch }
6252
6367
  } = config;
6253
- if ((0, import_shared50.isHtmlDisabled)(config, target)) {
6368
+ if ((0, import_shared42.isHtmlDisabled)(config, target)) {
6254
6369
  return;
6255
6370
  }
6256
6371
  const HTMLCount = chain.entryPoints.values().length;
@@ -6313,12 +6428,12 @@ var server_exports = {};
6313
6428
  __export(server_exports, {
6314
6429
  pluginServer: () => pluginServer
6315
6430
  });
6316
- var import_node_path26, import_shared51, pluginServer;
6431
+ var import_node_path25, import_shared43, pluginServer;
6317
6432
  var init_server = __esm({
6318
6433
  "src/plugins/server.ts"() {
6319
6434
  "use strict";
6320
- import_node_path26 = require("path");
6321
- import_shared51 = require("@rsbuild/shared");
6435
+ import_node_path25 = require("path");
6436
+ import_shared43 = require("@rsbuild/shared");
6322
6437
  init_config();
6323
6438
  pluginServer = () => ({
6324
6439
  name: "rsbuild:server",
@@ -6331,12 +6446,12 @@ var init_server = __esm({
6331
6446
  if (!copyOnBuild || !name) {
6332
6447
  continue;
6333
6448
  }
6334
- const normalizedPath = (0, import_node_path26.isAbsolute)(name) ? name : (0, import_node_path26.join)(api.context.rootPath, name);
6335
- if (!import_shared51.fse.existsSync(normalizedPath)) {
6449
+ const normalizedPath = (0, import_node_path25.isAbsolute)(name) ? name : (0, import_node_path25.join)(api.context.rootPath, name);
6450
+ if (!import_shared43.fse.existsSync(normalizedPath)) {
6336
6451
  continue;
6337
6452
  }
6338
6453
  try {
6339
- await import_shared51.fse.copy(normalizedPath, api.context.distPath, {
6454
+ await import_shared43.fse.copy(normalizedPath, api.context.distPath, {
6340
6455
  // dereference symlinks
6341
6456
  dereference: true
6342
6457
  });
@@ -6503,18 +6618,18 @@ function pluginModuleFederation() {
6503
6618
  chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
6504
6619
  }
6505
6620
  const publicPath = chain.output.get("publicPath");
6506
- if (publicPath === import_shared52.DEFAULT_ASSET_PREFIX) {
6621
+ if (publicPath === import_shared44.DEFAULT_ASSET_PREFIX) {
6507
6622
  chain.output.set("publicPath", "auto");
6508
6623
  }
6509
6624
  });
6510
6625
  }
6511
6626
  };
6512
6627
  }
6513
- var import_shared52, import_core8, PatchSplitChunksPlugin;
6628
+ var import_shared44, import_core8, PatchSplitChunksPlugin;
6514
6629
  var init_moduleFederation = __esm({
6515
6630
  "src/plugins/moduleFederation.ts"() {
6516
6631
  "use strict";
6517
- import_shared52 = require("@rsbuild/shared");
6632
+ import_shared44 = require("@rsbuild/shared");
6518
6633
  import_core8 = require("@rspack/core");
6519
6634
  PatchSplitChunksPlugin = class {
6520
6635
  constructor(name) {
@@ -6582,25 +6697,25 @@ __export(rspackProfile_exports, {
6582
6697
  pluginRspackProfile: () => pluginRspackProfile,
6583
6698
  stopProfiler: () => stopProfiler
6584
6699
  });
6585
- var import_node_inspector, import_node_path27, import_shared53, import_shared54, import_core9, stopProfiler, pluginRspackProfile;
6700
+ var import_node_inspector, import_node_path26, import_shared45, import_core9, stopProfiler, pluginRspackProfile;
6586
6701
  var init_rspackProfile = __esm({
6587
6702
  "src/plugins/rspackProfile.ts"() {
6588
6703
  "use strict";
6589
6704
  import_node_inspector = __toESM(require("inspector"));
6590
- import_node_path27 = __toESM(require("path"));
6591
- import_shared53 = require("@rsbuild/shared");
6592
- import_shared54 = require("@rsbuild/shared");
6705
+ import_node_path26 = __toESM(require("path"));
6706
+ import_shared45 = require("@rsbuild/shared");
6593
6707
  import_core9 = require("@rspack/core");
6708
+ init_logger();
6594
6709
  stopProfiler = (output, profileSession) => {
6595
6710
  if (!profileSession) {
6596
6711
  return;
6597
6712
  }
6598
6713
  profileSession.post("Profiler.stop", (error, param) => {
6599
6714
  if (error) {
6600
- import_shared54.logger.error("Failed to generate JS CPU profile:", error);
6715
+ import_rslog.logger.error("Failed to generate JS CPU profile:", error);
6601
6716
  return;
6602
6717
  }
6603
- import_shared53.fse.writeFileSync(output, JSON.stringify(param.profile));
6718
+ import_shared45.fse.writeFileSync(output, JSON.stringify(param.profile));
6604
6719
  });
6605
6720
  };
6606
6721
  pluginRspackProfile = () => ({
@@ -6614,7 +6729,7 @@ var init_rspackProfile = __esm({
6614
6729
  return;
6615
6730
  }
6616
6731
  const timestamp = Date.now();
6617
- const profileDir = import_node_path27.default.join(
6732
+ const profileDir = import_node_path26.default.join(
6618
6733
  api.context.distPath,
6619
6734
  `rspack-profile-${timestamp}`
6620
6735
  );
@@ -6622,11 +6737,11 @@ var init_rspackProfile = __esm({
6622
6737
  const enableProfileTrace = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("TRACE");
6623
6738
  const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
6624
6739
  const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
6625
- const traceFilePath = import_node_path27.default.join(profileDir, "trace.json");
6626
- const cpuProfilePath = import_node_path27.default.join(profileDir, "jscpuprofile.json");
6627
- const loggingFilePath = import_node_path27.default.join(profileDir, "logging.json");
6740
+ const traceFilePath = import_node_path26.default.join(profileDir, "trace.json");
6741
+ const cpuProfilePath = import_node_path26.default.join(profileDir, "jscpuprofile.json");
6742
+ const loggingFilePath = import_node_path26.default.join(profileDir, "logging.json");
6628
6743
  const onStart = () => {
6629
- import_shared53.fse.ensureDirSync(profileDir);
6744
+ import_shared45.fse.ensureDirSync(profileDir);
6630
6745
  if (enableProfileTrace) {
6631
6746
  import_core9.rspack.experimental_registerGlobalTrace(
6632
6747
  "trace",
@@ -6650,7 +6765,7 @@ var init_rspackProfile = __esm({
6650
6765
  logging: "verbose",
6651
6766
  loggingTrace: true
6652
6767
  });
6653
- import_shared53.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6768
+ import_shared45.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
6654
6769
  }
6655
6770
  });
6656
6771
  api.onExit(() => {
@@ -6658,7 +6773,7 @@ var init_rspackProfile = __esm({
6658
6773
  import_core9.rspack.experimental_cleanupGlobalTrace();
6659
6774
  }
6660
6775
  stopProfiler(cpuProfilePath, profileSession);
6661
- import_shared54.logger.info(`Saved Rspack profile file to ${profileDir}`);
6776
+ import_rslog.logger.info(`Saved Rspack profile file to ${profileDir}`);
6662
6777
  });
6663
6778
  }
6664
6779
  });
@@ -6670,16 +6785,16 @@ var lazyCompilation_exports = {};
6670
6785
  __export(lazyCompilation_exports, {
6671
6786
  pluginLazyCompilation: () => pluginLazyCompilation
6672
6787
  });
6673
- var import_shared55, pluginLazyCompilation;
6788
+ var pluginLazyCompilation;
6674
6789
  var init_lazyCompilation = __esm({
6675
6790
  "src/plugins/lazyCompilation.ts"() {
6676
6791
  "use strict";
6677
- import_shared55 = require("@rsbuild/shared");
6792
+ init_helpers();
6678
6793
  pluginLazyCompilation = () => ({
6679
6794
  name: "rsbuild:lazy-compilation",
6680
6795
  setup(api) {
6681
- api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
6682
- if (isProd6 || target !== "web") {
6796
+ api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
6797
+ if (isProd7 || target !== "web") {
6683
6798
  return;
6684
6799
  }
6685
6800
  const config = api.getNormalizedConfig();
@@ -6720,7 +6835,7 @@ var init_lazyCompilation = __esm({
6720
6835
  if (!name || isExcludedModule(name)) {
6721
6836
  return false;
6722
6837
  }
6723
- if ((0, import_shared55.isRegExp)(test)) {
6838
+ if (isRegExp(test)) {
6724
6839
  return name ? test.test(name) : false;
6725
6840
  }
6726
6841
  return test(module2);
@@ -6742,18 +6857,20 @@ var sri_exports = {};
6742
6857
  __export(sri_exports, {
6743
6858
  pluginSri: () => pluginSri
6744
6859
  });
6745
- var import_node_crypto2, import_shared56, getAssetName, pluginSri;
6860
+ var import_node_crypto2, import_shared46, getAssetName, pluginSri;
6746
6861
  var init_sri = __esm({
6747
6862
  "src/plugins/sri.ts"() {
6748
6863
  "use strict";
6749
6864
  import_node_crypto2 = __toESM(require("crypto"));
6750
- import_shared56 = require("@rsbuild/shared");
6865
+ import_shared46 = require("@rsbuild/shared");
6751
6866
  init_constants();
6867
+ init_helpers();
6868
+ init_logger();
6752
6869
  getAssetName = (url2, assetPrefix) => {
6753
6870
  if (url2.startsWith(assetPrefix)) {
6754
- return (0, import_shared56.removeLeadingSlash)(url2.replace(assetPrefix, ""));
6871
+ return removeLeadingSlash(url2.replace(assetPrefix, ""));
6755
6872
  }
6756
- return (0, import_shared56.removeLeadingSlash)(url2);
6873
+ return removeLeadingSlash(url2);
6757
6874
  };
6758
6875
  pluginSri = () => ({
6759
6876
  name: "rsbuild:sri",
@@ -6762,7 +6879,7 @@ var init_sri = __esm({
6762
6879
  const getAlgorithm = () => {
6763
6880
  const config = api.getNormalizedConfig();
6764
6881
  const { sri } = config.security;
6765
- const enable = sri.enable === "auto" ? (0, import_shared56.isProd)() : sri.enable;
6882
+ const enable = sri.enable === "auto" ? (0, import_shared46.isProd)() : sri.enable;
6766
6883
  if (!enable) {
6767
6884
  return null;
6768
6885
  }
@@ -6829,7 +6946,7 @@ var init_sri = __esm({
6829
6946
  `integrity="${integrity}"`
6830
6947
  );
6831
6948
  } else {
6832
- import_shared56.logger.debug(
6949
+ import_rslog.logger.debug(
6833
6950
  `[rsbuild:sri] failed to generate integrity for ${assetName}.`
6834
6951
  );
6835
6952
  replacedHtml = replacedHtml.replace(
@@ -6882,7 +6999,7 @@ var init_sri = __esm({
6882
6999
  }
6883
7000
  api.modifyBundlerChain((chain, { target }) => {
6884
7001
  const config = api.getNormalizedConfig();
6885
- if ((0, import_shared56.isHtmlDisabled)(config, target)) {
7002
+ if ((0, import_shared46.isHtmlDisabled)(config, target)) {
6886
7003
  return;
6887
7004
  }
6888
7005
  const algorithm = getAlgorithm();
@@ -6901,11 +7018,11 @@ var nonce_exports = {};
6901
7018
  __export(nonce_exports, {
6902
7019
  pluginNonce: () => pluginNonce
6903
7020
  });
6904
- var import_shared57, pluginNonce;
7021
+ var pluginNonce;
6905
7022
  var init_nonce = __esm({
6906
7023
  "src/plugins/nonce.ts"() {
6907
7024
  "use strict";
6908
- import_shared57 = require("@rsbuild/shared");
7025
+ init_helpers();
6909
7026
  pluginNonce = () => ({
6910
7027
  name: "rsbuild:nonce",
6911
7028
  setup(api) {
@@ -6914,7 +7031,7 @@ var init_nonce = __esm({
6914
7031
  if (!nonce) {
6915
7032
  return;
6916
7033
  }
6917
- (0, import_shared57.applyToCompiler)(compiler, (compiler2) => {
7034
+ applyToCompiler(compiler, (compiler2) => {
6918
7035
  const { plugins } = compiler2.options;
6919
7036
  const hasHTML = plugins.some(
6920
7037
  (plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
@@ -6922,7 +7039,7 @@ var init_nonce = __esm({
6922
7039
  if (!hasHTML) {
6923
7040
  return;
6924
7041
  }
6925
- const injectCode = (0, import_shared57.createVirtualModule)(
7042
+ const injectCode = createVirtualModule(
6926
7043
  `__webpack_nonce__ = "${nonce}";`
6927
7044
  );
6928
7045
  new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
@@ -6953,6 +7070,179 @@ var init_nonce = __esm({
6953
7070
  }
6954
7071
  });
6955
7072
 
7073
+ // src/server/prodServer.ts
7074
+ var prodServer_exports = {};
7075
+ __export(prodServer_exports, {
7076
+ RsbuildProdServer: () => RsbuildProdServer,
7077
+ startProdServer: () => startProdServer
7078
+ });
7079
+ async function startProdServer(context, config, { getPortSilently } = {}) {
7080
+ if (!(0, import_shared47.getNodeEnv)()) {
7081
+ (0, import_shared47.setNodeEnv)("production");
7082
+ }
7083
+ const { port, host, https } = await getServerConfig({
7084
+ config,
7085
+ getPortSilently
7086
+ });
7087
+ const { default: connect } = await import("../compiled/connect/index.js");
7088
+ const middlewares = connect();
7089
+ const serverConfig = config.server;
7090
+ const server = new RsbuildProdServer(
7091
+ {
7092
+ pwd: context.rootPath,
7093
+ output: {
7094
+ path: config.output.distPath.root || ROOT_DIST_DIR,
7095
+ assetPrefix: config.output.assetPrefix
7096
+ },
7097
+ serverConfig
7098
+ },
7099
+ middlewares
7100
+ );
7101
+ await context.hooks.onBeforeStartProdServer.call();
7102
+ const httpServer = await createHttpServer({
7103
+ serverConfig,
7104
+ middlewares: server.middlewares
7105
+ });
7106
+ await server.onInit(httpServer);
7107
+ return new Promise((resolve) => {
7108
+ httpServer.listen(
7109
+ {
7110
+ host,
7111
+ port
7112
+ },
7113
+ async () => {
7114
+ const routes = formatRoutes(
7115
+ context.entry,
7116
+ config.output.distPath.html,
7117
+ config.html.outputStructure
7118
+ );
7119
+ await context.hooks.onAfterStartProdServer.call({
7120
+ port,
7121
+ routes
7122
+ });
7123
+ const protocol = https ? "https" : "http";
7124
+ const urls = getAddressUrls({ protocol, port, host });
7125
+ printServerURLs({
7126
+ urls,
7127
+ port,
7128
+ routes,
7129
+ protocol,
7130
+ printUrls: serverConfig.printUrls
7131
+ });
7132
+ const onClose = () => {
7133
+ server.close();
7134
+ httpServer.close();
7135
+ };
7136
+ resolve({
7137
+ port,
7138
+ urls: urls.map((item) => item.url),
7139
+ server: {
7140
+ close: async () => {
7141
+ onClose();
7142
+ }
7143
+ }
7144
+ });
7145
+ }
7146
+ );
7147
+ });
7148
+ }
7149
+ var import_node_path27, import_shared47, RsbuildProdServer;
7150
+ var init_prodServer = __esm({
7151
+ "src/server/prodServer.ts"() {
7152
+ "use strict";
7153
+ import_node_path27 = require("path");
7154
+ import_shared47 = require("@rsbuild/shared");
7155
+ init_constants();
7156
+ init_logger();
7157
+ init_helper();
7158
+ init_httpServer();
7159
+ init_middlewares();
7160
+ RsbuildProdServer = class {
7161
+ constructor(options, middlewares) {
7162
+ __publicField(this, "app");
7163
+ __publicField(this, "options");
7164
+ __publicField(this, "middlewares");
7165
+ this.options = options;
7166
+ this.middlewares = middlewares;
7167
+ }
7168
+ // Complete the preparation of services
7169
+ async onInit(app) {
7170
+ this.app = app;
7171
+ await this.applyDefaultMiddlewares();
7172
+ }
7173
+ async applyDefaultMiddlewares() {
7174
+ const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
7175
+ if (import_rslog.logger.level === "verbose") {
7176
+ this.middlewares.use(await getRequestLoggerMiddleware());
7177
+ }
7178
+ if (compress) {
7179
+ const { default: compression } = await import("../compiled/http-compression/index.js");
7180
+ this.middlewares.use((req, res, next) => {
7181
+ compression({
7182
+ gzip: true,
7183
+ brotli: false
7184
+ })(req, res, next);
7185
+ });
7186
+ }
7187
+ if (headers) {
7188
+ this.middlewares.use((_req, res, next) => {
7189
+ for (const [key, value] of Object.entries(headers)) {
7190
+ res.setHeader(key, value);
7191
+ }
7192
+ next();
7193
+ });
7194
+ }
7195
+ if (proxy) {
7196
+ const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
7197
+ const { middlewares, upgrade } = createProxyMiddleware2(proxy);
7198
+ for (const middleware of middlewares) {
7199
+ this.middlewares.use(middleware);
7200
+ }
7201
+ this.app.on("upgrade", upgrade);
7202
+ }
7203
+ this.applyStaticAssetMiddleware();
7204
+ if (historyApiFallback) {
7205
+ const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
7206
+ const historyApiFallbackMiddleware = connectHistoryApiFallback(
7207
+ historyApiFallback === true ? {} : historyApiFallback
7208
+ );
7209
+ this.middlewares.use(historyApiFallbackMiddleware);
7210
+ await this.applyStaticAssetMiddleware();
7211
+ }
7212
+ this.middlewares.use(faviconFallbackMiddleware);
7213
+ }
7214
+ async applyStaticAssetMiddleware() {
7215
+ const {
7216
+ output: { path: path13, assetPrefix },
7217
+ serverConfig: { htmlFallback },
7218
+ pwd
7219
+ } = this.options;
7220
+ const { default: sirv } = await import("../compiled/sirv/index.js");
7221
+ const assetMiddleware = sirv((0, import_node_path27.join)(pwd, path13), {
7222
+ etag: true,
7223
+ dev: true,
7224
+ ignores: ["favicon.ico"],
7225
+ single: htmlFallback === "index"
7226
+ });
7227
+ this.middlewares.use((req, res, next) => {
7228
+ const url2 = req.url;
7229
+ if (assetPrefix && url2?.startsWith(assetPrefix)) {
7230
+ req.url = url2.slice(assetPrefix.length);
7231
+ assetMiddleware(req, res, (...args) => {
7232
+ req.url = url2;
7233
+ next(...args);
7234
+ });
7235
+ } else {
7236
+ assetMiddleware(req, res, next);
7237
+ }
7238
+ });
7239
+ }
7240
+ close() {
7241
+ }
7242
+ };
7243
+ }
7244
+ });
7245
+
6956
7246
  // src/createRsbuild.ts
6957
7247
  var createRsbuild_exports = {};
6958
7248
  __export(createRsbuild_exports, {
@@ -7048,9 +7338,9 @@ async function createRsbuild(options = {}) {
7048
7338
  );
7049
7339
  const pluginAPI = getPluginAPI({ context, pluginManager });
7050
7340
  context.pluginAPI = pluginAPI;
7051
- (0, import_shared58.debug)("add default plugins");
7341
+ import_rslog.logger.debug("add default plugins");
7052
7342
  await applyDefaultPlugins(pluginManager, context);
7053
- (0, import_shared58.debug)("add default plugins done");
7343
+ import_rslog.logger.debug("add default plugins done");
7054
7344
  const provider = rsbuildConfig.provider || await getRspackProvider();
7055
7345
  const providerInstance = await provider({
7056
7346
  context,
@@ -7058,14 +7348,19 @@ async function createRsbuild(options = {}) {
7058
7348
  rsbuildOptions,
7059
7349
  setCssExtractPlugin
7060
7350
  });
7351
+ const preview = async (options2) => {
7352
+ const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
7353
+ const config = await initRsbuildConfig({ context, pluginManager });
7354
+ return startProdServer2(context, config, options2);
7355
+ };
7061
7356
  const rsbuild = {
7062
- ...(0, import_shared58.pick)(pluginManager, [
7357
+ ...pick(pluginManager, [
7063
7358
  "addPlugins",
7064
7359
  "getPlugins",
7065
7360
  "removePlugins",
7066
7361
  "isPluginExists"
7067
7362
  ]),
7068
- ...(0, import_shared58.pick)(pluginAPI, [
7363
+ ...pick(pluginAPI, [
7069
7364
  "onBeforeBuild",
7070
7365
  "onBeforeCreateCompiler",
7071
7366
  "onBeforeStartDevServer",
@@ -7081,15 +7376,15 @@ async function createRsbuild(options = {}) {
7081
7376
  "getRsbuildConfig",
7082
7377
  "getNormalizedConfig"
7083
7378
  ]),
7084
- ...(0, import_shared58.pick)(providerInstance, [
7379
+ ...pick(providerInstance, [
7085
7380
  "build",
7086
- "preview",
7087
7381
  "initConfigs",
7088
7382
  "inspectConfig",
7089
7383
  "createCompiler",
7090
7384
  "createDevServer",
7091
7385
  "startDevServer"
7092
7386
  ]),
7387
+ preview,
7093
7388
  context: pluginAPI.context
7094
7389
  };
7095
7390
  if (rsbuildConfig.plugins) {
@@ -7098,13 +7393,15 @@ async function createRsbuild(options = {}) {
7098
7393
  }
7099
7394
  return rsbuild;
7100
7395
  }
7101
- var import_shared58, getRspackProvider, pickRsbuildConfig;
7396
+ var getRspackProvider, pickRsbuildConfig;
7102
7397
  var init_createRsbuild = __esm({
7103
7398
  "src/createRsbuild.ts"() {
7104
7399
  "use strict";
7105
- import_shared58 = require("@rsbuild/shared");
7106
7400
  init_createContext();
7401
+ init_helpers();
7107
7402
  init_initPlugins();
7403
+ init_internal();
7404
+ init_logger();
7108
7405
  init_pluginHelper();
7109
7406
  init_pluginManager();
7110
7407
  getRspackProvider = async () => {
@@ -7122,9 +7419,10 @@ var init_createRsbuild = __esm({
7122
7419
  "security",
7123
7420
  "performance",
7124
7421
  "moduleFederation",
7422
+ "environments",
7125
7423
  "_privateMeta"
7126
7424
  ];
7127
- return (0, import_shared58.pick)(rsbuildConfig, keys);
7425
+ return pick(rsbuildConfig, keys);
7128
7426
  };
7129
7427
  }
7130
7428
  });
@@ -7143,7 +7441,7 @@ async function init({
7143
7441
  cwd: root,
7144
7442
  mode: cliOptions?.envMode
7145
7443
  });
7146
- if ((0, import_shared59.isDev)()) {
7444
+ if ((0, import_shared48.isDev)()) {
7147
7445
  onBeforeRestartServer(envs.cleanup);
7148
7446
  }
7149
7447
  const { content: config, filePath: configFilePath } = await loadConfig({
@@ -7183,86 +7481,28 @@ async function init({
7183
7481
  });
7184
7482
  } catch (err) {
7185
7483
  if (isRestart) {
7186
- import_shared59.logger.error(err);
7484
+ import_rslog.logger.error(err);
7187
7485
  } else {
7188
7486
  throw err;
7189
7487
  }
7190
7488
  }
7191
7489
  }
7192
- var import_shared59, commonOpts;
7490
+ var import_shared48, commonOpts;
7193
7491
  var init_init = __esm({
7194
7492
  "src/cli/init.ts"() {
7195
7493
  "use strict";
7196
- import_shared59 = require("@rsbuild/shared");
7494
+ import_shared48 = require("@rsbuild/shared");
7197
7495
  init_config();
7198
7496
  init_loadEnv();
7497
+ init_logger();
7199
7498
  init_restart();
7200
7499
  commonOpts = {};
7201
7500
  }
7202
7501
  });
7203
7502
 
7204
- // src/index.ts
7205
- var src_exports = {};
7206
- __export(src_exports, {
7207
- PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
7208
- PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME,
7209
- __internalHelper: () => internal_exports,
7210
- createRsbuild: () => createRsbuild,
7211
- defineConfig: () => defineConfig,
7212
- loadConfig: () => loadConfig,
7213
- loadEnv: () => loadEnv,
7214
- logger: () => import_shared62.logger,
7215
- mergeRsbuildConfig: () => mergeRsbuildConfig,
7216
- rspack: () => import_core10.rspack,
7217
- version: () => version
7218
- });
7219
- module.exports = __toCommonJS(src_exports);
7220
- var import_core10 = require("@rspack/core");
7221
-
7222
- // src/internal.ts
7223
- var internal_exports = {};
7224
- __export(internal_exports, {
7225
- applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7226
- createDevServer: () => createDevServer,
7227
- createPluginManager: () => createPluginManager,
7228
- formatStats: () => formatStats,
7229
- getChainUtils: () => getChainUtils,
7230
- getDevMiddleware: () => getDevMiddleware,
7231
- getHTMLPlugin: () => getHTMLPlugin,
7232
- getStatsOptions: () => getStatsOptions,
7233
- getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7234
- initHooks: () => initHooks,
7235
- initPlugins: () => initPlugins,
7236
- initRsbuildConfig: () => initRsbuildConfig,
7237
- outputInspectConfigFiles: () => outputInspectConfigFiles,
7238
- prepareCli: () => prepareCli,
7239
- runCli: () => runCli,
7240
- setHTMLPlugin: () => setHTMLPlugin,
7241
- startProdServer: () => startProdServer,
7242
- stringifyConfig: () => stringifyConfig
7243
- });
7244
-
7245
7503
  // src/cli/commands.ts
7246
- var import_node_fs5 = require("fs");
7247
- var import_node_path28 = require("path");
7248
- var import_shared60 = require("@rsbuild/shared");
7249
- var import_commander = require("../compiled/commander/index.js");
7250
- init_helpers();
7251
- init_init();
7252
- var applyCommonOptions = (command) => {
7253
- command.option(
7254
- "-c --config <config>",
7255
- "specify the configuration file, can be a relative or absolute path"
7256
- ).option(
7257
- "--env-mode <mode>",
7258
- "specify the env mode to load the `.env.[mode]` file"
7259
- );
7260
- };
7261
- var applyServerOptions = (command) => {
7262
- command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
7263
- };
7264
7504
  function runCli() {
7265
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.7");
7505
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.7.9");
7266
7506
  const devCommand = import_commander.program.command("dev");
7267
7507
  const buildCommand = import_commander.program.command("build");
7268
7508
  const previewCommand = import_commander.program.command("preview");
@@ -7276,8 +7516,8 @@ function runCli() {
7276
7516
  const rsbuild = await init({ cliOptions: options });
7277
7517
  await rsbuild?.startDevServer();
7278
7518
  } catch (err) {
7279
- import_shared60.logger.error("Failed to start dev server.");
7280
- import_shared60.logger.error(err);
7519
+ import_rslog.logger.error("Failed to start dev server.");
7520
+ import_rslog.logger.error(err);
7281
7521
  process.exit(1);
7282
7522
  }
7283
7523
  });
@@ -7288,8 +7528,8 @@ function runCli() {
7288
7528
  watch: options.watch
7289
7529
  });
7290
7530
  } catch (err) {
7291
- import_shared60.logger.error("Failed to build.");
7292
- import_shared60.logger.error(err);
7531
+ import_rslog.logger.error("Failed to build.");
7532
+ import_rslog.logger.error(err);
7293
7533
  process.exit(1);
7294
7534
  }
7295
7535
  });
@@ -7300,14 +7540,14 @@ function runCli() {
7300
7540
  const { distPath } = rsbuild.context;
7301
7541
  if (!(0, import_node_fs5.existsSync)(distPath)) {
7302
7542
  throw new Error(
7303
- `The output directory ${import_shared60.color.yellow(
7543
+ `The output directory ${import_shared49.color.yellow(
7304
7544
  distPath
7305
7545
  )} does not exist, please build the project before previewing.`
7306
7546
  );
7307
7547
  }
7308
7548
  if (isEmptyDir(distPath)) {
7309
7549
  throw new Error(
7310
- `The output directory ${import_shared60.color.yellow(
7550
+ `The output directory ${import_shared49.color.yellow(
7311
7551
  distPath
7312
7552
  )} is empty, please build the project before previewing.`
7313
7553
  );
@@ -7315,8 +7555,8 @@ function runCli() {
7315
7555
  }
7316
7556
  await rsbuild?.preview();
7317
7557
  } catch (err) {
7318
- import_shared60.logger.error("Failed to start preview server.");
7319
- import_shared60.logger.error(err);
7558
+ import_rslog.logger.error("Failed to start preview server.");
7559
+ import_rslog.logger.error(err);
7320
7560
  process.exit(1);
7321
7561
  }
7322
7562
  });
@@ -7330,16 +7570,40 @@ function runCli() {
7330
7570
  writeToDisk: true
7331
7571
  });
7332
7572
  } catch (err) {
7333
- import_shared60.logger.error("Failed to inspect config.");
7334
- import_shared60.logger.error(err);
7573
+ import_rslog.logger.error("Failed to inspect config.");
7574
+ import_rslog.logger.error(err);
7335
7575
  process.exit(1);
7336
7576
  }
7337
7577
  });
7338
7578
  import_commander.program.parse();
7339
7579
  }
7580
+ var import_node_fs5, import_node_path28, import_shared49, import_commander, applyCommonOptions, applyServerOptions;
7581
+ var init_commands = __esm({
7582
+ "src/cli/commands.ts"() {
7583
+ "use strict";
7584
+ import_node_fs5 = require("fs");
7585
+ import_node_path28 = require("path");
7586
+ import_shared49 = require("@rsbuild/shared");
7587
+ import_commander = require("../compiled/commander/index.js");
7588
+ init_helpers();
7589
+ init_logger();
7590
+ init_init();
7591
+ applyCommonOptions = (command) => {
7592
+ command.option(
7593
+ "-c --config <config>",
7594
+ "specify the configuration file, can be a relative or absolute path"
7595
+ ).option(
7596
+ "--env-mode <mode>",
7597
+ "specify the env mode to load the `.env.[mode]` file"
7598
+ );
7599
+ };
7600
+ applyServerOptions = (command) => {
7601
+ command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
7602
+ };
7603
+ }
7604
+ });
7340
7605
 
7341
7606
  // src/cli/prepare.ts
7342
- var import_shared61 = require("@rsbuild/shared");
7343
7607
  function initNodeEnv() {
7344
7608
  if (!process.env.NODE_ENV) {
7345
7609
  const command = process.argv[2];
@@ -7352,34 +7616,89 @@ function prepareCli() {
7352
7616
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7353
7617
  console.log();
7354
7618
  }
7355
- import_shared61.logger.greet(` ${`Rsbuild v${"0.7.7"}`}
7619
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.7.9"}`}
7356
7620
  `);
7357
7621
  }
7622
+ var init_prepare = __esm({
7623
+ "src/cli/prepare.ts"() {
7624
+ "use strict";
7625
+ init_logger();
7626
+ }
7627
+ });
7358
7628
 
7359
7629
  // src/internal.ts
7360
- init_pluginManager();
7361
- init_initHooks();
7362
- init_initConfigs();
7363
- init_config();
7364
- init_pluginHelper();
7365
- init_helpers();
7366
- init_rspackConfig();
7367
- init_swc();
7368
- init_minimize();
7369
- init_devMiddleware();
7370
-
7371
- // src/server/index.ts
7372
- init_devServer();
7373
- init_prodServer();
7630
+ var internal_exports = {};
7631
+ __export(internal_exports, {
7632
+ TARGET_ID_MAP: () => TARGET_ID_MAP,
7633
+ applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7634
+ chainToConfig: () => chainToConfig,
7635
+ createDevServer: () => createDevServer,
7636
+ createPluginManager: () => createPluginManager,
7637
+ formatStats: () => formatStats,
7638
+ getChainUtils: () => getChainUtils,
7639
+ getDevMiddleware: () => getDevMiddleware,
7640
+ getHTMLPlugin: () => getHTMLPlugin,
7641
+ getStatsOptions: () => getStatsOptions,
7642
+ getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7643
+ initHooks: () => initHooks,
7644
+ initPlugins: () => initPlugins,
7645
+ initRsbuildConfig: () => initRsbuildConfig,
7646
+ modifyBundlerChain: () => modifyBundlerChain,
7647
+ onCompileDone: () => onCompileDone,
7648
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7649
+ prepareCli: () => prepareCli,
7650
+ runCli: () => runCli,
7651
+ setHTMLPlugin: () => setHTMLPlugin,
7652
+ stringifyConfig: () => stringifyConfig
7653
+ });
7654
+ var init_internal = __esm({
7655
+ "src/internal.ts"() {
7656
+ "use strict";
7657
+ init_commands();
7658
+ init_prepare();
7659
+ init_pluginManager();
7660
+ init_initHooks();
7661
+ init_initConfigs();
7662
+ init_config();
7663
+ init_pluginHelper();
7664
+ init_helpers();
7665
+ init_rspackConfig();
7666
+ init_configChain();
7667
+ init_swc();
7668
+ init_minimize();
7669
+ init_devMiddleware();
7670
+ init_devServer();
7671
+ init_constants();
7672
+ }
7673
+ });
7374
7674
 
7375
7675
  // src/index.ts
7676
+ var src_exports = {};
7677
+ __export(src_exports, {
7678
+ PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
7679
+ PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME,
7680
+ __internalHelper: () => internal_exports,
7681
+ createRsbuild: () => createRsbuild,
7682
+ defineConfig: () => defineConfig,
7683
+ ensureAssetPrefix: () => ensureAssetPrefix,
7684
+ loadConfig: () => loadConfig,
7685
+ loadEnv: () => loadEnv,
7686
+ logger: () => import_rslog.logger,
7687
+ mergeRsbuildConfig: () => mergeRsbuildConfig,
7688
+ rspack: () => import_core10.rspack,
7689
+ version: () => version
7690
+ });
7691
+ module.exports = __toCommonJS(src_exports);
7692
+ var import_core10 = require("@rspack/core");
7693
+ init_internal();
7376
7694
  init_loadEnv();
7377
7695
  init_createRsbuild();
7378
7696
  init_config();
7379
- var import_shared62 = require("@rsbuild/shared");
7697
+ init_logger();
7380
7698
  init_mergeConfig();
7699
+ init_helpers();
7381
7700
  init_constants();
7382
- var version = "0.7.7";
7701
+ var version = "0.7.9";
7383
7702
  // Annotate the CommonJS export names for ESM import in node:
7384
7703
  0 && (module.exports = {
7385
7704
  PLUGIN_CSS_NAME,
@@ -7387,6 +7706,7 @@ var version = "0.7.7";
7387
7706
  __internalHelper,
7388
7707
  createRsbuild,
7389
7708
  defineConfig,
7709
+ ensureAssetPrefix,
7390
7710
  loadConfig,
7391
7711
  loadEnv,
7392
7712
  logger,