@rsbuild/core 2.1.4 → 2.1.6

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 (38) hide show
  1. package/compiled/@rstackjs/load-config/index.d.ts +66 -0
  2. package/compiled/@rstackjs/load-config/license +21 -0
  3. package/compiled/@rstackjs/load-config/package.json +1 -0
  4. package/compiled/css-loader/index.js +2 -2
  5. package/compiled/html-rspack-plugin/index.d.ts +4 -4
  6. package/compiled/html-rspack-plugin/index.js +53 -48
  7. package/compiled/http-proxy-middleware/index.d.ts +2 -1
  8. package/compiled/http-proxy-middleware/package.json +1 -1
  9. package/compiled/jiti/dist/babel.cjs +49 -2
  10. package/compiled/postcss/index.js +1 -1
  11. package/compiled/postcss/package.json +1 -1
  12. package/compiled/postcss-loader/index.js +6 -6
  13. package/compiled/rslog/index.d.ts +7 -14
  14. package/compiled/rslog/package.json +1 -1
  15. package/dist/{756.js → 711.js} +162 -237
  16. package/dist/chokidar.js +33 -33
  17. package/dist/client/hmr.js +1 -1
  18. package/dist/client/overlay.js +1 -1
  19. package/dist/connect-next.js +3 -3
  20. package/dist/cssUrlLoader.mjs +1 -1
  21. package/dist/http-proxy-middleware.js +29 -10
  22. package/dist/ignoreCssLoader.mjs +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/launch-editor-middleware.js +1 -1
  25. package/dist/manifest-plugin.js +38 -34
  26. package/dist/memfs.js +370 -202
  27. package/dist/sirv.js +7 -7
  28. package/dist/ws.js +1 -1
  29. package/dist-types/configChain.d.ts +1 -0
  30. package/dist-types/constants.d.ts +2 -0
  31. package/dist-types/loadConfig.d.ts +4 -39
  32. package/dist-types/types/config.d.ts +7 -5
  33. package/package.json +9 -8
  34. package/types.d.ts +24 -0
  35. /package/dist/{349.js → 252.js} +0 -0
  36. /package/dist/{756.js.LICENSE.txt → 711.js.LICENSE.txt} +0 -0
  37. /package/dist/client/{60.js → 307.js} +0 -0
  38. /package/dist/{fresh-import.js → freshImport.js} +0 -0
@@ -1,13 +1,12 @@
1
- /*! LICENSE: 756.js.LICENSE.txt */
2
- let flagForceColor, runtimeProcessArgs, runtimeInfo, swcHelpersPath, pluginHelper_htmlPlugin;
1
+ /*! LICENSE: 711.js.LICENSE.txt */
2
+ let runtimeProcessArgs, runtimeInfo, swcHelpersPath, pluginHelper_htmlPlugin;
3
3
  import { rspack as core_rspack } from "@rspack/core";
4
4
  import node_util, { stripVTControlCharacters } from "node:util";
5
- import node_process from "node:process";
6
- import node_os, { constants as external_node_os_constants } from "node:os";
7
- import node_tty from "node:tty";
8
5
  import node_path, { dirname as external_node_path_dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, resolve as external_node_path_resolve, sep, win32 } from "node:path";
9
6
  import { builtinModules, createRequire, createRequire as __rspack_createRequire } from "node:module";
10
7
  import node_fs, { existsSync } from "node:fs";
8
+ import node_os, { constants as external_node_os_constants } from "node:os";
9
+ import node_process from "node:process";
11
10
  import { URL as external_node_url_URL, pathToFileURL, fileURLToPath as __rspack_fileURLToPath } from "node:url";
12
11
  import { isPromise, isRegExp } from "node:util/types";
13
12
  import { readFile } from "node:fs/promises";
@@ -387,8 +386,8 @@ __webpack_require__.add({
387
386
  return (asyncHooks.AsyncResource && (res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')), res && res.runInAsyncScope) ? res.runInAsyncScope.bind(res, fn, null) : fn;
388
387
  }
389
388
  },
390
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
391
- let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
389
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
390
+ let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/req.js");
392
391
  async function processResult(ctx, result) {
393
392
  let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
394
393
  default: obj
@@ -461,8 +460,8 @@ __webpack_require__.add({
461
460
  });
462
461
  };
463
462
  },
464
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
465
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
463
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
464
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/req.js");
466
465
  module.exports = async function options(config, file) {
467
466
  if (config.parser && 'string' == typeof config.parser) try {
468
467
  config.parser = await req(config.parser, file);
@@ -482,8 +481,8 @@ __webpack_require__.add({
482
481
  return config;
483
482
  };
484
483
  },
485
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
486
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
484
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
485
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/req.js");
487
486
  async function load(plugin, options, file) {
488
487
  try {
489
488
  if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
@@ -499,7 +498,7 @@ __webpack_require__.add({
499
498
  }), list;
500
499
  };
501
500
  },
502
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
501
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
503
502
  let tsx, jiti, { createRequire } = __webpack_require__("node:module?1bcb"), { pathToFileURL } = __webpack_require__("node:url?b4ec"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
504
503
  module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
505
504
  let url = createRequire(rootFile).resolve(name);
@@ -625,135 +624,33 @@ let createStyler = (style)=>(text)=>node_util.styleText(style, String(text)), co
625
624
  magenta: createStyler('magenta'),
626
625
  underline: createStyler('underline'),
627
626
  strikethrough: createStyler('strikethrough')
628
- };
629
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
630
- let prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--', position = argv.indexOf(prefix + flag), terminatorPosition = argv.indexOf('--');
631
- return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
632
- }
633
- let { env: dist_env } = node_process;
634
- function envForceColor() {
635
- if (!('FORCE_COLOR' in dist_env)) return;
636
- if ('true' === dist_env.FORCE_COLOR) return 1;
637
- if ('false' === dist_env.FORCE_COLOR) return 0;
638
- if (0 === dist_env.FORCE_COLOR.length) return 1;
639
- let level = Math.min(Number.parseInt(dist_env.FORCE_COLOR, 10), 3);
640
- if ([
641
- 0,
642
- 1,
643
- 2,
644
- 3
645
- ].includes(level)) return level;
646
- }
647
- function translateLevel(level) {
648
- return 0 !== level && {
649
- level,
650
- hasBasic: !0,
651
- has256: level >= 2,
652
- has16m: level >= 3
653
- };
654
- }
655
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = !0 } = {}) {
656
- let noFlagForceColor = envForceColor();
657
- void 0 !== noFlagForceColor && (flagForceColor = noFlagForceColor);
658
- let forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
659
- if (0 === forceColor) return 0;
660
- if (sniffFlags) {
661
- if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) return 3;
662
- if (hasFlag('color=256')) return 2;
663
- }
664
- if ('TF_BUILD' in dist_env && 'AGENT_NAME' in dist_env) return 1;
665
- if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
666
- let min = forceColor || 0;
667
- if ('dumb' === dist_env.TERM) return min;
668
- if ('win32' === node_process.platform) {
669
- let osRelease = node_os.release().split('.');
670
- return Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586 ? Number(osRelease[2]) >= 14931 ? 3 : 2 : 1;
671
- }
672
- if ('CI' in dist_env) return [
673
- 'GITHUB_ACTIONS',
674
- 'GITEA_ACTIONS',
675
- 'CIRCLECI'
676
- ].some((key)=>key in dist_env) ? 3 : [
677
- 'TRAVIS',
678
- 'APPVEYOR',
679
- 'GITLAB_CI',
680
- 'BUILDKITE',
681
- 'DRONE'
682
- ].some((sign)=>sign in dist_env) || 'codeship' === dist_env.CI_NAME ? 1 : min;
683
- if ('TEAMCITY_VERSION' in dist_env) return +!!/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(dist_env.TEAMCITY_VERSION);
684
- if ('truecolor' === dist_env.COLORTERM || 'xterm-kitty' === dist_env.TERM || 'xterm-ghostty' === dist_env.TERM || 'wezterm' === dist_env.TERM) return 3;
685
- if ('TERM_PROGRAM' in dist_env) {
686
- let version = Number.parseInt((dist_env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
687
- switch(dist_env.TERM_PROGRAM){
688
- case 'iTerm.app':
689
- return version >= 3 ? 3 : 2;
690
- case 'Apple_Terminal':
691
- return 2;
692
- }
693
- }
694
- return /-256(color)?$/i.test(dist_env.TERM) ? 2 : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(dist_env.TERM) || 'COLORTERM' in dist_env ? 1 : min;
695
- }
696
- function createSupportsColor(stream, options = {}) {
697
- return translateLevel(_supportsColor(stream, {
698
- streamIsTTY: stream && stream.isTTY,
699
- ...options
700
- }));
701
- }
702
- hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never') ? flagForceColor = 0 : (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) && (flagForceColor = 1);
703
- let supportsColor = {
704
- stdout: createSupportsColor({
705
- isTTY: node_tty.isatty(1)
706
- }),
707
- stderr: createSupportsColor({
708
- isTTY: node_tty.isatty(2)
709
- })
710
- }, colorLevel = supportsColor.stdout ? supportsColor.stdout.level : 0, errorStackRegExp = /at [^\r\n]{0,200}:\d+:\d+[\s\)]*$/, anonymousErrorStackRegExp = /at [^\r\n]{0,200}\(<anonymous>\)$/, indexErrorStackRegExp = /at [^\r\n]{0,200}\(index\s\d+\)$/, isWord = (char)=>!/[\s\n]/.test(char), LOG_LEVEL = {
627
+ }, supportsTrueColor = !0 === process.stdout.isTTY && process.stdout.hasColors(16777216, process.env), LOG_LEVEL = {
711
628
  silent: -1,
712
629
  error: 0,
713
630
  warn: 1,
714
631
  info: 2,
715
632
  log: 2,
716
633
  verbose: 3
634
+ }, createLogType = (label, level, style)=>{
635
+ let formattedLabel;
636
+ return {
637
+ get label () {
638
+ return formattedLabel ??= color.bold(style(label.padEnd(7)));
639
+ },
640
+ level
641
+ };
717
642
  }, LOG_TYPES = {
718
- error: {
719
- label: 'error',
720
- level: 'error',
721
- color: color.red
722
- },
723
- warn: {
724
- label: 'warn',
725
- level: 'warn',
726
- color: color.yellow
727
- },
728
- info: {
729
- label: 'info',
730
- level: 'info',
731
- color: color.cyan
732
- },
733
- start: {
734
- label: 'start',
735
- level: 'info',
736
- color: color.cyan
737
- },
738
- ready: {
739
- label: 'ready',
740
- level: 'info',
741
- color: color.green
742
- },
743
- success: {
744
- label: 'success',
745
- level: 'info',
746
- color: color.green
747
- },
643
+ error: createLogType('error', 'error', color.red),
644
+ warn: createLogType('warn', 'warn', color.yellow),
645
+ info: createLogType('info', 'info', color.cyan),
646
+ start: createLogType('start', 'info', color.cyan),
647
+ ready: createLogType('ready', 'info', color.green),
648
+ success: createLogType('success', 'info', color.green),
748
649
  log: {
749
650
  level: 'info'
750
651
  },
751
- debug: {
752
- label: 'debug',
753
- level: 'verbose',
754
- color: color.magenta
755
- }
756
- }, normalizeErrorMessage = (err)=>{
652
+ debug: createLogType('debug', 'verbose', color.magenta)
653
+ }, errorStackRegExp = /at [^\r\n]{0,200}(?::\d+:\d+[\s)]*|\(<anonymous>\)|\(index\s\d+\))$/, normalizeErrorMessage = (err)=>{
757
654
  if (err.stack) {
758
655
  let [rawName, ...rest] = err.stack.split('\n'), name = rawName.startsWith('Error: ') ? rawName.slice(7) : rawName;
759
656
  return `${name}\n${color.gray(rest.join('\n'))}`;
@@ -764,22 +661,15 @@ let supportsColor = {
764
661
  let logType = LOG_TYPES[type], { level } = logType;
765
662
  if (LOG_LEVEL[level] > LOG_LEVEL[maxLevel]) return;
766
663
  if (null == message) return console1.log();
767
- let label = '', text = '';
768
- if ('label' in logType && (label = (logType.label || '').padEnd(7), label = color.bold(logType.color ? logType.color(label) : label)), message instanceof Error) {
664
+ let label = 'label' in logType ? logType.label : '', text = '';
665
+ if (message instanceof Error) {
769
666
  text += normalizeErrorMessage(message);
770
667
  let { cause } = message;
771
668
  cause && (text += color.yellow('\n [cause]: '), text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause));
772
- } else text = 'error' === level && 'string' == typeof message ? message.split('\n').map((line)=>errorStackRegExp.test(line) || anonymousErrorStackRegExp.test(line) || indexErrorStackRegExp.test(line) ? color.gray(line) : line).join('\n') : `${message}`;
773
- prefix && (text = `${prefix} ${text}`), console1['error' === level || 'warn' === level ? level : 'log'](label.length ? `${label} ${text}` : text, ...args);
669
+ } else text = 'error' === level && 'string' == typeof message ? message.split('\n').map((line)=>errorStackRegExp.test(line) ? color.gray(line) : line).join('\n') : `${message}`;
670
+ prefix && (text = `${prefix} ${text}`), console1['error' === level || 'warn' === level ? level : 'log'](label ? `${label} ${text}` : text, ...args);
774
671
  }, logger = {
775
- greet: (message)=>log('log', ((message)=>{
776
- if (colorLevel < 3) return 2 === colorLevel ? color.cyan(message) : message;
777
- let chars = [
778
- ...message
779
- ], steps = chars.filter(isWord).length, r = 189, g = 255, b = 243, rStep = -115 / steps, gStep = -61 / steps, bStep = -89 / steps, output = '';
780
- for (let char of chars)isWord(char) && (r += rStep, g += gStep, b += bStep), output += `\x1b[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1b[39m`;
781
- return color.bold(output);
782
- })(message))
672
+ greet: (message)=>log('log', supportsTrueColor ? `\x1b[1;38;2;132;225;199m${message}\x1b[39;22m` : color.bold(color.cyan(message)))
783
673
  };
784
674
  return Object.keys(LOG_TYPES).forEach((key)=>{
785
675
  logger[key] = (...args)=>log(key, ...args);
@@ -1222,6 +1112,10 @@ let isDeno = "u" > typeof Deno, isWindows = 'win32' === process.platform, dirnam
1222
1112
  'ttf',
1223
1113
  'otf',
1224
1114
  'ttc'
1115
+ ], ASSET_EXTENSIONS = [
1116
+ 'webmanifest',
1117
+ 'pdf',
1118
+ 'txt'
1225
1119
  ], IMAGE_EXTENSIONS = [
1226
1120
  'png',
1227
1121
  'jpg',
@@ -1237,7 +1131,8 @@ let isDeno = "u" > typeof Deno, isWindows = 'win32' === process.platform, dirnam
1237
1131
  'tif',
1238
1132
  'tiff',
1239
1133
  'jfif',
1240
- 'cur'
1134
+ 'cur',
1135
+ 'jxl'
1241
1136
  ], VIDEO_EXTENSIONS = [
1242
1137
  'mp4',
1243
1138
  'webm',
@@ -1250,6 +1145,8 @@ let isDeno = "u" > typeof Deno, isWindows = 'win32' === process.platform, dirnam
1250
1145
  'aac',
1251
1146
  'm4a',
1252
1147
  'opus'
1148
+ ], TRACK_EXTENSIONS = [
1149
+ 'vtt'
1253
1150
  ], LAZY_COMPILATION_IDENTIFIER = 'lazy-compilation-proxy';
1254
1151
  var __webpack_modules__ = {}, __webpack_module_cache__ = {};
1255
1152
  function __nested_rspack_require_65__(moduleId) {
@@ -3445,7 +3342,9 @@ function getBrowserslist(path) {
3445
3342
  }
3446
3343
  function getBrowserslistByEnvironment(path, config) {
3447
3344
  let { target, overrideBrowserslist } = config.output;
3448
- if (Array.isArray(overrideBrowserslist)) return overrideBrowserslist;
3345
+ if (Array.isArray(overrideBrowserslist)) return [
3346
+ ...overrideBrowserslist
3347
+ ];
3449
3348
  if ('web' === target || 'web-worker' === target) {
3450
3349
  let browserslistrc = getBrowserslist(path);
3451
3350
  if (browserslistrc) return browserslistrc;
@@ -3500,7 +3399,7 @@ function createPublicContext(context) {
3500
3399
  async function createContext(options, userConfig, logger) {
3501
3400
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
3502
3401
  return {
3503
- version: "2.1.4",
3402
+ version: "2.1.6",
3504
3403
  rootPath,
3505
3404
  distPath: '',
3506
3405
  cachePath,
@@ -3762,6 +3661,7 @@ let configChain_CHAIN_ID = {
3762
3661
  JSON: 'json',
3763
3662
  IMAGE: 'image',
3764
3663
  MEDIA: 'media',
3664
+ ASSETS: 'assets',
3765
3665
  ADDITIONAL_ASSETS: 'additional-assets',
3766
3666
  JS: 'js',
3767
3667
  JS_DATA_URI: 'js-data-uri',
@@ -4338,10 +4238,16 @@ function loadEnv_parse(src) {
4338
4238
  }
4339
4239
  return obj;
4340
4240
  }
4241
+ function validatePrefixes(prefixes) {
4242
+ let invalidIndex = prefixes.findIndex((prefix)=>'' === prefix.trim());
4243
+ if (-1 === invalidIndex) return;
4244
+ let prefix = prefixes[invalidIndex];
4245
+ throw Error(`${color.dim('[rsbuild:loadEnv]')} Invalid ${color.yellow('prefixes')} option: received ${color.yellow(JSON.stringify(prefix))}. ${'' === prefix ? 'An empty string matches every key in processEnv, so every environment variable would be treated as public and could be inlined into client-side code through process.env.* and import.meta.env.* replacements.' : 'A whitespace-only string is not a valid public environment variable prefix because it does not contain any non-whitespace characters.'} Use a prefix with at least one non-whitespace character, such as ${color.yellow('"PUBLIC_"')}.`);
4246
+ }
4341
4247
  function loadEnv({ cwd = process.cwd(), mode = process.env.NODE_ENV || '', prefixes = [
4342
4248
  'PUBLIC_'
4343
4249
  ], processEnv = process.env } = {}) {
4344
- if ('local' === mode) throw Error(`${color.dim('[rsbuild:loadEnv]')} ${color.yellow('local')} cannot be used as a value for env mode, because ${color.yellow('.env.local')} represents a temporary local file. Please use another value.`);
4250
+ if (validatePrefixes(prefixes), 'local' === mode) throw Error(`${color.dim('[rsbuild:loadEnv]')} ${color.yellow('local')} cannot be used as a value for env mode, because ${color.yellow('.env.local')} represents a temporary local file. Please use another value.`);
4345
4251
  let filePaths = [
4346
4252
  '.env',
4347
4253
  '.env.local',
@@ -4937,7 +4843,7 @@ function parseMinifyOptions(config) {
4937
4843
  cssOptions: minify.cssOptions
4938
4844
  };
4939
4845
  }
4940
- let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/index.js");
4846
+ let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.17/node_modules/postcss-load-config/src/index.js");
4941
4847
  var postcss_load_config_src_default = __webpack_require__.n(postcss_load_config_src);
4942
4848
  async function getLightningCSSLoaderOptions(config, targets, minify) {
4943
4849
  let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
@@ -6038,9 +5944,7 @@ function getResourceType({ href, file }) {
6038
5944
  let url = new external_node_url_URL(file || href, 'https://example.com'), extension = node_path.extname(url.pathname).slice(1);
6039
5945
  return [
6040
5946
  'css'
6041
- ].includes(extension) ? 'style' : IMAGE_EXTENSIONS.includes(extension) ? 'image' : VIDEO_EXTENSIONS.includes(extension) ? 'video' : AUDIO_EXTENSIONS.includes(extension) ? 'audio' : FONT_EXTENSIONS.includes(extension) ? 'font' : [
6042
- 'vtt'
6043
- ].includes(extension) ? 'track' : "script";
5947
+ ].includes(extension) ? 'style' : IMAGE_EXTENSIONS.includes(extension) ? 'image' : VIDEO_EXTENSIONS.includes(extension) ? 'video' : AUDIO_EXTENSIONS.includes(extension) ? 'audio' : FONT_EXTENSIONS.includes(extension) ? 'font' : TRACK_EXTENSIONS.includes(extension) ? 'track' : "script";
6044
5948
  }
6045
5949
  let HtmlResourceHintsPlugin_defaultOptions = {
6046
5950
  type: 'async-chunks',
@@ -6135,15 +6039,17 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
6135
6039
  rel,
6136
6040
  ...option
6137
6041
  }
6138
- })), appendExcludes = (options, excludes)=>{
6139
- if (!excludes.length) return options;
6140
- let optionsList = helpers_castArray(options).map((option)=>({
6042
+ })), applyExcludes = (options, defaultExclude, excludes)=>{
6043
+ let optionsList = helpers_castArray(options).map((option)=>{
6044
+ let exclude = option.exclude ?? defaultExclude;
6045
+ return excludes.length || void 0 === option.exclude ? {
6141
6046
  ...option,
6142
- exclude: option.exclude ? [
6143
- ...helpers_castArray(option.exclude),
6047
+ exclude: excludes.length ? [
6048
+ ...helpers_castArray(exclude),
6144
6049
  ...excludes
6145
- ] : excludes
6146
- }));
6050
+ ] : exclude
6051
+ } : option;
6052
+ });
6147
6053
  return Array.isArray(options) ? optionsList : optionsList[0];
6148
6054
  };
6149
6055
  function isTerminalTraceOutput(output) {
@@ -6711,7 +6617,7 @@ function createAssetsMiddleware(context, ready, outputFileSystem) {
6711
6617
  }
6712
6618
  async function setupOutputFileSystem(writeToDisk, compilers) {
6713
6619
  if (!0 !== writeToDisk) {
6714
- let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.57.8/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6620
+ let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.64.0/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6715
6621
  for (let compiler of compilers)compiler.outputFileSystem = outputFileSystem;
6716
6622
  }
6717
6623
  let compiler = compilers.find((compiler)=>!!compiler.outputFileSystem);
@@ -7993,14 +7899,15 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
7993
7899
  });
7994
7900
  }, createCacheableFunction = (getter)=>{
7995
7901
  let cache = new WeakMap();
7996
- return async (stats, entryName, utils)=>{
7902
+ return (stats, entryName, utils)=>{
7997
7903
  let cachedEntries = cache.get(stats);
7998
- if (cachedEntries?.[entryName]) return cachedEntries[entryName];
7999
- let res = await getter(stats, entryName, utils);
8000
- return cache.set(stats, {
8001
- ...cachedEntries || {},
8002
- [entryName]: res
8003
- }), res;
7904
+ cachedEntries || (cachedEntries = new Map(), cache.set(stats, cachedEntries));
7905
+ let cachedPromise = cachedEntries.get(entryName);
7906
+ if (cachedPromise) return cachedPromise;
7907
+ let promise = Promise.resolve().then(()=>getter(stats, entryName, utils)).catch((error)=>{
7908
+ throw cachedEntries.delete(entryName), error;
7909
+ });
7910
+ return cachedEntries.set(entryName, promise), promise;
8004
7911
  };
8005
7912
  }, cleanupCallbacks = new Set(), handleTermination = async (exitCode)=>{
8006
7913
  try {
@@ -8741,8 +8648,9 @@ function applyDefaultPlugins(pluginManager, context) {
8741
8648
  'svg'
8742
8649
  ], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.MEDIA, [
8743
8650
  ...VIDEO_EXTENSIONS,
8744
- ...AUDIO_EXTENSIONS
8745
- ], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.FONT, FONT_EXTENSIONS, emitAssets);
8651
+ ...AUDIO_EXTENSIONS,
8652
+ ...TRACK_EXTENSIONS
8653
+ ], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.FONT, FONT_EXTENSIONS, emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.ASSETS, ASSET_EXTENSIONS, emitAssets);
8746
8654
  let rule = chain.module.rule(configChain_CHAIN_ID.RULE.JSON).test(/\.json$/i);
8747
8655
  rule.oneOf('json-asset-text').type('asset/source').with({
8748
8656
  type: 'text'
@@ -9425,9 +9333,9 @@ try {
9425
9333
  ...scriptTests,
9426
9334
  ...styleTests
9427
9335
  ].filter((item)=>isRegExp(item));
9428
- })(config);
9336
+ })(config), assetExclude = getRegExpForExts(ASSET_EXTENSIONS);
9429
9337
  if (prefetch) {
9430
- let options = appendExcludes(!0 === prefetch ? {} : prefetch, excludes);
9338
+ let options = applyExcludes(!0 === prefetch ? {} : prefetch, assetExclude, excludes);
9431
9339
  chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlResourceHintsPlugin, [
9432
9340
  options,
9433
9341
  'prefetch',
@@ -9437,7 +9345,7 @@ try {
9437
9345
  ]);
9438
9346
  }
9439
9347
  if (preload) {
9440
- let options = appendExcludes(!0 === preload ? {} : preload, excludes);
9348
+ let options = applyExcludes(!0 === preload ? {} : preload, assetExclude, excludes);
9441
9349
  chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlResourceHintsPlugin, [
9442
9350
  options,
9443
9351
  'preload',
@@ -9510,7 +9418,7 @@ try {
9510
9418
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
9511
9419
  let { output: { manifest }, dev: { writeToDisk } } = environment.config;
9512
9420
  if (!1 === manifest) return;
9513
- let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
9421
+ let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.4/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
9514
9422
  manifestFilenames.set(environment.name, manifestOptions.filename);
9515
9423
  let pluginOptions = {
9516
9424
  fileName: manifestOptions.filename,
@@ -9864,61 +9772,59 @@ async function createRsbuild(options = {}) {
9864
9772
  });
9865
9773
  })), rsbuild;
9866
9774
  }
9867
- function defineConfig(config) {
9868
- return config;
9869
- }
9870
- let DEFAULT_CONFIG_FILE_NAMES = [
9871
- 'rsbuild.config.ts',
9872
- 'rsbuild.config.js',
9873
- 'rsbuild.config.mts',
9874
- 'rsbuild.config.mjs',
9875
- 'rsbuild.config.cts',
9876
- 'rsbuild.config.cjs'
9877
- ], canReadExport = (module)=>null !== module && ('object' == typeof module || 'function' == typeof module), getConfigExport = (configModule, exportName, configFilePath)=>{
9775
+ let canReadExport = (module)=>null !== module && ('object' == typeof module || 'function' == typeof module), getConfigExport = (configModule, exportName, configPath)=>{
9878
9776
  if (!1 === exportName) return {};
9879
9777
  if ('default' === exportName) return canReadExport(configModule) && 'default' in configModule ? configModule.default : configModule;
9880
9778
  if (canReadExport(configModule) && Object.hasOwn(configModule, exportName)) return configModule[exportName];
9881
- throw Error(`Cannot find export ${color.yellow(exportName)} in config file: ${color.dim(configFilePath)}`);
9882
- }, tryFreshImport = async (configFileURL)=>{
9779
+ throw Error(`Cannot find export ${exportName} in config file: ${configPath}`);
9780
+ }, loadWithJiti = async (configPath, exportName, fresh)=>{
9781
+ let createJiti;
9883
9782
  try {
9884
- let { freshImport } = await import("./fresh-import.js");
9885
- return await freshImport(configFileURL);
9886
- } catch (err) {
9887
- src_logger.debug('failed to initialize fresh-import, fallback to dynamic import.'), src_logger.debug(err);
9783
+ ({ createJiti } = await import("../compiled/jiti/lib/jiti.mjs"));
9784
+ } catch (error) {
9785
+ throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
9786
+ cause: error
9787
+ });
9888
9788
  }
9889
- }, loadConfigWithNative = async (configFilePath)=>{
9890
- let configFileURL = pathToFileURL(configFilePath).href, freshImportResult = await tryFreshImport(configFileURL);
9891
- return freshImportResult ? {
9892
- configModule: freshImportResult.result,
9893
- dependencies: freshImportResult.dependencies.sort()
9894
- } : {
9895
- configModule: await import(`${configFileURL}?t=${Date.now()}`),
9896
- dependencies: []
9897
- };
9898
- }, loadConfigWithJiti = async (configFilePath, exportName)=>{
9899
- let { createJiti } = await import("../compiled/jiti/lib/jiti.mjs"), jiti = createJiti(import.meta.filename, {
9900
- moduleCache: !1,
9789
+ let jiti = createJiti(configPath, {
9790
+ moduleCache: !fresh,
9901
9791
  interopDefault: !0,
9902
9792
  nativeModules: [
9903
9793
  "typescript"
9904
9794
  ]
9905
9795
  });
9906
9796
  return 'default' === exportName ? {
9907
- configExport: await jiti.import(configFilePath, {
9797
+ configExport: await jiti.import(configPath, {
9908
9798
  default: !0
9909
9799
  }),
9910
9800
  dependencies: []
9911
9801
  } : {
9912
- configExport: getConfigExport(await jiti.import(configFilePath), exportName, configFilePath),
9802
+ configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
9803
+ dependencies: []
9804
+ };
9805
+ }, JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/, loadWithNative = async (configPath, fresh)=>{
9806
+ let configFileURL = pathToFileURL(configPath).href;
9807
+ if (!fresh) return {
9808
+ configModule: await import(configFileURL),
9809
+ dependencies: []
9810
+ };
9811
+ let { freshImport } = await import("./freshImport.js"), freshImportResult = await freshImport(configFileURL);
9812
+ return freshImportResult ? {
9813
+ configModule: freshImportResult.result,
9814
+ dependencies: freshImportResult.dependencies.sort()
9815
+ } : {
9816
+ configModule: await import(`${configFileURL}?t=${Date.now()}`),
9913
9817
  dependencies: []
9914
9818
  };
9915
9819
  };
9916
- async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileNames, envMode, meta, loader = 'auto', command, exportName = 'default' } = {}) {
9917
- let loadedConfig, configFilePath = ((root, customConfig, configFileNames = DEFAULT_CONFIG_FILE_NAMES)=>{
9820
+ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = !1 } = {}) {
9821
+ let loadedConfig;
9822
+ if (!path && 0 === configFileNames.length) throw Error('Either `path` or at least one `configFileNames` entry must be provided.');
9823
+ let configPath = ((root, customConfig, configFileNames = [])=>{
9918
9824
  if (customConfig) {
9919
9825
  let customConfigPath = external_node_path_isAbsolute(customConfig) ? customConfig : join(root, customConfig);
9920
9826
  if (node_fs.existsSync(customConfigPath)) return customConfigPath;
9921
- throw Error(`Cannot find config file: ${color.dim(customConfigPath)}`);
9827
+ throw Error(`Cannot find config file: ${customConfigPath}`);
9922
9828
  }
9923
9829
  for (let file of configFileNames){
9924
9830
  let configFile = join(root, file);
@@ -9926,55 +9832,74 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileName
9926
9832
  }
9927
9833
  return null;
9928
9834
  })(cwd, path, configFileNames);
9929
- if (!configFilePath) return src_logger.debug('no config file found.'), {
9835
+ if (!configPath) return {
9930
9836
  content: {},
9931
- filePath: configFilePath,
9837
+ filePath: configPath,
9932
9838
  dependencies: []
9933
9839
  };
9934
- let applyMetaInfo = (config)=>(config._privateMeta = {
9935
- configFilePath
9936
- }, config);
9937
- if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || /\.(?:js|mjs|cjs)$/.test(configFilePath)) {
9840
+ if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || JS_CONFIG_REGEXP.test(configPath)) {
9938
9841
  let result;
9939
9842
  try {
9940
- result = await loadConfigWithNative(configFilePath);
9843
+ result = await loadWithNative(configPath, fresh);
9941
9844
  } catch (err) {
9942
- let errorMessage = `Failed to load file with native loader: ${color.dim(configFilePath)}`;
9943
- if ('native' === loader) throw src_logger.error(errorMessage), err;
9944
- src_logger.debug(`${errorMessage}, fallback to jiti.`), src_logger.debug(err);
9845
+ if ('native' === loader) throw err;
9945
9846
  }
9946
9847
  result && (loadedConfig = {
9947
- configExport: getConfigExport(result.configModule, exportName, configFilePath),
9848
+ configExport: getConfigExport(result.configModule, exportName, configPath),
9948
9849
  dependencies: result.dependencies
9949
9850
  });
9950
9851
  }
9951
- if (!loadedConfig) try {
9952
- loadedConfig = await loadConfigWithJiti(configFilePath, exportName);
9953
- } catch (err) {
9954
- throw src_logger.error(`Failed to load file with jiti: ${color.dim(configFilePath)}`), err;
9955
- }
9852
+ loadedConfig || (loadedConfig = await loadWithJiti(configPath, exportName, fresh));
9956
9853
  let { configExport, dependencies } = loadedConfig;
9957
9854
  if ('function' == typeof configExport) {
9958
- let nodeEnv = process.env.NODE_ENV || '', configParams = {
9959
- env: nodeEnv,
9960
- command: command ?? process.argv[2],
9961
- envMode: envMode || nodeEnv,
9962
- meta
9963
- }, result = await configExport(configParams);
9855
+ let result = await configExport(...configParams);
9964
9856
  if (void 0 === result) throw Error('The config function must return a config object.');
9965
9857
  return {
9966
- content: applyMetaInfo(result),
9967
- filePath: configFilePath,
9858
+ content: result,
9859
+ filePath: configPath,
9968
9860
  dependencies
9969
9861
  };
9970
9862
  }
9971
- if (!isObject(configExport)) throw Error(`The config must be an object or a function that returns an object, get ${color.yellow(String(configExport))}`);
9972
- return src_logger.debug('configuration loaded from:', configFilePath), {
9973
- content: applyMetaInfo(configExport),
9974
- filePath: configFilePath,
9863
+ return {
9864
+ content: configExport,
9865
+ filePath: configPath,
9975
9866
  dependencies
9976
9867
  };
9977
9868
  }
9869
+ function defineConfig(config) {
9870
+ return config;
9871
+ }
9872
+ let DEFAULT_CONFIG_FILE_NAMES = [
9873
+ 'rsbuild.config.ts',
9874
+ 'rsbuild.config.js',
9875
+ 'rsbuild.config.mts',
9876
+ 'rsbuild.config.mjs',
9877
+ 'rsbuild.config.cts',
9878
+ 'rsbuild.config.cjs'
9879
+ ];
9880
+ async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileNames = DEFAULT_CONFIG_FILE_NAMES, envMode, meta, loader = 'auto', command, exportName = 'default' } = {}) {
9881
+ let nodeEnv = process.env.NODE_ENV || '', configParams = {
9882
+ env: nodeEnv,
9883
+ command: command ?? process.argv[2],
9884
+ envMode: envMode || nodeEnv,
9885
+ meta
9886
+ }, result = await dist_loadConfig({
9887
+ cwd,
9888
+ path,
9889
+ configFileNames,
9890
+ loader,
9891
+ exportName,
9892
+ configParams: [
9893
+ configParams
9894
+ ],
9895
+ fresh: !0
9896
+ });
9897
+ if (!result.filePath) return src_logger.debug('no config file found.'), result;
9898
+ if (!isObject(result.content)) throw Error(`The config must be an object or a function that returns an object, get ${color.yellow(String(result.content))}`);
9899
+ return result.content._privateMeta = {
9900
+ configFilePath: result.filePath
9901
+ }, src_logger.debug('configuration loaded from:', result.filePath), result;
9902
+ }
9978
9903
  let cliState = {
9979
9904
  options: {}
9980
9905
  }, initCliAction = (command, options)=>{
@@ -10107,7 +10032,7 @@ let applyServerOptions = (command)=>{
10107
10032
  };
10108
10033
  function setupCommands(argv) {
10109
10034
  let cli = ((name = "")=>new CAC(name))('rsbuild');
10110
- cli.version("2.1.4"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
10035
+ cli.version("2.1.6"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
10111
10036
  default: 'auto'
10112
10037
  }).option('--dist-path <dir>', 'Set the root directory of output files').option('--source-map', 'Enable source map').option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
10113
10038
  type: [
@@ -10171,7 +10096,7 @@ function setupCommands(argv) {
10171
10096
  }
10172
10097
  function showGreeting() {
10173
10098
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
10174
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.4\n`);
10099
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.6\n`);
10175
10100
  }
10176
10101
  function setupLogLevel(argv) {
10177
10102
  if (argv.length <= 3) return;
@@ -10193,5 +10118,5 @@ function runCLI({ argv = process.argv } = {}) {
10193
10118
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
10194
10119
  }
10195
10120
  }
10196
- let src_version = "2.1.4";
10121
+ let src_version = "2.1.6";
10197
10122
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, mrmime_lookup, runCLI, src_logger as logger, src_version as version };