@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.js CHANGED
@@ -23,12 +23,12 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
 
26
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
26
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
27
27
  import { fileURLToPath } from "url";
28
28
  import path from "path";
29
29
  var getFilename, getDirname, __dirname, __filename;
30
30
  var init_esm = __esm({
31
- "../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
31
+ "../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
32
32
  "use strict";
33
33
  getFilename = () => fileURLToPath(import.meta.url);
34
34
  getDirname = () => path.dirname(getFilename());
@@ -122,7 +122,7 @@ var init_format = __esm({
122
122
 
123
123
  // src/constants.ts
124
124
  import { join } from "path";
125
- var 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;
125
+ var 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;
126
126
  var init_constants = __esm({
127
127
  "src/constants.ts"() {
128
128
  "use strict";
@@ -169,19 +169,59 @@ var init_constants = __esm({
169
169
  ];
170
170
  VIDEO_EXTENSIONS = ["mp4", "webm", "ogg", "mov"];
171
171
  AUDIO_EXTENSIONS = ["mp3", "wav", "flac", "aac", "m4a", "opus"];
172
+ TARGET_ID_MAP = {
173
+ web: "Client",
174
+ node: "Server",
175
+ "web-worker": "Web Worker",
176
+ "service-worker": "Service Worker"
177
+ };
178
+ }
179
+ });
180
+
181
+ // src/logger.ts
182
+ import { color } from "@rsbuild/shared";
183
+ import { logger } from "../compiled/rslog/index.js";
184
+ function getTime() {
185
+ const now = /* @__PURE__ */ new Date();
186
+ const hours = String(now.getHours()).padStart(2, "0");
187
+ const minutes = String(now.getMinutes()).padStart(2, "0");
188
+ const seconds = String(now.getSeconds()).padStart(2, "0");
189
+ return `${hours}:${minutes}:${seconds}`;
190
+ }
191
+ var isDebug;
192
+ var init_logger = __esm({
193
+ "src/logger.ts"() {
194
+ "use strict";
195
+ init_esm();
196
+ isDebug = () => {
197
+ if (!process.env.DEBUG) {
198
+ return false;
199
+ }
200
+ const values = process.env.DEBUG.toLocaleLowerCase().split(",");
201
+ return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
202
+ };
203
+ if (isDebug()) {
204
+ logger.level = "verbose";
205
+ }
206
+ logger.override({
207
+ debug: (message, ...args) => {
208
+ if (logger.level !== "verbose") {
209
+ return;
210
+ }
211
+ const time = color.gray(`${getTime()}`);
212
+ console.log(` ${color.magenta("rsbuild")} ${time} ${message}`, ...args);
213
+ }
214
+ });
172
215
  }
173
216
  });
174
217
 
175
218
  // src/helpers.ts
176
- import path2 from "path";
219
+ import path2, { posix } from "path";
177
220
  import {
178
221
  DEFAULT_ASSET_PREFIX,
179
- addTrailingSlash,
180
- color,
181
- isDebug,
182
- isMultiCompiler,
183
- isProd,
184
- removeTailingSlash
222
+ castArray,
223
+ color as color2,
224
+ isProd
185
225
  } from "@rsbuild/shared";
186
226
  import { fse } from "@rsbuild/shared";
187
227
  function formatErrorMessage(errors) {
@@ -189,14 +229,14 @@ function formatErrorMessage(errors) {
189
229
  const text = `${messages.join("\n\n")}
190
230
  `;
191
231
  const isTerserError = text.includes("from Terser");
192
- const title = color.bold(
193
- color.red(isTerserError ? "Minify error: " : "Compile error: ")
232
+ const title = color2.bold(
233
+ color2.red(isTerserError ? "Minify error: " : "Compile error: ")
194
234
  );
195
235
  if (!errors.length) {
196
236
  return `${title}
197
- ${color.yellow(`For more details, please setting 'stats.errors: true' `)}`;
237
+ ${color2.yellow(`For more details, please setting 'stats.errors: true' `)}`;
198
238
  }
199
- const tip = color.yellow(
239
+ const tip = color2.yellow(
200
240
  isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
201
241
  );
202
242
  return `${title}
@@ -227,7 +267,7 @@ function formatStats(stats, options = {}) {
227
267
  warnings: getAllStatsWarnings(statsData)
228
268
  },
229
269
  // display verbose messages in prod build or debug mode
230
- isProd() || isDebug()
270
+ isProd() || logger.level === "verbose"
231
271
  );
232
272
  if (stats.hasErrors()) {
233
273
  return {
@@ -236,7 +276,7 @@ function formatStats(stats, options = {}) {
236
276
  };
237
277
  }
238
278
  if (warnings.length) {
239
- const title = color.bold(color.yellow("Compile Warning: \n"));
279
+ const title = color2.bold(color2.yellow("Compile Warning: \n"));
240
280
  return {
241
281
  message: `${title}${warnings.join("\n\n")}
242
282
  `,
@@ -252,13 +292,78 @@ function isEmptyDir(path14) {
252
292
  async function isFileExists(file) {
253
293
  return fse.promises.access(file, fse.constants.F_OK).then(() => true).catch(() => false);
254
294
  }
255
- var rspackMinVersion, compareSemver, isSatisfyRspackVersion, getCompiledPath, hintNodePolyfill, getAllStatsErrors, getAllStatsWarnings, formatPublicPath, getPublicPathFromChain, ensureAbsolutePath, isFileSync, findExists;
295
+ function getFilename2(config, type, isProd7) {
296
+ const { filename, filenameHash } = config.output;
297
+ const getHash = () => {
298
+ if (typeof filenameHash === "string") {
299
+ return filenameHash ? `.[${filenameHash}]` : "";
300
+ }
301
+ return filenameHash ? ".[contenthash:8]" : "";
302
+ };
303
+ const hash = getHash();
304
+ switch (type) {
305
+ case "js":
306
+ return filename.js ?? `[name]${isProd7 ? hash : ""}.js`;
307
+ case "css":
308
+ return filename.css ?? `[name]${isProd7 ? hash : ""}.css`;
309
+ case "svg":
310
+ return filename.svg ?? `[name]${hash}.svg`;
311
+ case "font":
312
+ return filename.font ?? `[name]${hash}[ext]`;
313
+ case "image":
314
+ return filename.image ?? `[name]${hash}[ext]`;
315
+ case "media":
316
+ return filename.media ?? `[name]${hash}[ext]`;
317
+ default:
318
+ throw new Error(`unknown key ${type} in "output.filename"`);
319
+ }
320
+ }
321
+ function partition(array, predicate) {
322
+ const truthy = [];
323
+ const falsy = [];
324
+ for (const value of array) {
325
+ if (predicate(value)) {
326
+ truthy.push(value);
327
+ } else {
328
+ falsy.push(value);
329
+ }
330
+ }
331
+ return [truthy, falsy];
332
+ }
333
+ function debounce(func, wait) {
334
+ let timeoutId = null;
335
+ return (...args) => {
336
+ if (timeoutId !== null) {
337
+ clearTimeout(timeoutId);
338
+ }
339
+ timeoutId = setTimeout(() => {
340
+ func(...args);
341
+ }, wait);
342
+ };
343
+ }
344
+ function isWebTarget(target) {
345
+ const targets = castArray(target);
346
+ return targets.includes("web") || target.includes("web-worker");
347
+ }
348
+ function pick(obj, keys) {
349
+ return keys.reduce(
350
+ (ret, key) => {
351
+ if (obj[key] !== void 0) {
352
+ ret[key] = obj[key];
353
+ }
354
+ return ret;
355
+ },
356
+ {}
357
+ );
358
+ }
359
+ var 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;
256
360
  var init_helpers = __esm({
257
361
  "src/helpers.ts"() {
258
362
  "use strict";
259
363
  init_esm();
260
364
  init_format();
261
365
  init_constants();
366
+ init_logger();
262
367
  rspackMinVersion = "0.6.2";
263
368
  compareSemver = (version1, version2) => {
264
369
  const parts1 = version1.split(".").map(Number);
@@ -343,7 +448,7 @@ var init_helpers = __esm({
343
448
  ];
344
449
  return `${message}
345
450
 
346
- ${color.yellow(tips.join("\n"))}`;
451
+ ${color2.yellow(tips.join("\n"))}`;
347
452
  }
348
453
  return message;
349
454
  };
@@ -365,6 +470,9 @@ ${color.yellow(tips.join("\n"))}`;
365
470
  }
366
471
  return statsData.warnings;
367
472
  };
473
+ removeLeadingSlash = (s) => s.replace(/^\/+/, "");
474
+ removeTailingSlash = (s) => s.replace(/\/+$/, "");
475
+ addTrailingSlash = (s) => s.endsWith("/") ? s : `${s}/`;
368
476
  formatPublicPath = (publicPath, withSlash = true) => {
369
477
  if (publicPath === "auto") {
370
478
  return publicPath;
@@ -394,12 +502,84 @@ ${color.yellow(tips.join("\n"))}`;
394
502
  }
395
503
  return false;
396
504
  };
505
+ urlJoin = (base, path14) => {
506
+ const fullUrl = new URL(base);
507
+ fullUrl.pathname = posix.join(fullUrl.pathname, path14);
508
+ return fullUrl.toString();
509
+ };
510
+ canParse = (url2) => {
511
+ try {
512
+ new URL(url2);
513
+ return true;
514
+ } catch {
515
+ return false;
516
+ }
517
+ };
518
+ ensureAssetPrefix = (url2, assetPrefix) => {
519
+ if (url2.startsWith("//")) {
520
+ return url2;
521
+ }
522
+ if (canParse(url2)) {
523
+ return url2;
524
+ }
525
+ if (assetPrefix.startsWith("http")) {
526
+ return urlJoin(assetPrefix, url2);
527
+ }
528
+ if (assetPrefix.startsWith("//")) {
529
+ return urlJoin(`https:${assetPrefix}`, url2).replace("https:", "");
530
+ }
531
+ return posix.join(assetPrefix, url2);
532
+ };
533
+ applyToCompiler = (compiler, apply) => {
534
+ if (isMultiCompiler(compiler)) {
535
+ compiler.compilers.forEach(apply);
536
+ } else {
537
+ apply(compiler);
538
+ }
539
+ };
540
+ upperFirst = (str) => str ? str.charAt(0).toUpperCase() + str.slice(1) : "";
541
+ isURL = (str) => str.startsWith("http") || str.startsWith("//:");
542
+ createVirtualModule = (content) => `data:text/javascript,${content}`;
543
+ isRegExp = (obj) => Object.prototype.toString.call(obj) === "[object RegExp]";
544
+ isMultiCompiler = (compiler) => {
545
+ return compiler.constructor.name === "MultiCompiler";
546
+ };
547
+ onCompileDone = (compiler, onDone, MultiStatsCtor) => {
548
+ if (isMultiCompiler(compiler)) {
549
+ const { compilers } = compiler;
550
+ const compilerStats = [];
551
+ let doneCompilers = 0;
552
+ for (let index = 0; index < compilers.length; index++) {
553
+ const compiler2 = compilers[index];
554
+ const compilerIndex = index;
555
+ let compilerDone = false;
556
+ compiler2.hooks.done.tapPromise("rsbuild:done", async (stats) => {
557
+ if (!compilerDone) {
558
+ compilerDone = true;
559
+ doneCompilers++;
560
+ }
561
+ compilerStats[compilerIndex] = stats;
562
+ if (doneCompilers === compilers.length) {
563
+ await onDone(new MultiStatsCtor(compilerStats));
564
+ }
565
+ });
566
+ compiler2.hooks.invalid.tap("rsbuild:done", () => {
567
+ if (compilerDone) {
568
+ compilerDone = false;
569
+ doneCompilers--;
570
+ }
571
+ });
572
+ }
573
+ } else {
574
+ compiler.hooks.done.tapPromise("rsbuild:done", onDone);
575
+ }
576
+ };
397
577
  }
398
578
  });
399
579
 
400
580
  // src/mergeConfig.ts
401
581
  import {
402
- castArray,
582
+ castArray as castArray2,
403
583
  isFunction,
404
584
  isPlainObject
405
585
  } from "@rsbuild/shared";
@@ -433,7 +613,7 @@ var init_mergeConfig = __esm({
433
613
  }
434
614
  const pair = [x, y];
435
615
  if (pair.some(Array.isArray)) {
436
- return [...castArray(x), ...castArray(y)];
616
+ return [...castArray2(x), ...castArray2(y)];
437
617
  }
438
618
  if (pair.some(isFunction)) {
439
619
  return pair;
@@ -466,13 +646,14 @@ var init_mergeConfig = __esm({
466
646
 
467
647
  // src/server/restart.ts
468
648
  import path3 from "path";
469
- import { color as color2, logger } from "@rsbuild/shared";
649
+ import { color as color3 } from "@rsbuild/shared";
470
650
  var cleaners, onBeforeRestartServer, clearConsole, restartDevServer;
471
651
  var init_restart = __esm({
472
652
  "src/server/restart.ts"() {
473
653
  "use strict";
474
654
  init_esm();
475
655
  init_init();
656
+ init_logger();
476
657
  cleaners = [];
477
658
  onBeforeRestartServer = (cleaner) => {
478
659
  cleaners.push(cleaner);
@@ -485,7 +666,7 @@ var init_restart = __esm({
485
666
  restartDevServer = async ({ filePath }) => {
486
667
  clearConsole();
487
668
  const filename = path3.basename(filePath);
488
- logger.info(`Restart because ${color2.yellow(filename)} is changed.
669
+ logger.info(`Restart because ${color3.yellow(filename)} is changed.
489
670
  `);
490
671
  for (const cleaner of cleaners) {
491
672
  await cleaner();
@@ -506,13 +687,10 @@ import { isAbsolute, join as join2 } from "path";
506
687
  import {
507
688
  DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX2,
508
689
  RspackChain,
509
- color as color3,
510
- debounce,
690
+ color as color4,
511
691
  fse as fse2,
512
692
  getNodeEnv,
513
- isObject,
514
- logger as logger2,
515
- upperFirst
693
+ isObject
516
694
  } from "@rsbuild/shared";
517
695
  function getDefaultEntry(root) {
518
696
  const files = [
@@ -576,7 +754,7 @@ async function loadConfig({
576
754
  return config;
577
755
  };
578
756
  try {
579
- const { default: jiti } = await import("@rsbuild/shared/jiti");
757
+ const { default: jiti } = await import("../compiled/jiti/index.js");
580
758
  const loadConfig2 = jiti(__filename, {
581
759
  esmResolve: true,
582
760
  // disable require cache to support restart CLI and read the new config
@@ -593,7 +771,7 @@ async function loadConfig({
593
771
  };
594
772
  const result = await configExport(params);
595
773
  if (result === void 0) {
596
- throw new Error("Rsbuild config function must return a config object.");
774
+ throw new Error("The config function must return a config object.");
597
775
  }
598
776
  return {
599
777
  content: applyMetaInfo(result),
@@ -602,7 +780,7 @@ async function loadConfig({
602
780
  }
603
781
  if (!isObject(configExport)) {
604
782
  throw new Error(
605
- `Rsbuild config must be an object or a function that returns an object, get ${color3.yellow(
783
+ `The config must be an object or a function that returns an object, get ${color4.yellow(
606
784
  configExport
607
785
  )}`
608
786
  );
@@ -612,7 +790,7 @@ async function loadConfig({
612
790
  filePath: configFilePath
613
791
  };
614
792
  } catch (err) {
615
- logger2.error(`Failed to load file: ${color3.dim(configFilePath)}`);
793
+ logger.error(`Failed to load file: ${color4.dim(configFilePath)}`);
616
794
  throw err;
617
795
  }
618
796
  }
@@ -650,11 +828,11 @@ async function outputInspectConfigFiles({
650
828
  )
651
829
  );
652
830
  const fileInfos = files.map(
653
- (item) => ` - ${color3.bold(color3.yellow(item.label))}: ${color3.underline(
831
+ (item) => ` - ${color4.bold(color4.yellow(item.label))}: ${color4.underline(
654
832
  item.path
655
833
  )}`
656
834
  ).join("\n");
657
- logger2.success(
835
+ logger.success(
658
836
  `Inspect config succeed, open following files to view the content:
659
837
 
660
838
  ${fileInfos}
@@ -672,6 +850,7 @@ var init_config = __esm({
672
850
  init_esm();
673
851
  init_constants();
674
852
  init_helpers();
853
+ init_logger();
675
854
  init_mergeConfig();
676
855
  init_restart();
677
856
  getDefaultDevConfig = () => ({
@@ -812,7 +991,7 @@ var init_config = __esm({
812
991
  if (fs.existsSync(customConfigPath)) {
813
992
  return customConfigPath;
814
993
  }
815
- logger2.warn(`Cannot find config file: ${color3.dim(customConfigPath)}
994
+ logger.warn(`Cannot find config file: ${color4.dim(customConfigPath)}
816
995
  `);
817
996
  }
818
997
  const CONFIG_FILES = [
@@ -993,9 +1172,8 @@ __export(entry_exports, {
993
1172
  pluginEntry: () => pluginEntry
994
1173
  });
995
1174
  import {
996
- castArray as castArray2,
997
- color as color4,
998
- createVirtualModule,
1175
+ castArray as castArray3,
1176
+ color as color5,
999
1177
  reduceConfigsMergeContext
1000
1178
  } from "@rsbuild/shared";
1001
1179
  function getEntryObject(config, target) {
@@ -1013,6 +1191,7 @@ var init_entry = __esm({
1013
1191
  "src/plugins/entry.ts"() {
1014
1192
  "use strict";
1015
1193
  init_esm();
1194
+ init_helpers();
1016
1195
  pluginEntry = () => ({
1017
1196
  name: "rsbuild:entry",
1018
1197
  setup(api) {
@@ -1031,16 +1210,16 @@ var init_entry = __esm({
1031
1210
  if (injectCoreJsEntry) {
1032
1211
  addEntry(createVirtualModule('import "core-js";'));
1033
1212
  }
1034
- castArray2(entry[entryName]).forEach(addEntry);
1213
+ castArray3(entry[entryName]).forEach(addEntry);
1035
1214
  }
1036
1215
  }
1037
1216
  );
1038
1217
  api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
1039
1218
  if (bundlerConfigs.every((config) => !config.entry)) {
1040
1219
  throw new Error(
1041
- `Could not find any entry module, please make sure that ${color4.cyan(
1220
+ `Could not find any entry module, please make sure that ${color5.cyan(
1042
1221
  "src/index.(ts|js|tsx|jsx|mjs|cjs)"
1043
- )} exists, or customize entry through the ${color4.cyan(
1222
+ )} exists, or customize entry through the ${color5.cyan(
1044
1223
  "source.entry"
1045
1224
  )} configuration.`
1046
1225
  );
@@ -1053,15 +1232,11 @@ var init_entry = __esm({
1053
1232
 
1054
1233
  // src/createContext.ts
1055
1234
  import { isAbsolute as isAbsolute2, join as join4 } from "path";
1056
- import {
1057
- getDistPath,
1058
- logger as logger3
1059
- } from "@rsbuild/shared";
1060
1235
  function getAbsolutePath(root, filepath) {
1061
1236
  return isAbsolute2(filepath) ? filepath : join4(root, filepath);
1062
1237
  }
1063
1238
  function getAbsoluteDistPath(cwd, config) {
1064
- const dirRoot = getDistPath(config, "root");
1239
+ const dirRoot = config.output?.distPath?.root ?? ROOT_DIST_DIR;
1065
1240
  return getAbsolutePath(cwd, dirRoot);
1066
1241
  }
1067
1242
  async function createContextByConfig(options, bundlerType, config = {}) {
@@ -1073,7 +1248,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
1073
1248
  return {
1074
1249
  entry: getEntryObject(config, "web"),
1075
1250
  targets: config.output?.targets || [],
1076
- version: "0.7.7",
1251
+ version: "0.7.9",
1077
1252
  rootPath,
1078
1253
  distPath,
1079
1254
  cachePath,
@@ -1115,7 +1290,7 @@ function createPublicContext(context) {
1115
1290
  return void 0;
1116
1291
  },
1117
1292
  set(_, prop) {
1118
- logger3.error(
1293
+ logger.error(
1119
1294
  `Context is readonly, you can not assign to the "context.${prop}" prop.`
1120
1295
  );
1121
1296
  return true;
@@ -1141,21 +1316,18 @@ var init_createContext = __esm({
1141
1316
  "use strict";
1142
1317
  init_esm();
1143
1318
  init_config();
1319
+ init_constants();
1144
1320
  init_initHooks();
1321
+ init_logger();
1145
1322
  init_entry();
1146
1323
  }
1147
1324
  });
1148
1325
 
1149
1326
  // src/initPlugins.ts
1150
1327
  import { join as join5 } from "path";
1151
- import {
1152
- getDistPath as getDistPath2,
1153
- removeLeadingSlash
1154
- } from "@rsbuild/shared";
1155
1328
  function getHTMLPathByEntry(entryName, config) {
1156
- const htmlPath = getDistPath2(config, "html");
1157
1329
  const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
1158
- return removeLeadingSlash(`${htmlPath}/${filename}`);
1330
+ return removeLeadingSlash(`${config.output.distPath.html}/${filename}`);
1159
1331
  }
1160
1332
  function applyTransformPlugin(chain, transformer) {
1161
1333
  const name = "RsbuildTransformPlugin";
@@ -1278,6 +1450,7 @@ var init_initPlugins = __esm({
1278
1450
  init_esm();
1279
1451
  init_constants();
1280
1452
  init_createContext();
1453
+ init_helpers();
1281
1454
  }
1282
1455
  });
1283
1456
 
@@ -1312,7 +1485,7 @@ var init_pluginHelper = __esm({
1312
1485
  });
1313
1486
 
1314
1487
  // src/pluginManager.ts
1315
- import { color as color5, debug, isFunction as isFunction3, logger as logger4 } from "@rsbuild/shared";
1488
+ import { color as color6, isFunction as isFunction3 } from "@rsbuild/shared";
1316
1489
  function validatePlugin(plugin) {
1317
1490
  const type = typeof plugin;
1318
1491
  if (type !== "object" || plugin === null) {
@@ -1326,12 +1499,12 @@ function validatePlugin(plugin) {
1326
1499
  if (isFunction3(plugin.apply)) {
1327
1500
  const { name = "SomeWebpackPlugin" } = plugin.constructor || {};
1328
1501
  const messages = [
1329
- `${color5.yellow(
1502
+ `${color6.yellow(
1330
1503
  name
1331
- )} looks like a Webpack or Rspack plugin, please use ${color5.yellow(
1504
+ )} looks like a Webpack or Rspack plugin, please use ${color6.yellow(
1332
1505
  "`tools.rspack`"
1333
1506
  )} to register it:`,
1334
- color5.green(`
1507
+ color6.green(`
1335
1508
  // rsbuild.config.ts
1336
1509
  export default {
1337
1510
  tools: {
@@ -1358,13 +1531,13 @@ function createPluginManager() {
1358
1531
  }
1359
1532
  validatePlugin(newPlugin);
1360
1533
  if (plugins.find((item) => item.name === newPlugin.name)) {
1361
- logger4.warn(
1534
+ logger.warn(
1362
1535
  `Rsbuild plugin "${newPlugin.name}" registered multiple times.`
1363
1536
  );
1364
1537
  } else if (before) {
1365
1538
  const index = plugins.findIndex((item) => item.name === before);
1366
1539
  if (index === -1) {
1367
- logger4.warn(`Plugin "${before}" does not exist.`);
1540
+ logger.warn(`Plugin "${before}" does not exist.`);
1368
1541
  plugins.push(newPlugin);
1369
1542
  } else {
1370
1543
  plugins.splice(index, 0, newPlugin);
@@ -1389,7 +1562,7 @@ async function initPlugins({
1389
1562
  pluginAPI,
1390
1563
  pluginManager
1391
1564
  }) {
1392
- debug("init plugins");
1565
+ logger.debug("init plugins");
1393
1566
  const plugins = pluginDagSort(pluginManager.getPlugins());
1394
1567
  const removedPlugins = plugins.reduce((ret, plugin) => {
1395
1568
  if (plugin.remove) {
@@ -1403,13 +1576,14 @@ async function initPlugins({
1403
1576
  }
1404
1577
  await plugin.setup(pluginAPI);
1405
1578
  }
1406
- debug("init plugins done");
1579
+ logger.debug("init plugins done");
1407
1580
  }
1408
1581
  var pluginDagSort;
1409
1582
  var init_pluginManager = __esm({
1410
1583
  "src/pluginManager.ts"() {
1411
1584
  "use strict";
1412
1585
  init_esm();
1586
+ init_logger();
1413
1587
  pluginDagSort = (plugins) => {
1414
1588
  let allLines = [];
1415
1589
  function getPlugin(name) {
@@ -1541,19 +1715,81 @@ var init_inspectConfig = __esm({
1541
1715
  }
1542
1716
  });
1543
1717
 
1718
+ // src/configChain.ts
1719
+ import {
1720
+ RspackChain as RspackChain2,
1721
+ castArray as castArray4,
1722
+ isPlainObject as isPlainObject2
1723
+ } from "@rsbuild/shared";
1724
+ async function getBundlerChain() {
1725
+ const bundlerChain = new RspackChain2();
1726
+ return bundlerChain;
1727
+ }
1728
+ async function modifyBundlerChain(context, utils) {
1729
+ logger.debug("modify bundler chain");
1730
+ const bundlerChain = await getBundlerChain();
1731
+ const [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.call(
1732
+ bundlerChain,
1733
+ utils
1734
+ );
1735
+ if (context.config.tools?.bundlerChain) {
1736
+ for (const item of castArray4(context.config.tools.bundlerChain)) {
1737
+ await item(modifiedBundlerChain, utils);
1738
+ }
1739
+ }
1740
+ logger.debug("modify bundler chain done");
1741
+ return modifiedBundlerChain;
1742
+ }
1743
+ function chainToConfig(chain) {
1744
+ const config = chain.toConfig();
1745
+ const { entry } = config;
1746
+ if (!isPlainObject2(entry)) {
1747
+ return config;
1748
+ }
1749
+ const formattedEntry = {};
1750
+ for (const [entryName, entryValue] of Object.entries(entry)) {
1751
+ const entryImport = [];
1752
+ let entryDescription = null;
1753
+ for (const item of castArray4(entryValue)) {
1754
+ if (typeof item === "string") {
1755
+ entryImport.push(item);
1756
+ continue;
1757
+ }
1758
+ if (item.import) {
1759
+ entryImport.push(...castArray4(item.import));
1760
+ }
1761
+ if (entryDescription) {
1762
+ Object.assign(entryDescription, item);
1763
+ } else {
1764
+ entryDescription = item;
1765
+ }
1766
+ }
1767
+ formattedEntry[entryName] = entryDescription ? {
1768
+ ...entryDescription,
1769
+ import: entryImport
1770
+ } : entryImport;
1771
+ }
1772
+ config.entry = formattedEntry;
1773
+ return config;
1774
+ }
1775
+ var init_configChain = __esm({
1776
+ "src/configChain.ts"() {
1777
+ "use strict";
1778
+ init_esm();
1779
+ init_logger();
1780
+ }
1781
+ });
1782
+
1544
1783
  // src/provider/rspackConfig.ts
1545
1784
  import {
1546
1785
  CHAIN_ID,
1547
- castArray as castArray3,
1548
- chainToConfig,
1549
- debug as debug2,
1786
+ castArray as castArray5,
1550
1787
  getNodeEnv as getNodeEnv4,
1551
- modifyBundlerChain,
1552
1788
  reduceConfigsAsyncWithContext
1553
1789
  } from "@rsbuild/shared";
1554
1790
  import { rspack as rspack2 } from "@rspack/core";
1555
1791
  async function modifyRspackConfig(context, rspackConfig, utils) {
1556
- debug2("modify Rspack config");
1792
+ logger.debug("modify Rspack config");
1557
1793
  let [modifiedConfig] = await context.hooks.modifyRspackConfig.call(
1558
1794
  rspackConfig,
1559
1795
  utils
@@ -1566,7 +1802,7 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
1566
1802
  mergeFn: utils.mergeConfig
1567
1803
  });
1568
1804
  }
1569
- debug2("modify Rspack config done");
1805
+ logger.debug("modify Rspack config done");
1570
1806
  return modifiedConfig;
1571
1807
  }
1572
1808
  async function getConfigUtils(config, chainUtils) {
@@ -1576,7 +1812,7 @@ async function getConfigUtils(config, chainUtils) {
1576
1812
  rspack: rspack2,
1577
1813
  mergeConfig: merge2,
1578
1814
  addRules(rules) {
1579
- const ruleArr = castArray3(rules);
1815
+ const ruleArr = castArray5(rules);
1580
1816
  if (!config.module) {
1581
1817
  config.module = {};
1582
1818
  }
@@ -1586,14 +1822,14 @@ async function getConfigUtils(config, chainUtils) {
1586
1822
  config.module.rules.unshift(...ruleArr);
1587
1823
  },
1588
1824
  prependPlugins(plugins) {
1589
- const pluginArr = castArray3(plugins);
1825
+ const pluginArr = castArray5(plugins);
1590
1826
  if (!config.plugins) {
1591
1827
  config.plugins = [];
1592
1828
  }
1593
1829
  config.plugins.unshift(...pluginArr);
1594
1830
  },
1595
1831
  appendPlugins(plugins) {
1596
- const pluginArr = castArray3(plugins);
1832
+ const pluginArr = castArray5(plugins);
1597
1833
  if (!config.plugins) {
1598
1834
  config.plugins = [];
1599
1835
  }
@@ -1656,23 +1892,21 @@ var init_rspackConfig = __esm({
1656
1892
  "src/provider/rspackConfig.ts"() {
1657
1893
  "use strict";
1658
1894
  init_esm();
1895
+ init_configChain();
1896
+ init_logger();
1659
1897
  init_pluginHelper();
1660
1898
  }
1661
1899
  });
1662
1900
 
1663
1901
  // src/provider/initConfigs.ts
1664
- import {
1665
- debug as debug3,
1666
- isDebug as isDebug2
1667
- } from "@rsbuild/shared";
1668
1902
  async function modifyRsbuildConfig(context) {
1669
- debug3("modify Rsbuild config");
1903
+ logger.debug("modify Rsbuild config");
1670
1904
  const [modified] = await context.hooks.modifyRsbuildConfig.call(
1671
1905
  context.config,
1672
1906
  { mergeRsbuildConfig }
1673
1907
  );
1674
1908
  context.config = modified;
1675
- debug3("modify Rsbuild config done");
1909
+ logger.debug("modify Rsbuild config done");
1676
1910
  }
1677
1911
  async function initRsbuildConfig({
1678
1912
  context,
@@ -1700,7 +1934,7 @@ async function initConfigs({
1700
1934
  const rspackConfigs = await Promise.all(
1701
1935
  targets.map((target) => generateRspackConfig({ target, context }))
1702
1936
  );
1703
- if (isDebug2()) {
1937
+ if (isDebug()) {
1704
1938
  const inspect = () => {
1705
1939
  const inspectOptions = {
1706
1940
  verbose: true,
@@ -1727,6 +1961,7 @@ var init_initConfigs = __esm({
1727
1961
  init_esm();
1728
1962
  init_config();
1729
1963
  init_createContext();
1964
+ init_logger();
1730
1965
  init_mergeConfig();
1731
1966
  init_pluginManager();
1732
1967
  init_inspectConfig();
@@ -1738,13 +1973,10 @@ var init_initConfigs = __esm({
1738
1973
  var devMiddleware_exports = {};
1739
1974
  __export(devMiddleware_exports, {
1740
1975
  getDevMiddleware: () => getDevMiddleware,
1976
+ isClientCompiler: () => isClientCompiler,
1977
+ isNodeCompiler: () => isNodeCompiler,
1741
1978
  setupServerHooks: () => setupServerHooks
1742
1979
  });
1743
- import {
1744
- applyToCompiler,
1745
- isClientCompiler,
1746
- isNodeCompiler
1747
- } from "@rsbuild/shared";
1748
1980
  function applyHMREntry({
1749
1981
  compiler,
1750
1982
  clientPaths,
@@ -1764,11 +1996,26 @@ function applyHMREntry({
1764
1996
  }).apply(compiler);
1765
1997
  }
1766
1998
  }
1767
- var setupServerHooks, getDevMiddleware;
1999
+ var isClientCompiler, isNodeCompiler, setupServerHooks, getDevMiddleware;
1768
2000
  var init_devMiddleware = __esm({
1769
2001
  "src/server/devMiddleware.ts"() {
1770
2002
  "use strict";
1771
2003
  init_esm();
2004
+ init_helpers();
2005
+ isClientCompiler = (compiler) => {
2006
+ const { target } = compiler.options;
2007
+ if (target) {
2008
+ return Array.isArray(target) ? target.includes("web") : target === "web";
2009
+ }
2010
+ return false;
2011
+ };
2012
+ isNodeCompiler = (compiler) => {
2013
+ const { target } = compiler.options;
2014
+ if (target) {
2015
+ return Array.isArray(target) ? target.includes("node") : target === "node";
2016
+ }
2017
+ return false;
2018
+ };
1772
2019
  setupServerHooks = (compiler, hookCallbacks) => {
1773
2020
  if (isNodeCompiler(compiler)) {
1774
2021
  return;
@@ -1807,13 +2054,9 @@ __export(createCompiler_exports, {
1807
2054
  createDevMiddleware: () => createDevMiddleware
1808
2055
  });
1809
2056
  import {
1810
- TARGET_ID_MAP,
1811
- color as color6,
1812
- debug as debug4,
2057
+ color as color7,
1813
2058
  isDev,
1814
2059
  isProd as isProd2,
1815
- logger as logger5,
1816
- onCompileDone,
1817
2060
  prettyTime
1818
2061
  } from "@rsbuild/shared";
1819
2062
  import { rspack as rspack3 } from "@rspack/core";
@@ -1821,13 +2064,13 @@ async function createCompiler({
1821
2064
  context,
1822
2065
  rspackConfigs
1823
2066
  }) {
1824
- debug4("create compiler");
2067
+ logger.debug("create compiler");
1825
2068
  await context.hooks.onBeforeCreateCompiler.call({
1826
2069
  bundlerConfigs: rspackConfigs
1827
2070
  });
1828
2071
  if (!await isSatisfyRspackVersion(rspack3.rspackVersion)) {
1829
2072
  throw new Error(
1830
- `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${color6.green(
2073
+ `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${color7.green(
1831
2074
  rspackMinVersion
1832
2075
  )}`
1833
2076
  );
@@ -1838,14 +2081,14 @@ async function createCompiler({
1838
2081
  let isCompiling = false;
1839
2082
  const logRspackVersion = () => {
1840
2083
  if (!isVersionLogged) {
1841
- debug4(`Use Rspack v${rspack3.rspackVersion}`);
2084
+ logger.debug(`Use Rspack v${rspack3.rspackVersion}`);
1842
2085
  isVersionLogged = true;
1843
2086
  }
1844
2087
  };
1845
2088
  compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
1846
2089
  logRspackVersion();
1847
2090
  if (!isCompiling) {
1848
- logger5.start("Compiling...");
2091
+ logger.start("Compiling...");
1849
2092
  }
1850
2093
  isCompiling = true;
1851
2094
  });
@@ -1862,7 +2105,7 @@ async function createCompiler({
1862
2105
  const time = prettyTime(c.time / 1e3);
1863
2106
  const target = context.targets[index];
1864
2107
  const name = TARGET_ID_MAP[target || "web"];
1865
- logger5.ready(`${name} compiled in ${time}`);
2108
+ logger.ready(`${name} compiled in ${time}`);
1866
2109
  }
1867
2110
  };
1868
2111
  if (!stats.hasErrors()) {
@@ -1876,10 +2119,10 @@ async function createCompiler({
1876
2119
  }
1877
2120
  const { message, level } = formatStats(stats, getStatsOptions(compiler));
1878
2121
  if (level === "error") {
1879
- logger5.error(message);
2122
+ logger.error(message);
1880
2123
  }
1881
2124
  if (level === "warning") {
1882
- logger5.warn(message);
2125
+ logger.warn(message);
1883
2126
  }
1884
2127
  if (isDev()) {
1885
2128
  await context.hooks.onDevCompileDone.call({
@@ -1897,7 +2140,7 @@ async function createCompiler({
1897
2140
  rspack3.MultiStats
1898
2141
  );
1899
2142
  await context.hooks.onAfterCreateCompiler.call({ compiler });
1900
- debug4("create compiler done");
2143
+ logger.debug("create compiler done");
1901
2144
  return compiler;
1902
2145
  }
1903
2146
  async function createDevMiddleware(options, customCompiler) {
@@ -1921,7 +2164,9 @@ var init_createCompiler = __esm({
1921
2164
  "src/provider/createCompiler.ts"() {
1922
2165
  "use strict";
1923
2166
  init_esm();
2167
+ init_constants();
1924
2168
  init_helpers();
2169
+ init_logger();
1925
2170
  init_initConfigs();
1926
2171
  }
1927
2172
  });
@@ -1930,16 +2175,14 @@ var init_createCompiler = __esm({
1930
2175
  import path4 from "path";
1931
2176
  import { parse as parse2 } from "url";
1932
2177
  import {
1933
- color as color7,
1934
- debug as debug5,
1935
- isDebug as isDebug3,
1936
- logger as logger6
2178
+ color as color8
1937
2179
  } from "@rsbuild/shared";
1938
2180
  var faviconFallbackMiddleware, getStatusCodeColor, getRequestLoggerMiddleware, notFoundMiddleware, getHtmlFallbackMiddleware;
1939
2181
  var init_middlewares = __esm({
1940
2182
  "src/server/middlewares.ts"() {
1941
2183
  "use strict";
1942
2184
  init_esm();
2185
+ init_logger();
1943
2186
  faviconFallbackMiddleware = (req, res, next) => {
1944
2187
  if (req.url === "/favicon.ico") {
1945
2188
  res.statusCode = 204;
@@ -1950,16 +2193,16 @@ var init_middlewares = __esm({
1950
2193
  };
1951
2194
  getStatusCodeColor = (status) => {
1952
2195
  if (status >= 500) {
1953
- return color7.red;
2196
+ return color8.red;
1954
2197
  }
1955
2198
  if (status >= 400) {
1956
- return color7.yellow;
2199
+ return color8.yellow;
1957
2200
  }
1958
2201
  if (status >= 300) {
1959
- return color7.cyan;
2202
+ return color8.cyan;
1960
2203
  }
1961
2204
  if (status >= 200) {
1962
- return color7.green;
2205
+ return color8.green;
1963
2206
  }
1964
2207
  return (res) => res;
1965
2208
  };
@@ -1974,8 +2217,8 @@ var init_middlewares = __esm({
1974
2217
  const statusColor = getStatusCodeColor(status);
1975
2218
  const endAt = process.hrtime();
1976
2219
  const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
1977
- debug5(
1978
- `${statusColor(status)} ${method} ${color7.gray(url2)} ${color7.gray(
2220
+ logger.debug(
2221
+ `${statusColor(status)} ${method} ${color8.gray(url2)} ${color8.gray(
1979
2222
  `${totalTime.toFixed(3)} ms`
1980
2223
  )}`
1981
2224
  );
@@ -2004,8 +2247,8 @@ var init_middlewares = __esm({
2004
2247
  try {
2005
2248
  pathname = parse2(url2, false, true).pathname;
2006
2249
  } catch (err) {
2007
- logger6.error(
2008
- new Error(`Invalid URL: ${color7.yellow(url2)}`, { cause: err })
2250
+ logger.error(
2251
+ new Error(`Invalid URL: ${color8.yellow(url2)}`, { cause: err })
2009
2252
  );
2010
2253
  return next();
2011
2254
  }
@@ -2017,10 +2260,10 @@ var init_middlewares = __esm({
2017
2260
  });
2018
2261
  };
2019
2262
  const rewrite = (newUrl, isFallback = false) => {
2020
- if (isFallback && isDebug3()) {
2021
- debug5(
2022
- `${req.method} ${color7.gray(
2023
- `${req.url} ${color7.yellow("fallback")} to ${newUrl}`
2263
+ if (isFallback && logger.level === "verbose") {
2264
+ logger.debug(
2265
+ `${req.method} ${color8.gray(
2266
+ `${req.url} ${color8.yellow("fallback")} to ${newUrl}`
2024
2267
  )}`
2025
2268
  );
2026
2269
  }
@@ -2065,9 +2308,6 @@ __export(proxy_exports, {
2065
2308
  createProxyMiddleware: () => createProxyMiddleware,
2066
2309
  formatProxyOptions: () => formatProxyOptions
2067
2310
  });
2068
- import {
2069
- logger as logger7
2070
- } from "@rsbuild/shared";
2071
2311
  import {
2072
2312
  createProxyMiddleware as baseCreateProxyMiddleware
2073
2313
  } from "@rsbuild/shared/http-proxy-middleware";
@@ -2092,7 +2332,7 @@ function formatProxyOptions(proxyOptions) {
2092
2332
  ret.push(opts);
2093
2333
  }
2094
2334
  }
2095
- const handleError = (err) => logger7.error(err);
2335
+ const handleError = (err) => logger.error(err);
2096
2336
  for (const opts of ret) {
2097
2337
  opts.onError ??= handleError;
2098
2338
  }
@@ -2103,6 +2343,7 @@ var init_proxy = __esm({
2103
2343
  "src/server/proxy.ts"() {
2104
2344
  "use strict";
2105
2345
  init_esm();
2346
+ init_logger();
2106
2347
  createProxyMiddleware = (proxyOptions) => {
2107
2348
  const formattedOptionsList = formatProxyOptions(proxyOptions);
2108
2349
  const proxyMiddlewares = [];
@@ -2144,13 +2385,13 @@ var init_proxy = __esm({
2144
2385
  // src/server/getDevMiddlewares.ts
2145
2386
  import { isAbsolute as isAbsolute4, join as join7 } from "path";
2146
2387
  import url from "url";
2147
- import { isDebug as isDebug4 } from "@rsbuild/shared";
2148
2388
  var applySetupMiddlewares, applyDefaultMiddlewares, getMiddlewares;
2149
2389
  var init_getDevMiddlewares = __esm({
2150
2390
  "src/server/getDevMiddlewares.ts"() {
2151
2391
  "use strict";
2152
2392
  init_esm();
2153
2393
  init_config();
2394
+ init_logger();
2154
2395
  init_middlewares();
2155
2396
  applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
2156
2397
  const setupMiddlewares = dev.setupMiddlewares || [];
@@ -2268,7 +2509,7 @@ var init_getDevMiddlewares = __esm({
2268
2509
  getMiddlewares = async (options) => {
2269
2510
  const middlewares = [];
2270
2511
  const { compileMiddlewareAPI } = options;
2271
- if (isDebug4()) {
2512
+ if (logger.level === "verbose") {
2272
2513
  middlewares.push(await getRequestLoggerMiddleware());
2273
2514
  }
2274
2515
  const { before, after } = applySetupMiddlewares(
@@ -2295,17 +2536,11 @@ var init_getDevMiddlewares = __esm({
2295
2536
  // src/server/helper.ts
2296
2537
  import net from "net";
2297
2538
  import os from "os";
2298
- import {
2299
- color as color8,
2300
- deepmerge,
2301
- isFunction as isFunction4,
2302
- logger as logger8,
2303
- normalizeUrl
2304
- } from "@rsbuild/shared";
2539
+ import { color as color9, deepmerge, isFunction as isFunction4 } from "@rsbuild/shared";
2305
2540
  function getURLMessages(urls, routes) {
2306
2541
  if (routes.length === 1) {
2307
2542
  return urls.map(
2308
- ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${color8.cyan(
2543
+ ({ label, url: url2 }) => ` ${`> ${label.padEnd(10)}`}${color9.cyan(
2309
2544
  normalizeUrl(`${url2}${routes[0].pathname}`)
2310
2545
  )}
2311
2546
  `
@@ -2320,9 +2555,9 @@ function getURLMessages(urls, routes) {
2320
2555
  message += ` ${`> ${label}`}
2321
2556
  `;
2322
2557
  for (const r of routes) {
2323
- message += ` ${color8.dim("-")} ${color8.dim(
2558
+ message += ` ${color9.dim("-")} ${color9.dim(
2324
2559
  r.entryName.padEnd(maxNameLength + 4)
2325
- )}${color8.cyan(normalizeUrl(`${url2}${r.pathname}`))}
2560
+ )}${color9.cyan(normalizeUrl(`${url2}${r.pathname}`))}
2326
2561
  `;
2327
2562
  }
2328
2563
  });
@@ -2363,15 +2598,17 @@ function printServerURLs({
2363
2598
  return;
2364
2599
  }
2365
2600
  const message = getURLMessages(urls, routes);
2366
- logger8.log(message);
2601
+ logger.log(message);
2367
2602
  return message;
2368
2603
  }
2369
- var formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
2604
+ var normalizeUrl, formatPrefix, formatRoutes, HMR_SOCK_PATH, getPort, getServerConfig, getDevConfig, getIpv4Interfaces, isLoopbackHost, getHostInUrl, concatUrl, LOCAL_LABEL, NETWORK_LABEL, getUrlLabel, getAddressUrls;
2370
2605
  var init_helper = __esm({
2371
2606
  "src/server/helper.ts"() {
2372
2607
  "use strict";
2373
2608
  init_esm();
2374
2609
  init_constants();
2610
+ init_logger();
2611
+ normalizeUrl = (url2) => url2.replace(/([^:]\/)\/+/g, "$1");
2375
2612
  formatPrefix = (prefix) => {
2376
2613
  if (!prefix) {
2377
2614
  return "/";
@@ -2434,8 +2671,8 @@ var init_helper = __esm({
2434
2671
  );
2435
2672
  }
2436
2673
  if (!silent) {
2437
- logger8.info(
2438
- `Port ${original} is in use, ${color8.yellow(`using port ${port}.`)}
2674
+ logger.info(
2675
+ `Port ${original} is in use, ${color9.yellow(`using port ${port}.`)}
2439
2676
  `
2440
2677
  );
2441
2678
  }
@@ -2660,13 +2897,13 @@ var init_watchFiles = __esm({
2660
2897
  });
2661
2898
 
2662
2899
  // src/server/socketServer.ts
2663
- import { logger as logger9 } from "@rsbuild/shared";
2664
2900
  var SocketServer;
2665
2901
  var init_socketServer = __esm({
2666
2902
  "src/server/socketServer.ts"() {
2667
2903
  "use strict";
2668
2904
  init_esm();
2669
2905
  init_helpers();
2906
+ init_logger();
2670
2907
  SocketServer = class {
2671
2908
  constructor(options) {
2672
2909
  __publicField(this, "wsServer");
@@ -2692,7 +2929,7 @@ var init_socketServer = __esm({
2692
2929
  path: this.options.client?.path
2693
2930
  });
2694
2931
  this.wsServer.on("error", (err) => {
2695
- logger9.error(err);
2932
+ logger.error(err);
2696
2933
  });
2697
2934
  this.timer = setInterval(() => {
2698
2935
  for (const socket of this.wsServer.clients) {
@@ -2911,10 +3148,8 @@ __export(devServer_exports, {
2911
3148
  });
2912
3149
  import fs3 from "fs";
2913
3150
  import {
2914
- debug as debug6,
2915
3151
  getNodeEnv as getNodeEnv5,
2916
3152
  getPublicPathFromCompiler,
2917
- isMultiCompiler as isMultiCompiler2,
2918
3153
  setNodeEnv as setNodeEnv2
2919
3154
  } from "@rsbuild/shared";
2920
3155
  async function createDevServer(options, createDevMiddleware2, config, {
@@ -2925,7 +3160,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2925
3160
  if (!getNodeEnv5()) {
2926
3161
  setNodeEnv2("development");
2927
3162
  }
2928
- debug6("create dev server");
3163
+ logger.debug("create dev server");
2929
3164
  const serverConfig = config.server;
2930
3165
  const { port, host, https } = await getServerConfig({
2931
3166
  config,
@@ -2952,7 +3187,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2952
3187
  customCompiler
2953
3188
  );
2954
3189
  const { CompilerDevMiddleware: CompilerDevMiddleware2 } = await Promise.resolve().then(() => (init_compilerDevMiddleware(), compilerDevMiddleware_exports));
2955
- const publicPaths = isMultiCompiler2(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [getPublicPathFromCompiler(compiler)];
3190
+ const publicPaths = isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [getPublicPathFromCompiler(compiler)];
2956
3191
  const compilerDevMiddleware = new CompilerDevMiddleware2({
2957
3192
  dev: devConfig,
2958
3193
  server: serverConfig,
@@ -2960,7 +3195,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
2960
3195
  devMiddleware
2961
3196
  });
2962
3197
  await compilerDevMiddleware.init();
2963
- outputFileSystem = (isMultiCompiler2(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || fs3;
3198
+ outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || fs3;
2964
3199
  return {
2965
3200
  middleware: compilerDevMiddleware.middleware,
2966
3201
  sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
@@ -3024,7 +3259,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
3024
3259
  serverConfig,
3025
3260
  middlewares
3026
3261
  });
3027
- debug6("listen dev server");
3262
+ logger.debug("listen dev server");
3028
3263
  return new Promise((resolve) => {
3029
3264
  httpServer.listen(
3030
3265
  {
@@ -3037,7 +3272,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
3037
3272
  }
3038
3273
  middlewares.use(notFoundMiddleware);
3039
3274
  httpServer.on("upgrade", devMiddlewares.onUpgrade);
3040
- debug6("listen dev server done");
3275
+ logger.debug("listen dev server done");
3041
3276
  await server.afterListen();
3042
3277
  const closeServer = async () => {
3043
3278
  await server.close();
@@ -3068,7 +3303,7 @@ async function createDevServer(options, createDevMiddleware2, config, {
3068
3303
  await fileWatcher?.close();
3069
3304
  }
3070
3305
  };
3071
- debug6("create dev server done");
3306
+ logger.debug("create dev server done");
3072
3307
  return server;
3073
3308
  }
3074
3309
  var init_devServer = __esm({
@@ -3076,6 +3311,8 @@ var init_devServer = __esm({
3076
3311
  "use strict";
3077
3312
  init_esm();
3078
3313
  init_constants();
3314
+ init_helpers();
3315
+ init_logger();
3079
3316
  init_getDevMiddlewares();
3080
3317
  init_helper();
3081
3318
  init_httpServer();
@@ -3085,213 +3322,38 @@ var init_devServer = __esm({
3085
3322
  }
3086
3323
  });
3087
3324
 
3088
- // src/server/prodServer.ts
3089
- var prodServer_exports = {};
3090
- __export(prodServer_exports, {
3091
- RsbuildProdServer: () => RsbuildProdServer,
3092
- startProdServer: () => startProdServer
3325
+ // src/provider/build.ts
3326
+ var build_exports = {};
3327
+ __export(build_exports, {
3328
+ build: () => build
3093
3329
  });
3094
- import { join as join8 } from "path";
3095
- import {
3096
- getNodeEnv as getNodeEnv6,
3097
- isDebug as isDebug5,
3098
- setNodeEnv as setNodeEnv3
3099
- } from "@rsbuild/shared";
3100
- async function startProdServer(context, config, { getPortSilently } = {}) {
3101
- if (!getNodeEnv6()) {
3102
- setNodeEnv3("production");
3103
- }
3104
- const { port, host, https } = await getServerConfig({
3105
- config,
3106
- getPortSilently
3107
- });
3108
- const { default: connect } = await import("../compiled/connect/index.js");
3109
- const middlewares = connect();
3110
- const serverConfig = config.server;
3111
- const server = new RsbuildProdServer(
3112
- {
3113
- pwd: context.rootPath,
3114
- output: {
3115
- path: config.output.distPath.root || ROOT_DIST_DIR,
3116
- assetPrefix: config.output.assetPrefix
3117
- },
3118
- serverConfig
3119
- },
3120
- middlewares
3121
- );
3122
- await context.hooks.onBeforeStartProdServer.call();
3123
- const httpServer = await createHttpServer({
3124
- serverConfig,
3125
- middlewares: server.middlewares
3126
- });
3127
- await server.onInit(httpServer);
3128
- return new Promise((resolve) => {
3129
- httpServer.listen(
3130
- {
3131
- host,
3132
- port
3133
- },
3134
- async () => {
3135
- const routes = formatRoutes(
3136
- context.entry,
3137
- config.output.distPath.html,
3138
- config.html.outputStructure
3139
- );
3140
- await context.hooks.onAfterStartProdServer.call({
3141
- port,
3142
- routes
3143
- });
3144
- const protocol = https ? "https" : "http";
3145
- const urls = getAddressUrls({ protocol, port, host });
3146
- printServerURLs({
3147
- urls,
3148
- port,
3149
- routes,
3150
- protocol,
3151
- printUrls: serverConfig.printUrls
3152
- });
3153
- const onClose = () => {
3154
- server.close();
3155
- httpServer.close();
3156
- };
3157
- resolve({
3158
- port,
3159
- urls: urls.map((item) => item.url),
3160
- server: {
3161
- close: async () => {
3162
- onClose();
3163
- }
3164
- }
3165
- });
3166
- }
3167
- );
3168
- });
3169
- }
3170
- var RsbuildProdServer;
3171
- var init_prodServer = __esm({
3172
- "src/server/prodServer.ts"() {
3330
+ import { getNodeEnv as getNodeEnv6, setNodeEnv as setNodeEnv3 } from "@rsbuild/shared";
3331
+ import { rspack as rspack4 } from "@rspack/core";
3332
+ var build;
3333
+ var init_build = __esm({
3334
+ "src/provider/build.ts"() {
3173
3335
  "use strict";
3174
3336
  init_esm();
3175
- init_constants();
3176
- init_helper();
3177
- init_httpServer();
3178
- init_middlewares();
3179
- RsbuildProdServer = class {
3180
- constructor(options, middlewares) {
3181
- __publicField(this, "app");
3182
- __publicField(this, "options");
3183
- __publicField(this, "middlewares");
3184
- this.options = options;
3185
- this.middlewares = middlewares;
3337
+ init_helpers();
3338
+ init_logger();
3339
+ init_createCompiler();
3340
+ init_initConfigs();
3341
+ build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
3342
+ if (!getNodeEnv6()) {
3343
+ setNodeEnv3(mode);
3186
3344
  }
3187
- // Complete the preparation of services
3188
- async onInit(app) {
3189
- this.app = app;
3190
- await this.applyDefaultMiddlewares();
3191
- }
3192
- async applyDefaultMiddlewares() {
3193
- const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
3194
- if (isDebug5()) {
3195
- this.middlewares.use(await getRequestLoggerMiddleware());
3196
- }
3197
- if (compress) {
3198
- const { default: compression } = await import("../compiled/http-compression/index.js");
3199
- this.middlewares.use((req, res, next) => {
3200
- compression({
3201
- gzip: true,
3202
- brotli: false
3203
- })(req, res, next);
3204
- });
3205
- }
3206
- if (headers) {
3207
- this.middlewares.use((_req, res, next) => {
3208
- for (const [key, value] of Object.entries(headers)) {
3209
- res.setHeader(key, value);
3210
- }
3211
- next();
3212
- });
3213
- }
3214
- if (proxy) {
3215
- const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
3216
- const { middlewares, upgrade } = createProxyMiddleware2(proxy);
3217
- for (const middleware of middlewares) {
3218
- this.middlewares.use(middleware);
3219
- }
3220
- this.app.on("upgrade", upgrade);
3221
- }
3222
- this.applyStaticAssetMiddleware();
3223
- if (historyApiFallback) {
3224
- const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
3225
- const historyApiFallbackMiddleware = connectHistoryApiFallback(
3226
- historyApiFallback === true ? {} : historyApiFallback
3227
- );
3228
- this.middlewares.use(historyApiFallbackMiddleware);
3229
- await this.applyStaticAssetMiddleware();
3230
- }
3231
- this.middlewares.use(faviconFallbackMiddleware);
3232
- }
3233
- async applyStaticAssetMiddleware() {
3234
- const {
3235
- output: { path: path14, assetPrefix },
3236
- serverConfig: { htmlFallback },
3237
- pwd
3238
- } = this.options;
3239
- const { default: sirv } = await import("../compiled/sirv/index.js");
3240
- const assetMiddleware = sirv(join8(pwd, path14), {
3241
- etag: true,
3242
- dev: true,
3243
- ignores: ["favicon.ico"],
3244
- single: htmlFallback === "index"
3245
- });
3246
- this.middlewares.use((req, res, next) => {
3247
- const url2 = req.url;
3248
- if (assetPrefix && url2?.startsWith(assetPrefix)) {
3249
- req.url = url2.slice(assetPrefix.length);
3250
- assetMiddleware(req, res, (...args) => {
3251
- req.url = url2;
3252
- next(...args);
3253
- });
3254
- } else {
3255
- assetMiddleware(req, res, next);
3256
- }
3257
- });
3258
- }
3259
- close() {
3260
- }
3261
- };
3262
- }
3263
- });
3264
-
3265
- // src/provider/build.ts
3266
- var build_exports = {};
3267
- __export(build_exports, {
3268
- build: () => build
3269
- });
3270
- import { getNodeEnv as getNodeEnv7, logger as logger10, onCompileDone as onCompileDone2, setNodeEnv as setNodeEnv4 } from "@rsbuild/shared";
3271
- import { rspack as rspack4 } from "@rspack/core";
3272
- var build;
3273
- var init_build = __esm({
3274
- "src/provider/build.ts"() {
3275
- "use strict";
3276
- init_esm();
3277
- init_createCompiler();
3278
- init_initConfigs();
3279
- build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
3280
- if (!getNodeEnv7()) {
3281
- setNodeEnv4(mode);
3282
- }
3283
- const { context } = initOptions;
3284
- let compiler;
3285
- let bundlerConfigs;
3286
- if (customCompiler) {
3287
- compiler = customCompiler;
3288
- } else {
3289
- const { rspackConfigs } = await initConfigs(initOptions);
3290
- compiler = await createCompiler({
3291
- context,
3292
- rspackConfigs
3293
- });
3294
- bundlerConfigs = rspackConfigs;
3345
+ const { context } = initOptions;
3346
+ let compiler;
3347
+ let bundlerConfigs;
3348
+ if (customCompiler) {
3349
+ compiler = customCompiler;
3350
+ } else {
3351
+ const { rspackConfigs } = await initConfigs(initOptions);
3352
+ compiler = await createCompiler({
3353
+ context,
3354
+ rspackConfigs
3355
+ });
3356
+ bundlerConfigs = rspackConfigs;
3295
3357
  }
3296
3358
  let isFirstCompile = true;
3297
3359
  await context.hooks.onBeforeBuild.call({
@@ -3302,7 +3364,7 @@ var init_build = __esm({
3302
3364
  isFirstCompile = false;
3303
3365
  await p;
3304
3366
  };
3305
- onCompileDone2(
3367
+ onCompileDone(
3306
3368
  compiler,
3307
3369
  onDone,
3308
3370
  // @ts-expect-error type mismatch
@@ -3311,7 +3373,7 @@ var init_build = __esm({
3311
3373
  if (watch) {
3312
3374
  compiler.watch({}, (err) => {
3313
3375
  if (err) {
3314
- logger10.error(err);
3376
+ logger.error(err);
3315
3377
  }
3316
3378
  });
3317
3379
  return;
@@ -3324,7 +3386,7 @@ var init_build = __esm({
3324
3386
  } else {
3325
3387
  compiler.close((closeErr) => {
3326
3388
  if (closeErr) {
3327
- logger10.error(closeErr);
3389
+ logger.error(closeErr);
3328
3390
  }
3329
3391
  resolve({ stats });
3330
3392
  });
@@ -3389,11 +3451,6 @@ var init_provider = __esm({
3389
3451
  );
3390
3452
  return server.listen();
3391
3453
  },
3392
- async preview(options) {
3393
- const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
3394
- const config = await initRsbuildConfig({ context, pluginManager });
3395
- return startProdServer2(context, config, options);
3396
- },
3397
3454
  async build(options) {
3398
3455
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
3399
3456
  return build2({ context, pluginManager, rsbuildOptions }, options);
@@ -3426,22 +3483,30 @@ __export(basic_exports, {
3426
3483
  pluginBasic: () => pluginBasic
3427
3484
  });
3428
3485
  import path5 from "path";
3429
- import { TARGET_ID_MAP as TARGET_ID_MAP2, getJsSourceMap, isUsingHMR } from "@rsbuild/shared";
3430
- var pluginBasic;
3486
+ import { isProd as isProd3, isUsingHMR } from "@rsbuild/shared";
3487
+ var getJsSourceMap, pluginBasic;
3431
3488
  var init_basic = __esm({
3432
3489
  "src/plugins/basic.ts"() {
3433
3490
  "use strict";
3434
3491
  init_esm();
3492
+ init_constants();
3493
+ getJsSourceMap = (config) => {
3494
+ const { sourceMap } = config.output;
3495
+ if (sourceMap.js === void 0) {
3496
+ return isProd3() ? false : "cheap-module-source-map";
3497
+ }
3498
+ return sourceMap.js;
3499
+ };
3435
3500
  pluginBasic = () => ({
3436
3501
  name: "rsbuild:basic",
3437
3502
  setup(api) {
3438
3503
  api.modifyBundlerChain(
3439
- (chain, { env, isProd: isProd6, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3504
+ (chain, { env, isProd: isProd7, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
3440
3505
  const config = api.getNormalizedConfig();
3441
- chain.name(TARGET_ID_MAP2[target]);
3506
+ chain.name(TARGET_ID_MAP[target]);
3442
3507
  chain.devtool(getJsSourceMap(config));
3443
3508
  chain.context(api.context.rootPath);
3444
- chain.mode(isProd6 ? "production" : "development");
3509
+ chain.mode(isProd7 ? "production" : "development");
3445
3510
  chain.merge({
3446
3511
  infrastructureLogging: {
3447
3512
  // Using `error` level to avoid `cache.PackFileCacheStrategy` logs
@@ -3454,9 +3519,9 @@ var init_basic = __esm({
3454
3519
  exportsPresence: "error"
3455
3520
  }
3456
3521
  });
3457
- const isMinimize = isProd6 && config.output.minify !== false;
3522
+ const isMinimize = isProd7 && config.output.minify !== false;
3458
3523
  chain.optimization.minimize(isMinimize);
3459
- const usingHMR = isUsingHMR(config, { target, isProd: isProd6 });
3524
+ const usingHMR = isUsingHMR(config, { target, isProd: isProd7 });
3460
3525
  if (usingHMR) {
3461
3526
  chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
3462
3527
  }
@@ -3480,10 +3545,10 @@ __export(cache_exports, {
3480
3545
  pluginCache: () => pluginCache
3481
3546
  });
3482
3547
  import crypto from "crypto";
3483
- import { isAbsolute as isAbsolute5, join as join9 } from "path";
3548
+ import { isAbsolute as isAbsolute5, join as join8 } from "path";
3484
3549
  import { fse as fse3 } from "@rsbuild/shared";
3485
3550
  async function validateCache(cacheDirectory, buildDependencies) {
3486
- const configFile = join9(cacheDirectory, "buildDependencies.json");
3551
+ const configFile = join8(cacheDirectory, "buildDependencies.json");
3487
3552
  if (await isFileExists(configFile)) {
3488
3553
  const prevBuildDependencies = await fse3.readJSON(configFile);
3489
3554
  if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
@@ -3500,13 +3565,13 @@ function getDigestHash(digest) {
3500
3565
  }
3501
3566
  function getCacheDirectory({ cacheDirectory }, context) {
3502
3567
  if (cacheDirectory) {
3503
- return isAbsolute5(cacheDirectory) ? cacheDirectory : join9(context.rootPath, cacheDirectory);
3568
+ return isAbsolute5(cacheDirectory) ? cacheDirectory : join8(context.rootPath, cacheDirectory);
3504
3569
  }
3505
- return join9(context.cachePath, context.bundlerType);
3570
+ return join8(context.cachePath, context.bundlerType);
3506
3571
  }
3507
3572
  async function getBuildDependencies(context, config) {
3508
- const rootPackageJson = join9(context.rootPath, "package.json");
3509
- const browserslistConfig = join9(context.rootPath, ".browserslistrc");
3573
+ const rootPackageJson = join8(context.rootPath, "package.json");
3574
+ const browserslistConfig = join8(context.rootPath, ".browserslistrc");
3510
3575
  const buildDependencies = {};
3511
3576
  if (await isFileExists(rootPackageJson)) {
3512
3577
  buildDependencies.packageJson = [rootPackageJson];
@@ -3522,7 +3587,7 @@ async function getBuildDependencies(context, config) {
3522
3587
  }
3523
3588
  const tailwindExts = ["ts", "js", "cjs", "mjs"];
3524
3589
  const configs = tailwindExts.map(
3525
- (ext) => join9(context.rootPath, `tailwind.config.${ext}`)
3590
+ (ext) => join8(context.rootPath, `tailwind.config.${ext}`)
3526
3591
  );
3527
3592
  const tailwindConfig = findExists(configs);
3528
3593
  if (tailwindConfig) {
@@ -3626,7 +3691,7 @@ import {
3626
3691
  deepmerge as deepmerge2,
3627
3692
  getBrowserslistWithDefault as getBrowserslistWithDefault2,
3628
3693
  isFunction as isFunction5,
3629
- isPlainObject as isPlainObject2,
3694
+ isPlainObject as isPlainObject3,
3630
3695
  reduceConfigs,
3631
3696
  reduceConfigsWithContext
3632
3697
  } from "@rsbuild/shared";
@@ -3652,7 +3717,7 @@ async function applyCSSRule({
3652
3717
  rule,
3653
3718
  config,
3654
3719
  context,
3655
- utils: { target, isProd: isProd6, CHAIN_ID: CHAIN_ID3 },
3720
+ utils: { target, isProd: isProd7, CHAIN_ID: CHAIN_ID3 },
3656
3721
  importLoaders = 1
3657
3722
  }) {
3658
3723
  const browserslist = await getBrowserslistWithDefault2(
@@ -3661,7 +3726,7 @@ async function applyCSSRule({
3661
3726
  target
3662
3727
  );
3663
3728
  const enableExtractCSS = isUseCssExtract(config, target);
3664
- const localIdentName = getCSSModulesLocalIdentName(config, isProd6);
3729
+ const localIdentName = getCSSModulesLocalIdentName(config, isProd7);
3665
3730
  const cssLoaderOptions = getCSSLoaderOptions({
3666
3731
  config,
3667
3732
  importLoaders,
@@ -3703,8 +3768,8 @@ var init_css = __esm({
3703
3768
  init_pluginHelper();
3704
3769
  enableNativeCss = (config) => !config.output.injectStyles;
3705
3770
  isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
3706
- getCSSModulesLocalIdentName = (config, isProd6) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3707
- (isProd6 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3771
+ getCSSModulesLocalIdentName = (config, isProd7) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
3772
+ (isProd7 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
3708
3773
  normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
3709
3774
  if (options.modules && exportOnlyLocals) {
3710
3775
  let { modules } = options;
@@ -3734,7 +3799,7 @@ var init_css = __esm({
3734
3799
  (plugin) => isFunction5(plugin) ? plugin({}) : plugin
3735
3800
  );
3736
3801
  const hasAutoprefixer = pluginObjects.some((pluginObject) => {
3737
- if (isPlainObject2(pluginObject) && "postcssPlugin" in pluginObject) {
3802
+ if (isPlainObject3(pluginObject) && "postcssPlugin" in pluginObject) {
3738
3803
  return pluginObject.postcssPlugin === "autoprefixer";
3739
3804
  }
3740
3805
  return false;
@@ -3850,21 +3915,19 @@ var output_exports = {};
3850
3915
  __export(output_exports, {
3851
3916
  pluginOutput: () => pluginOutput
3852
3917
  });
3853
- import { posix } from "path";
3918
+ import { posix as posix2 } from "path";
3854
3919
  import {
3855
- DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX3,
3856
- getDistPath as getDistPath3,
3857
- getFilename as getFilename2
3920
+ DEFAULT_ASSET_PREFIX as DEFAULT_ASSET_PREFIX3
3858
3921
  } from "@rsbuild/shared";
3859
3922
  import { rspack as rspack5 } from "@rspack/core";
3860
3923
  function getPublicPath({
3861
- isProd: isProd6,
3924
+ isProd: isProd7,
3862
3925
  config,
3863
3926
  context
3864
3927
  }) {
3865
3928
  const { dev, output } = config;
3866
3929
  let publicPath = DEFAULT_ASSET_PREFIX3;
3867
- if (isProd6) {
3930
+ if (isProd7) {
3868
3931
  if (typeof output.assetPrefix === "string") {
3869
3932
  publicPath = output.assetPrefix;
3870
3933
  }
@@ -3896,38 +3959,38 @@ var init_output = __esm({
3896
3959
  name: "rsbuild:output",
3897
3960
  setup(api) {
3898
3961
  api.modifyBundlerChain(
3899
- async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd6, isServer, isServiceWorker }) => {
3962
+ async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd7, isServer, isServiceWorker }) => {
3900
3963
  const config = api.getNormalizedConfig();
3901
3964
  const publicPath = getPublicPath({
3902
3965
  config,
3903
- isProd: isProd6,
3966
+ isProd: isProd7,
3904
3967
  context: api.context
3905
3968
  });
3906
- const jsPath = getDistPath3(config, "js");
3907
- const jsAsyncPath = getDistPath3(config, "jsAsync");
3908
- const jsFilename = getFilename2(config, "js", isProd6);
3969
+ const jsPath = config.output.distPath.js;
3970
+ const jsAsyncPath = config.output.distPath.jsAsync ?? (jsPath ? `${jsPath}/async` : "async");
3971
+ const jsFilename = getFilename2(config, "js", isProd7);
3909
3972
  const isJsFilenameFn = typeof jsFilename === "function";
3910
3973
  chain.output.path(api.context.distPath).filename(
3911
3974
  isJsFilenameFn ? (...args) => {
3912
3975
  const name = jsFilename(...args);
3913
- return posix.join(jsPath, name);
3914
- } : posix.join(jsPath, jsFilename)
3976
+ return posix2.join(jsPath, name);
3977
+ } : posix2.join(jsPath, jsFilename)
3915
3978
  ).chunkFilename(
3916
3979
  isJsFilenameFn ? (...args) => {
3917
3980
  const name = jsFilename(...args);
3918
- return posix.join(jsAsyncPath, name);
3919
- } : posix.join(jsAsyncPath, jsFilename)
3981
+ return posix2.join(jsAsyncPath, name);
3982
+ } : posix2.join(jsAsyncPath, jsFilename)
3920
3983
  ).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
3921
3984
  if (isServer) {
3922
- const serverPath = getDistPath3(config, "server");
3923
- chain.output.path(posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3985
+ const serverPath = config.output.distPath.server;
3986
+ chain.output.path(posix2.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
3924
3987
  ...chain.output.get("library") || {},
3925
3988
  type: "commonjs2"
3926
3989
  });
3927
3990
  }
3928
3991
  if (isServiceWorker) {
3929
- const workerPath = getDistPath3(config, "worker");
3930
- const filename = posix.join(workerPath, "[name].js");
3992
+ const workerPath = config.output.distPath.worker;
3993
+ const filename = posix2.join(workerPath, "[name].js");
3931
3994
  chain.output.filename(filename).chunkFilename(filename);
3932
3995
  }
3933
3996
  if (config.output.copy && api.context.bundlerType === "rspack") {
@@ -3937,13 +4000,13 @@ var init_output = __esm({
3937
4000
  }
3938
4001
  if (isUseCssExtract(config, target)) {
3939
4002
  const extractPluginOptions = config.tools.cssExtract.pluginOptions;
3940
- const cssPath = getDistPath3(config, "css");
3941
- const cssFilename = getFilename2(config, "css", isProd6);
3942
- const cssAsyncPath = getDistPath3(config, "cssAsync");
4003
+ const cssPath = config.output.distPath.css;
4004
+ const cssFilename = getFilename2(config, "css", isProd7);
4005
+ const cssAsyncPath = config.output.distPath.cssAsync ?? (cssPath ? `${cssPath}/async` : "async");
3943
4006
  chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
3944
4007
  {
3945
- filename: posix.join(cssPath, cssFilename),
3946
- chunkFilename: posix.join(cssAsyncPath, cssFilename),
4008
+ filename: posix2.join(cssPath, cssFilename),
4009
+ chunkFilename: posix2.join(cssAsyncPath, cssFilename),
3947
4010
  ...extractPluginOptions
3948
4011
  }
3949
4012
  ]);
@@ -3961,7 +4024,7 @@ __export(resolve_exports, {
3961
4024
  pluginResolve: () => pluginResolve
3962
4025
  });
3963
4026
  import {
3964
- castArray as castArray4,
4027
+ castArray as castArray6,
3965
4028
  reduceConfigsWithContext as reduceConfigsWithContext2
3966
4029
  } from "@rsbuild/shared";
3967
4030
  function applyFullySpecified({
@@ -3998,7 +4061,7 @@ function applyAlias({
3998
4061
  ctx: { target }
3999
4062
  });
4000
4063
  for (const name of Object.keys(mergedAlias)) {
4001
- const values = castArray4(mergedAlias[name]);
4064
+ const values = castArray6(mergedAlias[name]);
4002
4065
  const formattedValues = values.map((value) => {
4003
4066
  if (typeof value === "string" && value.startsWith(".")) {
4004
4067
  return ensureAbsolutePath(rootPath, value);
@@ -4055,7 +4118,7 @@ __export(fileSize_exports, {
4055
4118
  });
4056
4119
  import path7 from "path";
4057
4120
  import { JS_REGEX, fse as fse4 } from "@rsbuild/shared";
4058
- import { color as color9, logger as logger11 } from "@rsbuild/shared";
4121
+ import { color as color10 } from "@rsbuild/shared";
4059
4122
  async function printHeader(longestFileLength, longestLabelLength) {
4060
4123
  const longestLengths = [longestFileLength, longestLabelLength];
4061
4124
  const headerRow = ["File", "Size", "Gzipped"].reduce((prev, cur, index) => {
@@ -4066,7 +4129,7 @@ async function printHeader(longestFileLength, longestLabelLength) {
4066
4129
  }
4067
4130
  return `${prev + curLabel} `;
4068
4131
  }, " ");
4069
- logger11.log(color9.bold(color9.blue(headerRow)));
4132
+ logger.log(color10.bold(color10.blue(headerRow)));
4070
4133
  }
4071
4134
  async function printFileSizes(config, stats, rootPath) {
4072
4135
  if (config.detail === false && config.total === false) {
@@ -4117,7 +4180,7 @@ async function printFileSizes(config, stats, rootPath) {
4117
4180
  return;
4118
4181
  }
4119
4182
  assets.sort((a, b) => a.size - b.size);
4120
- logger11.info("Production file sizes:\n");
4183
+ logger.info("Production file sizes:\n");
4121
4184
  const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
4122
4185
  const longestFileLength = Math.max(
4123
4186
  ...assets.map((a) => (a.folder + path7.sep + a.name).length)
@@ -4139,22 +4202,22 @@ async function printFileSizes(config, stats, rootPath) {
4139
4202
  const rightPadding = " ".repeat(longestLabelLength - sizeLength);
4140
4203
  sizeLabel += rightPadding;
4141
4204
  }
4142
- let fileNameLabel = color9.dim(asset.folder + path7.sep) + coloringAssetName(asset.name);
4205
+ let fileNameLabel = color10.dim(asset.folder + path7.sep) + coloringAssetName(asset.name);
4143
4206
  if (fileNameLength < longestFileLength) {
4144
4207
  const rightPadding = " ".repeat(longestFileLength - fileNameLength);
4145
4208
  fileNameLabel += rightPadding;
4146
4209
  }
4147
- logger11.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
4210
+ logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
4148
4211
  }
4149
4212
  }
4150
4213
  if (config.total !== false) {
4151
- const totalSizeLabel = `${color9.bold(
4152
- color9.blue("Total size:")
4214
+ const totalSizeLabel = `${color10.bold(
4215
+ color10.blue("Total size:")
4153
4216
  )} ${calcFileSize(totalSize)}`;
4154
- const gzippedSizeLabel = `${color9.bold(
4155
- color9.blue("Gzipped size:")
4217
+ const gzippedSizeLabel = `${color10.bold(
4218
+ color10.blue("Gzipped size:")
4156
4219
  )} ${calcFileSize(totalGzipSize)}`;
4157
- logger11.log(`
4220
+ logger.log(`
4158
4221
  ${totalSizeLabel}
4159
4222
  ${gzippedSizeLabel}
4160
4223
  `);
@@ -4166,15 +4229,16 @@ var init_fileSize = __esm({
4166
4229
  "use strict";
4167
4230
  init_esm();
4168
4231
  init_constants();
4232
+ init_logger();
4169
4233
  filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
4170
4234
  getAssetColor = (size) => {
4171
4235
  if (size > 300 * 1e3) {
4172
- return color9.red;
4236
+ return color10.red;
4173
4237
  }
4174
4238
  if (size > 100 * 1e3) {
4175
- return color9.yellow;
4239
+ return color10.yellow;
4176
4240
  }
4177
- return color9.green;
4241
+ return color10.green;
4178
4242
  };
4179
4243
  calcFileSize = (len) => {
4180
4244
  const val = len / 1e3;
@@ -4182,15 +4246,15 @@ var init_fileSize = __esm({
4182
4246
  };
4183
4247
  coloringAssetName = (assetName) => {
4184
4248
  if (JS_REGEX.test(assetName)) {
4185
- return color9.cyan(assetName);
4249
+ return color10.cyan(assetName);
4186
4250
  }
4187
4251
  if (CSS_REGEX.test(assetName)) {
4188
- return color9.yellow(assetName);
4252
+ return color10.yellow(assetName);
4189
4253
  }
4190
4254
  if (HTML_REGEX.test(assetName)) {
4191
- return color9.green(assetName);
4255
+ return color10.green(assetName);
4192
4256
  }
4193
- return color9.magenta(assetName);
4257
+ return color10.magenta(assetName);
4194
4258
  };
4195
4259
  pluginFileSize = () => ({
4196
4260
  name: "rsbuild:file-size",
@@ -4212,8 +4276,8 @@ var init_fileSize = __esm({
4212
4276
  api.context.rootPath
4213
4277
  );
4214
4278
  } catch (err) {
4215
- logger11.warn("Failed to print file size.");
4216
- logger11.warn(err);
4279
+ logger.warn("Failed to print file size.");
4280
+ logger.warn(err);
4217
4281
  }
4218
4282
  }
4219
4283
  });
@@ -4228,12 +4292,13 @@ __export(cleanOutput_exports, {
4228
4292
  pluginCleanOutput: () => pluginCleanOutput
4229
4293
  });
4230
4294
  import { sep } from "path";
4231
- import { color as color10, fse as fse5, logger as logger12 } from "@rsbuild/shared";
4295
+ import { color as color11, fse as fse5 } from "@rsbuild/shared";
4232
4296
  var emptyDir, addTrailingSep, isStrictSubdir, pluginCleanOutput;
4233
4297
  var init_cleanOutput = __esm({
4234
4298
  "src/plugins/cleanOutput.ts"() {
4235
4299
  "use strict";
4236
4300
  init_esm();
4301
+ init_logger();
4237
4302
  emptyDir = async (dir) => {
4238
4303
  if (await fse5.pathExists(dir)) {
4239
4304
  await fse5.emptyDir(dir);
@@ -4255,14 +4320,14 @@ var init_cleanOutput = __esm({
4255
4320
  if (cleanDistPath === void 0) {
4256
4321
  cleanDistPath = isStrictSubdir(rootPath, distPath);
4257
4322
  if (!cleanDistPath) {
4258
- logger12.warn(
4323
+ logger.warn(
4259
4324
  "The dist path is not a subdir of root path, Rsbuild will not empty it."
4260
4325
  );
4261
- logger12.warn(
4262
- `Please set ${color10.yellow("`output.cleanDistPath`")} config manually.`
4326
+ logger.warn(
4327
+ `Please set ${color11.yellow("`output.cleanDistPath`")} config manually.`
4263
4328
  );
4264
- logger12.warn(`Current root path: ${color10.dim(rootPath)}`);
4265
- logger12.warn(`Current dist path: ${color10.dim(distPath)}`);
4329
+ logger.warn(`Current root path: ${color11.dim(rootPath)}`);
4330
+ logger.warn(`Current dist path: ${color11.dim(distPath)}`);
4266
4331
  }
4267
4332
  }
4268
4333
  if (cleanDistPath) {
@@ -4283,7 +4348,6 @@ __export(asset_exports, {
4283
4348
  pluginAsset: () => pluginAsset
4284
4349
  });
4285
4350
  import path8 from "path";
4286
- import { getDistPath as getDistPath4, getFilename as getFilename3 } from "@rsbuild/shared";
4287
4351
  function getRegExpForExts(exts) {
4288
4352
  const matcher = exts.map((ext) => ext.trim()).map((ext) => ext.startsWith(".") ? ext.slice(1) : ext).join("|");
4289
4353
  return new RegExp(
@@ -4297,6 +4361,7 @@ var init_asset = __esm({
4297
4361
  "use strict";
4298
4362
  init_esm();
4299
4363
  init_constants();
4364
+ init_helpers();
4300
4365
  chainStaticAssetRule = ({
4301
4366
  emit,
4302
4367
  rule,
@@ -4321,12 +4386,12 @@ var init_asset = __esm({
4321
4386
  pluginAsset = () => ({
4322
4387
  name: "rsbuild:asset",
4323
4388
  setup(api) {
4324
- api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
4389
+ api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
4325
4390
  const config = api.getNormalizedConfig();
4326
4391
  const createAssetRule = (assetType, exts, emit2) => {
4327
4392
  const regExp = getRegExpForExts(exts);
4328
- const distDir = getDistPath4(config, assetType);
4329
- const filename = getFilename3(config, assetType, isProd6);
4393
+ const distDir = config.output.distPath[assetType];
4394
+ const filename = getFilename2(config, assetType, isProd7);
4330
4395
  const { dataUriLimit } = config.output;
4331
4396
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
4332
4397
  const rule = chain.module.rule(assetType).test(regExp);
@@ -4409,9 +4474,9 @@ var init_minimize = __esm({
4409
4474
  }
4410
4475
  return options;
4411
4476
  };
4412
- parseMinifyOptions = (config, isProd6 = true) => {
4477
+ parseMinifyOptions = (config, isProd7 = true) => {
4413
4478
  const minify = config.output.minify;
4414
- if (minify === false || !isProd6) {
4479
+ if (minify === false || !isProd7) {
4415
4480
  return {
4416
4481
  minifyJs: false,
4417
4482
  minifyCss: false,
@@ -4443,9 +4508,9 @@ var init_minimize = __esm({
4443
4508
  if (api.context.bundlerType === "webpack") {
4444
4509
  return;
4445
4510
  }
4446
- api.modifyBundlerChain(async (chain, { isProd: isProd6 }) => {
4511
+ api.modifyBundlerChain(async (chain, { isProd: isProd7 }) => {
4447
4512
  const config = api.getNormalizedConfig();
4448
- const isMinimize = isProd6 && config.output.minify !== false;
4513
+ const isMinimize = isProd7 && config.output.minify !== false;
4449
4514
  if (!isMinimize) {
4450
4515
  return;
4451
4516
  }
@@ -4473,15 +4538,14 @@ __export(HtmlBasicPlugin_exports, {
4473
4538
  hasTitle: () => hasTitle
4474
4539
  });
4475
4540
  import {
4476
- isFunction as isFunction6,
4477
- partition,
4478
- withPublicPath
4541
+ isFunction as isFunction6
4479
4542
  } from "@rsbuild/shared";
4480
4543
  var VOID_TAGS, HEAD_TAGS, FILE_ATTRS, hasTitle, getTagPriority, formatBasicTag, fromBasicTag, formatTags, applyTagConfig, addTitleTag, addFavicon, HtmlBasicPlugin;
4481
4544
  var init_HtmlBasicPlugin = __esm({
4482
4545
  "src/rspack/HtmlBasicPlugin.ts"() {
4483
4546
  "use strict";
4484
4547
  init_esm();
4548
+ init_helpers();
4485
4549
  init_pluginHelper();
4486
4550
  VOID_TAGS = [
4487
4551
  "area",
@@ -4556,9 +4620,9 @@ var init_HtmlBasicPlugin = __esm({
4556
4620
  if (typeof optPublicPath === "function") {
4557
4621
  filename = optPublicPath(filename, data.publicPath);
4558
4622
  } else if (typeof optPublicPath === "string") {
4559
- filename = withPublicPath(filename, optPublicPath);
4623
+ filename = ensureAssetPrefix(filename, optPublicPath);
4560
4624
  } else if (optPublicPath !== false) {
4561
- filename = withPublicPath(filename, data.publicPath);
4625
+ filename = ensureAssetPrefix(filename, data.publicPath);
4562
4626
  }
4563
4627
  const optHash = tag.hash ?? tagConfig.hash;
4564
4628
  if (typeof optHash === "function") {
@@ -4684,13 +4748,14 @@ __export(HtmlAppIconPlugin_exports, {
4684
4748
  HtmlAppIconPlugin: () => HtmlAppIconPlugin
4685
4749
  });
4686
4750
  import fs4 from "fs";
4687
- import { basename, posix as posix2 } from "path";
4688
- import { getPublicPathFromCompiler as getPublicPathFromCompiler2, withPublicPath as withPublicPath2 } from "@rsbuild/shared";
4751
+ import { basename, posix as posix3 } from "path";
4752
+ import { getPublicPathFromCompiler as getPublicPathFromCompiler2 } from "@rsbuild/shared";
4689
4753
  var HtmlAppIconPlugin;
4690
4754
  var init_HtmlAppIconPlugin = __esm({
4691
4755
  "src/rspack/HtmlAppIconPlugin.ts"() {
4692
4756
  "use strict";
4693
4757
  init_esm();
4758
+ init_helpers();
4694
4759
  init_pluginHelper();
4695
4760
  HtmlAppIconPlugin = class {
4696
4761
  constructor(options) {
@@ -4707,7 +4772,7 @@ var init_HtmlAppIconPlugin = __esm({
4707
4772
  `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
4708
4773
  );
4709
4774
  }
4710
- const iconRelativePath = posix2.join(this.distDir, basename(this.iconPath));
4775
+ const iconRelativePath = posix3.join(this.distDir, basename(this.iconPath));
4711
4776
  compiler.hooks.compilation.tap(this.name, (compilation) => {
4712
4777
  getHTMLPlugin().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
4713
4778
  const publicPath = getPublicPathFromCompiler2(compiler);
@@ -4717,7 +4782,7 @@ var init_HtmlAppIconPlugin = __esm({
4717
4782
  attributes: {
4718
4783
  rel: "apple-touch-icon",
4719
4784
  sizes: "180*180",
4720
- href: withPublicPath2(iconRelativePath, publicPath)
4785
+ href: ensureAssetPrefix(iconRelativePath, publicPath)
4721
4786
  },
4722
4787
  meta: {}
4723
4788
  });
@@ -4760,14 +4825,12 @@ __export(html_exports, {
4760
4825
  });
4761
4826
  import path9, { isAbsolute as isAbsolute6 } from "path";
4762
4827
  import {
4763
- castArray as castArray5,
4764
- color as color11,
4828
+ castArray as castArray7,
4829
+ color as color12,
4765
4830
  deepmerge as deepmerge4,
4766
4831
  fse as fse6,
4767
- getDistPath as getDistPath5,
4768
4832
  isHtmlDisabled,
4769
- isPlainObject as isPlainObject3,
4770
- isURL,
4833
+ isPlainObject as isPlainObject4,
4771
4834
  reduceConfigsMergeContext as reduceConfigsMergeContext2,
4772
4835
  reduceConfigsWithContext as reduceConfigsWithContext3
4773
4836
  } from "@rsbuild/shared";
@@ -4803,8 +4866,8 @@ function getTerserMinifyOptions(config) {
4803
4866
  const finalOptions = applyRemoveConsole(options, config);
4804
4867
  return finalOptions;
4805
4868
  }
4806
- async function getHtmlMinifyOptions(isProd6, config) {
4807
- if (!isProd6 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4869
+ async function getHtmlMinifyOptions(isProd7, config) {
4870
+ if (!isProd7 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
4808
4871
  return false;
4809
4872
  }
4810
4873
  const minifyJS = getTerserMinifyOptions(config);
@@ -4854,7 +4917,7 @@ async function getTemplate(entryName, config, rootPath) {
4854
4917
  if (!existTemplatePath.includes(absolutePath)) {
4855
4918
  if (!await isFileExists(absolutePath)) {
4856
4919
  throw new Error(
4857
- `Failed to resolve HTML template, please check if the file exists: ${color11.cyan(
4920
+ `Failed to resolve HTML template, please check if the file exists: ${color12.cyan(
4858
4921
  absolutePath
4859
4922
  )}`
4860
4923
  );
@@ -4913,7 +4976,7 @@ function getTemplateParameters(entryName, config, assetPrefix) {
4913
4976
  function getChunks(entryName, entryValue) {
4914
4977
  const chunks = [entryName];
4915
4978
  for (const item of entryValue) {
4916
- if (!isPlainObject3(item)) {
4979
+ if (!isPlainObject4(item)) {
4917
4980
  continue;
4918
4981
  }
4919
4982
  const { dependOn } = item;
@@ -4939,7 +5002,7 @@ var init_html = __esm({
4939
5002
  existTemplatePath = [];
4940
5003
  getTagConfig = (api) => {
4941
5004
  const config = api.getNormalizedConfig();
4942
- const tags = castArray5(config.html.tags).filter(Boolean);
5005
+ const tags = castArray7(config.html.tags).filter(Boolean);
4943
5006
  if (!tags.length) {
4944
5007
  return void 0;
4945
5008
  }
@@ -4954,12 +5017,12 @@ var init_html = __esm({
4954
5017
  name: "rsbuild:html",
4955
5018
  setup(api) {
4956
5019
  api.modifyBundlerChain(
4957
- async (chain, { HtmlPlugin, isProd: isProd6, CHAIN_ID: CHAIN_ID3, target }) => {
5020
+ async (chain, { HtmlPlugin, isProd: isProd7, CHAIN_ID: CHAIN_ID3, target }) => {
4958
5021
  const config = api.getNormalizedConfig();
4959
5022
  if (isHtmlDisabled(config, target)) {
4960
5023
  return;
4961
5024
  }
4962
- const minify = await getHtmlMinifyOptions(isProd6, config);
5025
+ const minify = await getHtmlMinifyOptions(isProd7, config);
4963
5026
  const assetPrefix = getPublicPathFromChain(chain, false);
4964
5027
  const entries = chain.entryPoints.entries() || {};
4965
5028
  const entryNames = Object.keys(entries);
@@ -5035,7 +5098,7 @@ var init_html = __esm({
5035
5098
  }
5036
5099
  if (appIcon) {
5037
5100
  const { HtmlAppIconPlugin: HtmlAppIconPlugin2 } = await Promise.resolve().then(() => (init_HtmlAppIconPlugin(), HtmlAppIconPlugin_exports));
5038
- const distDir = getDistPath5(config, "image");
5101
+ const distDir = config.output.distPath.image;
5039
5102
  const iconPath = path9.isAbsolute(appIcon) ? appIcon : path9.join(api.context.rootPath, appIcon);
5040
5103
  chain.plugin(CHAIN_ID3.PLUGIN.APP_ICON).use(HtmlAppIconPlugin2, [{ iconPath, distDir }]);
5041
5104
  }
@@ -5070,8 +5133,7 @@ var wasm_exports = {};
5070
5133
  __export(wasm_exports, {
5071
5134
  pluginWasm: () => pluginWasm
5072
5135
  });
5073
- import { posix as posix3 } from "path";
5074
- import { getDistPath as getDistPath6 } from "@rsbuild/shared";
5136
+ import { posix as posix4 } from "path";
5075
5137
  var pluginWasm;
5076
5138
  var init_wasm = __esm({
5077
5139
  "src/plugins/wasm.ts"() {
@@ -5082,12 +5144,12 @@ var init_wasm = __esm({
5082
5144
  setup(api) {
5083
5145
  api.modifyBundlerChain(async (chain, { CHAIN_ID: CHAIN_ID3 }) => {
5084
5146
  const config = api.getNormalizedConfig();
5085
- const distPath = getDistPath6(config, "wasm");
5147
+ const distPath = config.output.distPath.wasm;
5086
5148
  chain.experiments({
5087
5149
  ...chain.get("experiments"),
5088
5150
  asyncWebAssembly: true
5089
5151
  });
5090
- const wasmFilename = posix3.join(distPath, "[hash].module.wasm");
5152
+ const wasmFilename = posix4.join(distPath, "[hash].module.wasm");
5091
5153
  chain.output.merge({
5092
5154
  webassemblyModuleFilename: wasmFilename
5093
5155
  });
@@ -5137,12 +5199,12 @@ __export(nodeAddons_exports, {
5137
5199
  pluginNodeAddons: () => pluginNodeAddons
5138
5200
  });
5139
5201
  import path10 from "path";
5140
- var getFilename4, pluginNodeAddons;
5202
+ var getFilename3, pluginNodeAddons;
5141
5203
  var init_nodeAddons = __esm({
5142
5204
  "src/plugins/nodeAddons.ts"() {
5143
5205
  "use strict";
5144
5206
  init_esm();
5145
- getFilename4 = (resourcePath) => {
5207
+ getFilename3 = (resourcePath) => {
5146
5208
  let basename2 = "";
5147
5209
  if (resourcePath) {
5148
5210
  const parsed = path10.parse(resourcePath);
@@ -5161,7 +5223,7 @@ var init_nodeAddons = __esm({
5161
5223
  api.transform(
5162
5224
  { test: /\.node$/, targets: ["node"], raw: true },
5163
5225
  ({ code, emitFile, resourcePath }) => {
5164
- const name = getFilename4(resourcePath);
5226
+ const name = getFilename3(resourcePath);
5165
5227
  if (name === null) {
5166
5228
  throw new Error(`Failed to load Node.js addon: "${resourcePath}"`);
5167
5229
  }
@@ -5186,7 +5248,7 @@ var define_exports = {};
5186
5248
  __export(define_exports, {
5187
5249
  pluginDefine: () => pluginDefine
5188
5250
  });
5189
- import { getNodeEnv as getNodeEnv8 } from "@rsbuild/shared";
5251
+ import { getNodeEnv as getNodeEnv7 } from "@rsbuild/shared";
5190
5252
  var pluginDefine;
5191
5253
  var init_define = __esm({
5192
5254
  "src/plugins/define.ts"() {
@@ -5199,7 +5261,7 @@ var init_define = __esm({
5199
5261
  api.modifyBundlerChain((chain, { CHAIN_ID: CHAIN_ID3, bundler }) => {
5200
5262
  const config = api.getNormalizedConfig();
5201
5263
  const builtinVars = {
5202
- "process.env.NODE_ENV": JSON.stringify(getNodeEnv8()),
5264
+ "process.env.NODE_ENV": JSON.stringify(getNodeEnv7()),
5203
5265
  "process.env.ASSET_PREFIX": JSON.stringify(
5204
5266
  getPublicPathFromChain(chain, false)
5205
5267
  )
@@ -5218,13 +5280,14 @@ var progress_exports = {};
5218
5280
  __export(progress_exports, {
5219
5281
  pluginProgress: () => pluginProgress
5220
5282
  });
5221
- import { TARGET_ID_MAP as TARGET_ID_MAP3, isProd as isProd3 } from "@rsbuild/shared";
5283
+ import { isProd as isProd4 } from "@rsbuild/shared";
5222
5284
  import { rspack as rspack7 } from "@rspack/core";
5223
5285
  var pluginProgress;
5224
5286
  var init_progress = __esm({
5225
5287
  "src/plugins/progress.ts"() {
5226
5288
  "use strict";
5227
5289
  init_esm();
5290
+ init_constants();
5228
5291
  pluginProgress = () => ({
5229
5292
  name: "rsbuild:progress",
5230
5293
  setup(api) {
@@ -5234,11 +5297,11 @@ var init_progress = __esm({
5234
5297
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID: CHAIN_ID3 }) => {
5235
5298
  const config = api.getNormalizedConfig();
5236
5299
  const options = config.dev.progressBar ?? // enable progress bar in production by default
5237
- isProd3();
5300
+ isProd4();
5238
5301
  if (!options) {
5239
5302
  return;
5240
5303
  }
5241
- const prefix = options !== true && options.id !== void 0 ? options.id : TARGET_ID_MAP3[target];
5304
+ const prefix = options !== true && options.id !== void 0 ? options.id : TARGET_ID_MAP[target];
5242
5305
  chain.plugin(CHAIN_ID3.PLUGIN.PROGRESS).use(rspack7.ProgressPlugin, [
5243
5306
  {
5244
5307
  prefix,
@@ -5265,7 +5328,6 @@ import {
5265
5328
  deepmerge as deepmerge5,
5266
5329
  getBrowserslistWithDefault as getBrowserslistWithDefault3,
5267
5330
  getCoreJsVersion,
5268
- isWebTarget,
5269
5331
  reduceConfigs as reduceConfigs2
5270
5332
  } from "@rsbuild/shared";
5271
5333
  async function getDefaultSwcConfig(config, rootPath, target) {
@@ -5328,6 +5390,7 @@ var init_swc = __esm({
5328
5390
  "use strict";
5329
5391
  init_esm();
5330
5392
  init_constants();
5393
+ init_helpers();
5331
5394
  builtinSwcLoaderName = "builtin:swc-loader";
5332
5395
  pluginSwc = () => ({
5333
5396
  name: PLUGIN_SWC_NAME,
@@ -5643,12 +5706,7 @@ __export(open_exports, {
5643
5706
  });
5644
5707
  import { exec } from "child_process";
5645
5708
  import { promisify } from "util";
5646
- import {
5647
- canParse,
5648
- castArray as castArray6,
5649
- debug as debug7,
5650
- logger as logger13
5651
- } from "@rsbuild/shared";
5709
+ import { castArray as castArray8 } from "@rsbuild/shared";
5652
5710
  async function openBrowser(url2) {
5653
5711
  const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
5654
5712
  if (shouldTryOpenChromeWithAppleScript) {
@@ -5665,10 +5723,10 @@ async function openBrowser(url2) {
5665
5723
  );
5666
5724
  return true;
5667
5725
  }
5668
- debug7("Failed to find the target browser.");
5726
+ logger.debug("Failed to find the target browser.");
5669
5727
  } catch (err) {
5670
- debug7("Failed to open start URL with apple script.");
5671
- logger13.debug(err);
5728
+ logger.debug("Failed to open start URL with apple script.");
5729
+ logger.debug(err);
5672
5730
  }
5673
5731
  }
5674
5732
  try {
@@ -5676,8 +5734,8 @@ async function openBrowser(url2) {
5676
5734
  await open(url2);
5677
5735
  return true;
5678
5736
  } catch (err) {
5679
- logger13.error("Failed to open start URL.");
5680
- logger13.error(err);
5737
+ logger.error("Failed to open start URL.");
5738
+ logger.error(err);
5681
5739
  return false;
5682
5740
  }
5683
5741
  }
@@ -5746,6 +5804,8 @@ var init_open = __esm({
5746
5804
  "use strict";
5747
5805
  init_esm();
5748
5806
  init_constants();
5807
+ init_helpers();
5808
+ init_logger();
5749
5809
  execAsync = promisify(exec);
5750
5810
  supportedChromiumBrowsers = [
5751
5811
  "Google Chrome Canary",
@@ -5783,7 +5843,7 @@ var init_open = __esm({
5783
5843
  return { targets: open, before: beforeStartUrl };
5784
5844
  }
5785
5845
  return {
5786
- targets: open.target ? castArray6(open.target) : [],
5846
+ targets: open.target ? castArray8(open.target) : [],
5787
5847
  before: open.before
5788
5848
  };
5789
5849
  };
@@ -5795,9 +5855,8 @@ var InlineChunkHtmlPlugin_exports = {};
5795
5855
  __export(InlineChunkHtmlPlugin_exports, {
5796
5856
  InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
5797
5857
  });
5798
- import { join as join10 } from "path";
5858
+ import { join as join9 } from "path";
5799
5859
  import {
5800
- addTrailingSlash as addTrailingSlash2,
5801
5860
  getPublicPathFromCompiler as getPublicPathFromCompiler3,
5802
5861
  isFunction as isFunction7
5803
5862
  } from "@rsbuild/shared";
@@ -5806,6 +5865,7 @@ var init_InlineChunkHtmlPlugin = __esm({
5806
5865
  "src/rspack/InlineChunkHtmlPlugin.ts"() {
5807
5866
  "use strict";
5808
5867
  init_esm();
5868
+ init_helpers();
5809
5869
  init_pluginHelper();
5810
5870
  InlineChunkHtmlPlugin = class {
5811
5871
  constructor({
@@ -5838,8 +5898,8 @@ var init_InlineChunkHtmlPlugin = __esm({
5838
5898
  const { devtool } = compilation.options;
5839
5899
  if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
5840
5900
  !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
5841
- const prefix = addTrailingSlash2(
5842
- join10(publicPath, this.distPath[type] || "")
5901
+ const prefix = addTrailingSlash(
5902
+ join9(publicPath, this.distPath[type] || "")
5843
5903
  );
5844
5904
  return source.replace(
5845
5905
  /# sourceMappingURL=/,
@@ -5978,8 +6038,7 @@ __export(inlineChunk_exports, {
5978
6038
  });
5979
6039
  import {
5980
6040
  JS_REGEX as JS_REGEX2,
5981
- isHtmlDisabled as isHtmlDisabled2,
5982
- pick
6041
+ isHtmlDisabled as isHtmlDisabled2
5983
6042
  } from "@rsbuild/shared";
5984
6043
  var pluginInlineChunk;
5985
6044
  var init_inlineChunk = __esm({
@@ -5987,6 +6046,7 @@ var init_inlineChunk = __esm({
5987
6046
  "use strict";
5988
6047
  init_esm();
5989
6048
  init_constants();
6049
+ init_helpers();
5990
6050
  pluginInlineChunk = () => ({
5991
6051
  name: "rsbuild:inline-chunk",
5992
6052
  setup(api) {
@@ -6026,13 +6086,13 @@ var bundleAnalyzer_exports = {};
6026
6086
  __export(bundleAnalyzer_exports, {
6027
6087
  pluginBundleAnalyzer: () => pluginBundleAnalyzer
6028
6088
  });
6029
- import { isProd as isProd4 } from "@rsbuild/shared";
6089
+ import { isProd as isProd5 } from "@rsbuild/shared";
6030
6090
  function pluginBundleAnalyzer() {
6031
6091
  return {
6032
6092
  name: "rsbuild:bundle-analyzer",
6033
6093
  setup(api) {
6034
6094
  api.modifyRsbuildConfig((config) => {
6035
- if (isProd4() || !isUseAnalyzer(config)) {
6095
+ if (isProd5() || !isUseAnalyzer(config)) {
6036
6096
  return;
6037
6097
  }
6038
6098
  config.dev ||= {};
@@ -6071,12 +6131,13 @@ var rsdoctor_exports = {};
6071
6131
  __export(rsdoctor_exports, {
6072
6132
  pluginRsdoctor: () => pluginRsdoctor
6073
6133
  });
6074
- import { color as color12, logger as logger14 } from "@rsbuild/shared";
6134
+ import { color as color13 } from "@rsbuild/shared";
6075
6135
  var pluginRsdoctor;
6076
6136
  var init_rsdoctor = __esm({
6077
6137
  "src/plugins/rsdoctor.ts"() {
6078
6138
  "use strict";
6079
6139
  init_esm();
6140
+ init_logger();
6080
6141
  pluginRsdoctor = () => ({
6081
6142
  name: "rsbuild:rsdoctor",
6082
6143
  setup(api) {
@@ -6093,8 +6154,8 @@ var init_rsdoctor = __esm({
6093
6154
  });
6094
6155
  module = await import(path14);
6095
6156
  } catch (err) {
6096
- logger14.warn(
6097
- `\`process.env.RSDOCTOR\` enabled, please install ${color12.bold(color12.yellow(packageName))} package.`
6157
+ logger.warn(
6158
+ `\`process.env.RSDOCTOR\` enabled, please install ${color13.bold(color13.yellow(packageName))} package.`
6098
6159
  );
6099
6160
  return;
6100
6161
  }
@@ -6115,7 +6176,7 @@ var init_rsdoctor = __esm({
6115
6176
  isAutoRegister = true;
6116
6177
  }
6117
6178
  if (isAutoRegister) {
6118
- logger14.info(`${color12.bold(color12.yellow(packageName))} enabled.`);
6179
+ logger.info(`${color13.bold(color13.yellow(packageName))} enabled.`);
6119
6180
  }
6120
6181
  });
6121
6182
  }
@@ -6274,9 +6335,7 @@ __export(HtmlPreloadOrPrefetchPlugin_exports, {
6274
6335
  HtmlPreloadOrPrefetchPlugin: () => HtmlPreloadOrPrefetchPlugin
6275
6336
  });
6276
6337
  import {
6277
- getPublicPathFromCompiler as getPublicPathFromCompiler4,
6278
- upperFirst as upperFirst2,
6279
- withPublicPath as withPublicPath3
6338
+ getPublicPathFromCompiler as getPublicPathFromCompiler4
6280
6339
  } from "@rsbuild/shared";
6281
6340
  function filterResourceHints(resourceHints, scripts) {
6282
6341
  return resourceHints.filter(
@@ -6323,7 +6382,7 @@ function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
6323
6382
  const publicPath = getPublicPathFromCompiler4(compilation.compiler);
6324
6383
  const { crossOriginLoading } = compilation.compiler.options.output;
6325
6384
  for (const file of sortedFilteredFiles) {
6326
- const href = withPublicPath3(file, publicPath);
6385
+ const href = ensureAssetPrefix(file, publicPath);
6327
6386
  const attributes = {
6328
6387
  href,
6329
6388
  rel: type
@@ -6356,6 +6415,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6356
6415
  "src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts"() {
6357
6416
  "use strict";
6358
6417
  init_esm();
6418
+ init_helpers();
6359
6419
  init_pluginHelper();
6360
6420
  init_helpers2();
6361
6421
  defaultOptions = {
@@ -6377,7 +6437,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6377
6437
  apply(compiler) {
6378
6438
  compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
6379
6439
  getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(
6380
- `HTML${upperFirst2(this.type)}Plugin`,
6440
+ `HTML${upperFirst(this.type)}Plugin`,
6381
6441
  (htmlPluginData) => {
6382
6442
  this.resourceHints = generateLinks(
6383
6443
  this.options,
@@ -6390,7 +6450,7 @@ var init_HtmlPreloadOrPrefetchPlugin = __esm({
6390
6450
  }
6391
6451
  );
6392
6452
  getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(
6393
- `HTML${upperFirst2(this.type)}Plugin`,
6453
+ `HTML${upperFirst(this.type)}Plugin`,
6394
6454
  (htmlPluginData) => {
6395
6455
  if (this.resourceHints) {
6396
6456
  htmlPluginData.assetTags.styles = [
@@ -6521,7 +6581,7 @@ var server_exports = {};
6521
6581
  __export(server_exports, {
6522
6582
  pluginServer: () => pluginServer
6523
6583
  });
6524
- import { isAbsolute as isAbsolute7, join as join11 } from "path";
6584
+ import { isAbsolute as isAbsolute7, join as join10 } from "path";
6525
6585
  import { fse as fse7 } from "@rsbuild/shared";
6526
6586
  var pluginServer;
6527
6587
  var init_server = __esm({
@@ -6540,7 +6600,7 @@ var init_server = __esm({
6540
6600
  if (!copyOnBuild || !name) {
6541
6601
  continue;
6542
6602
  }
6543
- const normalizedPath = isAbsolute7(name) ? name : join11(api.context.rootPath, name);
6603
+ const normalizedPath = isAbsolute7(name) ? name : join10(api.context.rootPath, name);
6544
6604
  if (!fse7.existsSync(normalizedPath)) {
6545
6605
  continue;
6546
6606
  }
@@ -6798,20 +6858,20 @@ __export(rspackProfile_exports, {
6798
6858
  import inspector from "inspector";
6799
6859
  import path13 from "path";
6800
6860
  import { fse as fse8 } from "@rsbuild/shared";
6801
- import { logger as logger15 } from "@rsbuild/shared";
6802
6861
  import { rspack as rspack9 } from "@rspack/core";
6803
6862
  var stopProfiler, pluginRspackProfile;
6804
6863
  var init_rspackProfile = __esm({
6805
6864
  "src/plugins/rspackProfile.ts"() {
6806
6865
  "use strict";
6807
6866
  init_esm();
6867
+ init_logger();
6808
6868
  stopProfiler = (output, profileSession) => {
6809
6869
  if (!profileSession) {
6810
6870
  return;
6811
6871
  }
6812
6872
  profileSession.post("Profiler.stop", (error, param) => {
6813
6873
  if (error) {
6814
- logger15.error("Failed to generate JS CPU profile:", error);
6874
+ logger.error("Failed to generate JS CPU profile:", error);
6815
6875
  return;
6816
6876
  }
6817
6877
  fse8.writeFileSync(output, JSON.stringify(param.profile));
@@ -6872,7 +6932,7 @@ var init_rspackProfile = __esm({
6872
6932
  rspack9.experimental_cleanupGlobalTrace();
6873
6933
  }
6874
6934
  stopProfiler(cpuProfilePath, profileSession);
6875
- logger15.info(`Saved Rspack profile file to ${profileDir}`);
6935
+ logger.info(`Saved Rspack profile file to ${profileDir}`);
6876
6936
  });
6877
6937
  }
6878
6938
  });
@@ -6884,17 +6944,17 @@ var lazyCompilation_exports = {};
6884
6944
  __export(lazyCompilation_exports, {
6885
6945
  pluginLazyCompilation: () => pluginLazyCompilation
6886
6946
  });
6887
- import { isRegExp } from "@rsbuild/shared";
6888
6947
  var pluginLazyCompilation;
6889
6948
  var init_lazyCompilation = __esm({
6890
6949
  "src/plugins/lazyCompilation.ts"() {
6891
6950
  "use strict";
6892
6951
  init_esm();
6952
+ init_helpers();
6893
6953
  pluginLazyCompilation = () => ({
6894
6954
  name: "rsbuild:lazy-compilation",
6895
6955
  setup(api) {
6896
- api.modifyBundlerChain((chain, { isProd: isProd6, target }) => {
6897
- if (isProd6 || target !== "web") {
6956
+ api.modifyBundlerChain((chain, { isProd: isProd7, target }) => {
6957
+ if (isProd7 || target !== "web") {
6898
6958
  return;
6899
6959
  }
6900
6960
  const config = api.getNormalizedConfig();
@@ -6960,9 +7020,7 @@ __export(sri_exports, {
6960
7020
  import crypto2 from "crypto";
6961
7021
  import {
6962
7022
  isHtmlDisabled as isHtmlDisabled4,
6963
- isProd as isProd5,
6964
- logger as logger16,
6965
- removeLeadingSlash as removeLeadingSlash2
7023
+ isProd as isProd6
6966
7024
  } from "@rsbuild/shared";
6967
7025
  var getAssetName, pluginSri;
6968
7026
  var init_sri = __esm({
@@ -6970,11 +7028,13 @@ var init_sri = __esm({
6970
7028
  "use strict";
6971
7029
  init_esm();
6972
7030
  init_constants();
7031
+ init_helpers();
7032
+ init_logger();
6973
7033
  getAssetName = (url2, assetPrefix) => {
6974
7034
  if (url2.startsWith(assetPrefix)) {
6975
- return removeLeadingSlash2(url2.replace(assetPrefix, ""));
7035
+ return removeLeadingSlash(url2.replace(assetPrefix, ""));
6976
7036
  }
6977
- return removeLeadingSlash2(url2);
7037
+ return removeLeadingSlash(url2);
6978
7038
  };
6979
7039
  pluginSri = () => ({
6980
7040
  name: "rsbuild:sri",
@@ -6983,7 +7043,7 @@ var init_sri = __esm({
6983
7043
  const getAlgorithm = () => {
6984
7044
  const config = api.getNormalizedConfig();
6985
7045
  const { sri } = config.security;
6986
- const enable = sri.enable === "auto" ? isProd5() : sri.enable;
7046
+ const enable = sri.enable === "auto" ? isProd6() : sri.enable;
6987
7047
  if (!enable) {
6988
7048
  return null;
6989
7049
  }
@@ -7050,7 +7110,7 @@ var init_sri = __esm({
7050
7110
  `integrity="${integrity}"`
7051
7111
  );
7052
7112
  } else {
7053
- logger16.debug(
7113
+ logger.debug(
7054
7114
  `[rsbuild:sri] failed to generate integrity for ${assetName}.`
7055
7115
  );
7056
7116
  replacedHtml = replacedHtml.replace(
@@ -7122,12 +7182,12 @@ var nonce_exports = {};
7122
7182
  __export(nonce_exports, {
7123
7183
  pluginNonce: () => pluginNonce
7124
7184
  });
7125
- import { applyToCompiler as applyToCompiler2, createVirtualModule as createVirtualModule2 } from "@rsbuild/shared";
7126
7185
  var pluginNonce;
7127
7186
  var init_nonce = __esm({
7128
7187
  "src/plugins/nonce.ts"() {
7129
7188
  "use strict";
7130
7189
  init_esm();
7190
+ init_helpers();
7131
7191
  pluginNonce = () => ({
7132
7192
  name: "rsbuild:nonce",
7133
7193
  setup(api) {
@@ -7136,7 +7196,7 @@ var init_nonce = __esm({
7136
7196
  if (!nonce) {
7137
7197
  return;
7138
7198
  }
7139
- applyToCompiler2(compiler, (compiler2) => {
7199
+ applyToCompiler(compiler, (compiler2) => {
7140
7200
  const { plugins } = compiler2.options;
7141
7201
  const hasHTML = plugins.some(
7142
7202
  (plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
@@ -7144,7 +7204,7 @@ var init_nonce = __esm({
7144
7204
  if (!hasHTML) {
7145
7205
  return;
7146
7206
  }
7147
- const injectCode = createVirtualModule2(
7207
+ const injectCode = createVirtualModule(
7148
7208
  `__webpack_nonce__ = "${nonce}";`
7149
7209
  );
7150
7210
  new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
@@ -7175,13 +7235,189 @@ var init_nonce = __esm({
7175
7235
  }
7176
7236
  });
7177
7237
 
7238
+ // src/server/prodServer.ts
7239
+ var prodServer_exports = {};
7240
+ __export(prodServer_exports, {
7241
+ RsbuildProdServer: () => RsbuildProdServer,
7242
+ startProdServer: () => startProdServer
7243
+ });
7244
+ import { join as join11 } from "path";
7245
+ import {
7246
+ getNodeEnv as getNodeEnv8,
7247
+ setNodeEnv as setNodeEnv4
7248
+ } from "@rsbuild/shared";
7249
+ async function startProdServer(context, config, { getPortSilently } = {}) {
7250
+ if (!getNodeEnv8()) {
7251
+ setNodeEnv4("production");
7252
+ }
7253
+ const { port, host, https } = await getServerConfig({
7254
+ config,
7255
+ getPortSilently
7256
+ });
7257
+ const { default: connect } = await import("../compiled/connect/index.js");
7258
+ const middlewares = connect();
7259
+ const serverConfig = config.server;
7260
+ const server = new RsbuildProdServer(
7261
+ {
7262
+ pwd: context.rootPath,
7263
+ output: {
7264
+ path: config.output.distPath.root || ROOT_DIST_DIR,
7265
+ assetPrefix: config.output.assetPrefix
7266
+ },
7267
+ serverConfig
7268
+ },
7269
+ middlewares
7270
+ );
7271
+ await context.hooks.onBeforeStartProdServer.call();
7272
+ const httpServer = await createHttpServer({
7273
+ serverConfig,
7274
+ middlewares: server.middlewares
7275
+ });
7276
+ await server.onInit(httpServer);
7277
+ return new Promise((resolve) => {
7278
+ httpServer.listen(
7279
+ {
7280
+ host,
7281
+ port
7282
+ },
7283
+ async () => {
7284
+ const routes = formatRoutes(
7285
+ context.entry,
7286
+ config.output.distPath.html,
7287
+ config.html.outputStructure
7288
+ );
7289
+ await context.hooks.onAfterStartProdServer.call({
7290
+ port,
7291
+ routes
7292
+ });
7293
+ const protocol = https ? "https" : "http";
7294
+ const urls = getAddressUrls({ protocol, port, host });
7295
+ printServerURLs({
7296
+ urls,
7297
+ port,
7298
+ routes,
7299
+ protocol,
7300
+ printUrls: serverConfig.printUrls
7301
+ });
7302
+ const onClose = () => {
7303
+ server.close();
7304
+ httpServer.close();
7305
+ };
7306
+ resolve({
7307
+ port,
7308
+ urls: urls.map((item) => item.url),
7309
+ server: {
7310
+ close: async () => {
7311
+ onClose();
7312
+ }
7313
+ }
7314
+ });
7315
+ }
7316
+ );
7317
+ });
7318
+ }
7319
+ var RsbuildProdServer;
7320
+ var init_prodServer = __esm({
7321
+ "src/server/prodServer.ts"() {
7322
+ "use strict";
7323
+ init_esm();
7324
+ init_constants();
7325
+ init_logger();
7326
+ init_helper();
7327
+ init_httpServer();
7328
+ init_middlewares();
7329
+ RsbuildProdServer = class {
7330
+ constructor(options, middlewares) {
7331
+ __publicField(this, "app");
7332
+ __publicField(this, "options");
7333
+ __publicField(this, "middlewares");
7334
+ this.options = options;
7335
+ this.middlewares = middlewares;
7336
+ }
7337
+ // Complete the preparation of services
7338
+ async onInit(app) {
7339
+ this.app = app;
7340
+ await this.applyDefaultMiddlewares();
7341
+ }
7342
+ async applyDefaultMiddlewares() {
7343
+ const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
7344
+ if (logger.level === "verbose") {
7345
+ this.middlewares.use(await getRequestLoggerMiddleware());
7346
+ }
7347
+ if (compress) {
7348
+ const { default: compression } = await import("../compiled/http-compression/index.js");
7349
+ this.middlewares.use((req, res, next) => {
7350
+ compression({
7351
+ gzip: true,
7352
+ brotli: false
7353
+ })(req, res, next);
7354
+ });
7355
+ }
7356
+ if (headers) {
7357
+ this.middlewares.use((_req, res, next) => {
7358
+ for (const [key, value] of Object.entries(headers)) {
7359
+ res.setHeader(key, value);
7360
+ }
7361
+ next();
7362
+ });
7363
+ }
7364
+ if (proxy) {
7365
+ const { createProxyMiddleware: createProxyMiddleware2 } = await Promise.resolve().then(() => (init_proxy(), proxy_exports));
7366
+ const { middlewares, upgrade } = createProxyMiddleware2(proxy);
7367
+ for (const middleware of middlewares) {
7368
+ this.middlewares.use(middleware);
7369
+ }
7370
+ this.app.on("upgrade", upgrade);
7371
+ }
7372
+ this.applyStaticAssetMiddleware();
7373
+ if (historyApiFallback) {
7374
+ const { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js");
7375
+ const historyApiFallbackMiddleware = connectHistoryApiFallback(
7376
+ historyApiFallback === true ? {} : historyApiFallback
7377
+ );
7378
+ this.middlewares.use(historyApiFallbackMiddleware);
7379
+ await this.applyStaticAssetMiddleware();
7380
+ }
7381
+ this.middlewares.use(faviconFallbackMiddleware);
7382
+ }
7383
+ async applyStaticAssetMiddleware() {
7384
+ const {
7385
+ output: { path: path14, assetPrefix },
7386
+ serverConfig: { htmlFallback },
7387
+ pwd
7388
+ } = this.options;
7389
+ const { default: sirv } = await import("../compiled/sirv/index.js");
7390
+ const assetMiddleware = sirv(join11(pwd, path14), {
7391
+ etag: true,
7392
+ dev: true,
7393
+ ignores: ["favicon.ico"],
7394
+ single: htmlFallback === "index"
7395
+ });
7396
+ this.middlewares.use((req, res, next) => {
7397
+ const url2 = req.url;
7398
+ if (assetPrefix && url2?.startsWith(assetPrefix)) {
7399
+ req.url = url2.slice(assetPrefix.length);
7400
+ assetMiddleware(req, res, (...args) => {
7401
+ req.url = url2;
7402
+ next(...args);
7403
+ });
7404
+ } else {
7405
+ assetMiddleware(req, res, next);
7406
+ }
7407
+ });
7408
+ }
7409
+ close() {
7410
+ }
7411
+ };
7412
+ }
7413
+ });
7414
+
7178
7415
  // src/createRsbuild.ts
7179
7416
  var createRsbuild_exports = {};
7180
7417
  __export(createRsbuild_exports, {
7181
7418
  createRsbuild: () => createRsbuild,
7182
7419
  pickRsbuildConfig: () => pickRsbuildConfig
7183
7420
  });
7184
- import { debug as debug8, pick as pick2 } from "@rsbuild/shared";
7185
7421
  async function applyDefaultPlugins(pluginManager, context) {
7186
7422
  const { pluginBasic: pluginBasic2 } = await Promise.resolve().then(() => (init_basic(), basic_exports));
7187
7423
  const { pluginEntry: pluginEntry2 } = await Promise.resolve().then(() => (init_entry(), entry_exports));
@@ -7271,9 +7507,9 @@ async function createRsbuild(options = {}) {
7271
7507
  );
7272
7508
  const pluginAPI = getPluginAPI({ context, pluginManager });
7273
7509
  context.pluginAPI = pluginAPI;
7274
- debug8("add default plugins");
7510
+ logger.debug("add default plugins");
7275
7511
  await applyDefaultPlugins(pluginManager, context);
7276
- debug8("add default plugins done");
7512
+ logger.debug("add default plugins done");
7277
7513
  const provider = rsbuildConfig.provider || await getRspackProvider();
7278
7514
  const providerInstance = await provider({
7279
7515
  context,
@@ -7281,14 +7517,19 @@ async function createRsbuild(options = {}) {
7281
7517
  rsbuildOptions,
7282
7518
  setCssExtractPlugin
7283
7519
  });
7520
+ const preview = async (options2) => {
7521
+ const { startProdServer: startProdServer2 } = await Promise.resolve().then(() => (init_prodServer(), prodServer_exports));
7522
+ const config = await initRsbuildConfig({ context, pluginManager });
7523
+ return startProdServer2(context, config, options2);
7524
+ };
7284
7525
  const rsbuild = {
7285
- ...pick2(pluginManager, [
7526
+ ...pick(pluginManager, [
7286
7527
  "addPlugins",
7287
7528
  "getPlugins",
7288
7529
  "removePlugins",
7289
7530
  "isPluginExists"
7290
7531
  ]),
7291
- ...pick2(pluginAPI, [
7532
+ ...pick(pluginAPI, [
7292
7533
  "onBeforeBuild",
7293
7534
  "onBeforeCreateCompiler",
7294
7535
  "onBeforeStartDevServer",
@@ -7304,15 +7545,15 @@ async function createRsbuild(options = {}) {
7304
7545
  "getRsbuildConfig",
7305
7546
  "getNormalizedConfig"
7306
7547
  ]),
7307
- ...pick2(providerInstance, [
7548
+ ...pick(providerInstance, [
7308
7549
  "build",
7309
- "preview",
7310
7550
  "initConfigs",
7311
7551
  "inspectConfig",
7312
7552
  "createCompiler",
7313
7553
  "createDevServer",
7314
7554
  "startDevServer"
7315
7555
  ]),
7556
+ preview,
7316
7557
  context: pluginAPI.context
7317
7558
  };
7318
7559
  if (rsbuildConfig.plugins) {
@@ -7327,7 +7568,10 @@ var init_createRsbuild = __esm({
7327
7568
  "use strict";
7328
7569
  init_esm();
7329
7570
  init_createContext();
7571
+ init_helpers();
7330
7572
  init_initPlugins();
7573
+ init_internal();
7574
+ init_logger();
7331
7575
  init_pluginHelper();
7332
7576
  init_pluginManager();
7333
7577
  getRspackProvider = async () => {
@@ -7345,15 +7589,16 @@ var init_createRsbuild = __esm({
7345
7589
  "security",
7346
7590
  "performance",
7347
7591
  "moduleFederation",
7592
+ "environments",
7348
7593
  "_privateMeta"
7349
7594
  ];
7350
- return pick2(rsbuildConfig, keys);
7595
+ return pick(rsbuildConfig, keys);
7351
7596
  };
7352
7597
  }
7353
7598
  });
7354
7599
 
7355
7600
  // src/cli/init.ts
7356
- import { isDev as isDev2, logger as logger17 } from "@rsbuild/shared";
7601
+ import { isDev as isDev2 } from "@rsbuild/shared";
7357
7602
  async function init({
7358
7603
  cliOptions,
7359
7604
  isRestart
@@ -7407,7 +7652,7 @@ async function init({
7407
7652
  });
7408
7653
  } catch (err) {
7409
7654
  if (isRestart) {
7410
- logger17.error(err);
7655
+ logger.error(err);
7411
7656
  } else {
7412
7657
  throw err;
7413
7658
  }
@@ -7420,61 +7665,19 @@ var init_init = __esm({
7420
7665
  init_esm();
7421
7666
  init_config();
7422
7667
  init_loadEnv();
7668
+ init_logger();
7423
7669
  init_restart();
7424
7670
  commonOpts = {};
7425
7671
  }
7426
7672
  });
7427
7673
 
7428
- // src/index.ts
7429
- init_esm();
7430
- import { rspack as rspack10 } from "@rspack/core";
7431
-
7432
- // src/internal.ts
7433
- var internal_exports = {};
7434
- __export(internal_exports, {
7435
- applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7436
- createDevServer: () => createDevServer,
7437
- createPluginManager: () => createPluginManager,
7438
- formatStats: () => formatStats,
7439
- getChainUtils: () => getChainUtils,
7440
- getDevMiddleware: () => getDevMiddleware,
7441
- getHTMLPlugin: () => getHTMLPlugin,
7442
- getStatsOptions: () => getStatsOptions,
7443
- getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7444
- initHooks: () => initHooks,
7445
- initPlugins: () => initPlugins,
7446
- initRsbuildConfig: () => initRsbuildConfig,
7447
- outputInspectConfigFiles: () => outputInspectConfigFiles,
7448
- prepareCli: () => prepareCli,
7449
- runCli: () => runCli,
7450
- setHTMLPlugin: () => setHTMLPlugin,
7451
- startProdServer: () => startProdServer,
7452
- stringifyConfig: () => stringifyConfig
7453
- });
7454
- init_esm();
7455
-
7456
7674
  // src/cli/commands.ts
7457
- init_esm();
7458
- init_helpers();
7459
- init_init();
7460
7675
  import { existsSync } from "fs";
7461
7676
  import { join as join12 } from "path";
7462
- import { color as color13, logger as logger18 } from "@rsbuild/shared";
7677
+ import { color as color14 } from "@rsbuild/shared";
7463
7678
  import { program } from "../compiled/commander/index.js";
7464
- var applyCommonOptions = (command) => {
7465
- command.option(
7466
- "-c --config <config>",
7467
- "specify the configuration file, can be a relative or absolute path"
7468
- ).option(
7469
- "--env-mode <mode>",
7470
- "specify the env mode to load the `.env.[mode]` file"
7471
- );
7472
- };
7473
- var applyServerOptions = (command) => {
7474
- 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");
7475
- };
7476
7679
  function runCli() {
7477
- program.name("rsbuild").usage("<command> [options]").version("0.7.7");
7680
+ program.name("rsbuild").usage("<command> [options]").version("0.7.9");
7478
7681
  const devCommand = program.command("dev");
7479
7682
  const buildCommand = program.command("build");
7480
7683
  const previewCommand = program.command("preview");
@@ -7488,8 +7691,8 @@ function runCli() {
7488
7691
  const rsbuild = await init({ cliOptions: options });
7489
7692
  await rsbuild?.startDevServer();
7490
7693
  } catch (err) {
7491
- logger18.error("Failed to start dev server.");
7492
- logger18.error(err);
7694
+ logger.error("Failed to start dev server.");
7695
+ logger.error(err);
7493
7696
  process.exit(1);
7494
7697
  }
7495
7698
  });
@@ -7500,8 +7703,8 @@ function runCli() {
7500
7703
  watch: options.watch
7501
7704
  });
7502
7705
  } catch (err) {
7503
- logger18.error("Failed to build.");
7504
- logger18.error(err);
7706
+ logger.error("Failed to build.");
7707
+ logger.error(err);
7505
7708
  process.exit(1);
7506
7709
  }
7507
7710
  });
@@ -7512,14 +7715,14 @@ function runCli() {
7512
7715
  const { distPath } = rsbuild.context;
7513
7716
  if (!existsSync(distPath)) {
7514
7717
  throw new Error(
7515
- `The output directory ${color13.yellow(
7718
+ `The output directory ${color14.yellow(
7516
7719
  distPath
7517
7720
  )} does not exist, please build the project before previewing.`
7518
7721
  );
7519
7722
  }
7520
7723
  if (isEmptyDir(distPath)) {
7521
7724
  throw new Error(
7522
- `The output directory ${color13.yellow(
7725
+ `The output directory ${color14.yellow(
7523
7726
  distPath
7524
7727
  )} is empty, please build the project before previewing.`
7525
7728
  );
@@ -7527,8 +7730,8 @@ function runCli() {
7527
7730
  }
7528
7731
  await rsbuild?.preview();
7529
7732
  } catch (err) {
7530
- logger18.error("Failed to start preview server.");
7531
- logger18.error(err);
7733
+ logger.error("Failed to start preview server.");
7734
+ logger.error(err);
7532
7735
  process.exit(1);
7533
7736
  }
7534
7737
  });
@@ -7542,17 +7745,37 @@ function runCli() {
7542
7745
  writeToDisk: true
7543
7746
  });
7544
7747
  } catch (err) {
7545
- logger18.error("Failed to inspect config.");
7546
- logger18.error(err);
7748
+ logger.error("Failed to inspect config.");
7749
+ logger.error(err);
7547
7750
  process.exit(1);
7548
7751
  }
7549
7752
  });
7550
7753
  program.parse();
7551
7754
  }
7755
+ var applyCommonOptions, applyServerOptions;
7756
+ var init_commands = __esm({
7757
+ "src/cli/commands.ts"() {
7758
+ "use strict";
7759
+ init_esm();
7760
+ init_helpers();
7761
+ init_logger();
7762
+ init_init();
7763
+ applyCommonOptions = (command) => {
7764
+ command.option(
7765
+ "-c --config <config>",
7766
+ "specify the configuration file, can be a relative or absolute path"
7767
+ ).option(
7768
+ "--env-mode <mode>",
7769
+ "specify the env mode to load the `.env.[mode]` file"
7770
+ );
7771
+ };
7772
+ applyServerOptions = (command) => {
7773
+ 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");
7774
+ };
7775
+ }
7776
+ });
7552
7777
 
7553
7778
  // src/cli/prepare.ts
7554
- init_esm();
7555
- import { logger as logger19 } from "@rsbuild/shared";
7556
7779
  function initNodeEnv() {
7557
7780
  if (!process.env.NODE_ENV) {
7558
7781
  const command = process.argv[2];
@@ -7565,44 +7788,86 @@ function prepareCli() {
7565
7788
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
7566
7789
  console.log();
7567
7790
  }
7568
- logger19.greet(` ${`Rsbuild v${"0.7.7"}`}
7791
+ logger.greet(` ${`Rsbuild v${"0.7.9"}`}
7569
7792
  `);
7570
7793
  }
7794
+ var init_prepare = __esm({
7795
+ "src/cli/prepare.ts"() {
7796
+ "use strict";
7797
+ init_esm();
7798
+ init_logger();
7799
+ }
7800
+ });
7571
7801
 
7572
7802
  // src/internal.ts
7573
- init_pluginManager();
7574
- init_initHooks();
7575
- init_initConfigs();
7576
- init_config();
7577
- init_pluginHelper();
7578
- init_helpers();
7579
- init_rspackConfig();
7580
- init_swc();
7581
- init_minimize();
7582
- init_devMiddleware();
7583
-
7584
- // src/server/index.ts
7585
- init_esm();
7586
- init_devServer();
7587
- init_prodServer();
7803
+ var internal_exports = {};
7804
+ __export(internal_exports, {
7805
+ TARGET_ID_MAP: () => TARGET_ID_MAP,
7806
+ applySwcDecoratorConfig: () => applySwcDecoratorConfig,
7807
+ chainToConfig: () => chainToConfig,
7808
+ createDevServer: () => createDevServer,
7809
+ createPluginManager: () => createPluginManager,
7810
+ formatStats: () => formatStats,
7811
+ getChainUtils: () => getChainUtils,
7812
+ getDevMiddleware: () => getDevMiddleware,
7813
+ getHTMLPlugin: () => getHTMLPlugin,
7814
+ getStatsOptions: () => getStatsOptions,
7815
+ getSwcMinimizerOptions: () => getSwcMinimizerOptions,
7816
+ initHooks: () => initHooks,
7817
+ initPlugins: () => initPlugins,
7818
+ initRsbuildConfig: () => initRsbuildConfig,
7819
+ modifyBundlerChain: () => modifyBundlerChain,
7820
+ onCompileDone: () => onCompileDone,
7821
+ outputInspectConfigFiles: () => outputInspectConfigFiles,
7822
+ prepareCli: () => prepareCli,
7823
+ runCli: () => runCli,
7824
+ setHTMLPlugin: () => setHTMLPlugin,
7825
+ stringifyConfig: () => stringifyConfig
7826
+ });
7827
+ var init_internal = __esm({
7828
+ "src/internal.ts"() {
7829
+ "use strict";
7830
+ init_esm();
7831
+ init_commands();
7832
+ init_prepare();
7833
+ init_pluginManager();
7834
+ init_initHooks();
7835
+ init_initConfigs();
7836
+ init_config();
7837
+ init_pluginHelper();
7838
+ init_helpers();
7839
+ init_rspackConfig();
7840
+ init_configChain();
7841
+ init_swc();
7842
+ init_minimize();
7843
+ init_devMiddleware();
7844
+ init_devServer();
7845
+ init_constants();
7846
+ }
7847
+ });
7588
7848
 
7589
7849
  // src/index.ts
7850
+ init_esm();
7851
+ init_internal();
7590
7852
  init_loadEnv();
7591
7853
  init_createRsbuild();
7592
7854
  init_config();
7855
+ init_logger();
7593
7856
  init_mergeConfig();
7857
+ init_helpers();
7594
7858
  init_constants();
7595
- import { logger as logger20 } from "@rsbuild/shared";
7596
- var version = "0.7.7";
7859
+ import { rspack as rspack10 } from "@rspack/core";
7860
+ var version = "0.7.9";
7597
7861
  export {
7598
7862
  PLUGIN_CSS_NAME,
7599
7863
  PLUGIN_SWC_NAME,
7600
7864
  internal_exports as __internalHelper,
7601
7865
  createRsbuild,
7602
7866
  defineConfig,
7867
+ ensureAssetPrefix,
7603
7868
  loadConfig,
7604
7869
  loadEnv,
7605
- logger20 as logger,
7870
+ logger,
7606
7871
  mergeRsbuildConfig,
7607
7872
  rspack10 as rspack,
7608
7873
  version