@rsbuild/core 1.2.17 → 1.2.19

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.
@@ -1,19 +1,19 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 306: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 7302: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const loader = __nccwpck_require__(9232);
5
+ const loader = __nccwpck_require__(2540);
6
6
  module.exports = loader.default;
7
7
  module.exports.defaultGetLocalIdent =
8
- __nccwpck_require__(7193).defaultGetLocalIdent;
8
+ __nccwpck_require__(4485).defaultGetLocalIdent;
9
9
  },
10
- 9232: (__unused_webpack_module, exports, __nccwpck_require__) => {
10
+ 2540: (__unused_webpack_module, exports, __nccwpck_require__) => {
11
11
  "use strict";
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports["default"] = loader;
14
14
  var _postcss = _interopRequireDefault(__nccwpck_require__(9409));
15
- var _plugins = __nccwpck_require__(3695);
16
- var _utils = __nccwpck_require__(7193);
15
+ var _plugins = __nccwpck_require__(35);
16
+ var _utils = __nccwpck_require__(4485);
17
17
  function _interopRequireDefault(obj) {
18
18
  return obj && obj.__esModule ? obj : { default: obj };
19
19
  }
@@ -236,7 +236,7 @@
236
236
  callback(null, `${importCode}${moduleCode}${exportCode}`);
237
237
  }
238
238
  },
239
- 3695: (__unused_webpack_module, exports, __nccwpck_require__) => {
239
+ 35: (__unused_webpack_module, exports, __nccwpck_require__) => {
240
240
  "use strict";
241
241
  Object.defineProperty(exports, "__esModule", { value: true });
242
242
  Object.defineProperty(exports, "icssParser", {
@@ -258,22 +258,20 @@
258
258
  },
259
259
  });
260
260
  var _postcssImportParser = _interopRequireDefault(
261
- __nccwpck_require__(7068),
261
+ __nccwpck_require__(7608),
262
262
  );
263
- var _postcssIcssParser = _interopRequireDefault(
264
- __nccwpck_require__(7113),
265
- );
266
- var _postcssUrlParser = _interopRequireDefault(__nccwpck_require__(4400));
263
+ var _postcssIcssParser = _interopRequireDefault(__nccwpck_require__(301));
264
+ var _postcssUrlParser = _interopRequireDefault(__nccwpck_require__(2700));
267
265
  function _interopRequireDefault(obj) {
268
266
  return obj && obj.__esModule ? obj : { default: obj };
269
267
  }
270
268
  },
271
- 7113: (__unused_webpack_module, exports, __nccwpck_require__) => {
269
+ 301: (__unused_webpack_module, exports, __nccwpck_require__) => {
272
270
  "use strict";
273
271
  Object.defineProperty(exports, "__esModule", { value: true });
274
272
  exports["default"] = void 0;
275
273
  var _icssUtils = __nccwpck_require__(4531);
276
- var _utils = __nccwpck_require__(7193);
274
+ var _utils = __nccwpck_require__(4485);
277
275
  const plugin = (options = {}) => ({
278
276
  postcssPlugin: "postcss-icss-parser",
279
277
  async OnceExit(root) {
@@ -372,14 +370,14 @@
372
370
  plugin.postcss = true;
373
371
  var _default = (exports["default"] = plugin);
374
372
  },
375
- 7068: (__unused_webpack_module, exports, __nccwpck_require__) => {
373
+ 7608: (__unused_webpack_module, exports, __nccwpck_require__) => {
376
374
  "use strict";
377
375
  Object.defineProperty(exports, "__esModule", { value: true });
378
376
  exports["default"] = void 0;
379
377
  var _postcssValueParser = _interopRequireDefault(
380
378
  __nccwpck_require__(2948),
381
379
  );
382
- var _utils = __nccwpck_require__(7193);
380
+ var _utils = __nccwpck_require__(4485);
383
381
  function _interopRequireDefault(obj) {
384
382
  return obj && obj.__esModule ? obj : { default: obj };
385
383
  }
@@ -684,14 +682,14 @@
684
682
  plugin.postcss = true;
685
683
  var _default = (exports["default"] = plugin);
686
684
  },
687
- 4400: (__unused_webpack_module, exports, __nccwpck_require__) => {
685
+ 2700: (__unused_webpack_module, exports, __nccwpck_require__) => {
688
686
  "use strict";
689
687
  Object.defineProperty(exports, "__esModule", { value: true });
690
688
  exports["default"] = void 0;
691
689
  var _postcssValueParser = _interopRequireDefault(
692
690
  __nccwpck_require__(2948),
693
691
  );
694
- var _utils = __nccwpck_require__(7193);
692
+ var _utils = __nccwpck_require__(4485);
695
693
  function _interopRequireDefault(obj) {
696
694
  return obj && obj.__esModule ? obj : { default: obj };
697
695
  }
@@ -1034,7 +1032,7 @@
1034
1032
  plugin.postcss = true;
1035
1033
  var _default = (exports["default"] = plugin);
1036
1034
  },
1037
- 7193: (__unused_webpack_module, exports, __nccwpck_require__) => {
1035
+ 4485: (__unused_webpack_module, exports, __nccwpck_require__) => {
1038
1036
  "use strict";
1039
1037
  Object.defineProperty(exports, "__esModule", { value: true });
1040
1038
  exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
@@ -8098,6 +8096,6 @@
8098
8096
  }
8099
8097
  if (typeof __nccwpck_require__ !== "undefined")
8100
8098
  __nccwpck_require__.ab = __dirname + "/";
8101
- var __webpack_exports__ = __nccwpck_require__(306);
8099
+ var __webpack_exports__ = __nccwpck_require__(7302);
8102
8100
  module.exports = __webpack_exports__;
8103
8101
  })();
@@ -1,8 +1,8 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 744: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 555: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const { HtmlWebpackChildCompiler } = __nccwpck_require__(525);
5
+ const { HtmlWebpackChildCompiler } = __nccwpck_require__(360);
6
6
  const compilerMap = new WeakMap();
7
7
  class CachedChildCompilation {
8
8
  constructor(compiler) {
@@ -304,7 +304,7 @@
304
304
  }
305
305
  module.exports = { CachedChildCompilation };
306
306
  },
307
- 525: (module) => {
307
+ 360: (module) => {
308
308
  "use strict";
309
309
  class HtmlWebpackChildCompiler {
310
310
  constructor(templates) {
@@ -473,7 +473,7 @@
473
473
  }
474
474
  module.exports = { HtmlWebpackChildCompiler };
475
475
  },
476
- 835: (module) => {
476
+ 16: (module) => {
477
477
  "use strict";
478
478
  module.exports = {};
479
479
  module.exports.none = (chunks) => chunks;
@@ -492,7 +492,7 @@
492
492
  };
493
493
  module.exports.auto = module.exports.none;
494
494
  },
495
- 518: (module) => {
495
+ 223: (module) => {
496
496
  "use strict";
497
497
  module.exports = function (err) {
498
498
  return {
@@ -513,7 +513,7 @@
513
513
  };
514
514
  };
515
515
  },
516
- 621: (module, __unused_webpack_exports, __nccwpck_require__) => {
516
+ 910: (module, __unused_webpack_exports, __nccwpck_require__) => {
517
517
  "use strict";
518
518
  const { AsyncSeriesWaterfallHook } = __nccwpck_require__(408);
519
519
  const htmlWebpackPluginHooksMap = new WeakMap();
@@ -539,7 +539,7 @@
539
539
  }
540
540
  module.exports = { getHtmlRspackPluginHooks };
541
541
  },
542
- 716: (module) => {
542
+ 315: (module) => {
543
543
  const voidTags = [
544
544
  "area",
545
545
  "base",
@@ -607,19 +607,19 @@
607
607
  htmlTagObjectToString,
608
608
  };
609
609
  },
610
- 185: (module, __unused_webpack_exports, __nccwpck_require__) => {
610
+ 850: (module, __unused_webpack_exports, __nccwpck_require__) => {
611
611
  "use strict";
612
612
  const promisify = __nccwpck_require__(23).promisify;
613
613
  const vm = __nccwpck_require__(154);
614
614
  const fs = __nccwpck_require__(896);
615
615
  const path = __nccwpck_require__(928);
616
- const { CachedChildCompilation } = __nccwpck_require__(744);
616
+ const { CachedChildCompilation } = __nccwpck_require__(555);
617
617
  const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } =
618
- __nccwpck_require__(716);
619
- const prettyError = __nccwpck_require__(518);
620
- const chunkSorter = __nccwpck_require__(835);
618
+ __nccwpck_require__(315);
619
+ const prettyError = __nccwpck_require__(223);
620
+ const chunkSorter = __nccwpck_require__(16);
621
621
  const getHtmlRspackPluginHooks =
622
- __nccwpck_require__(621).getHtmlRspackPluginHooks;
622
+ __nccwpck_require__(910).getHtmlRspackPluginHooks;
623
623
  class HtmlRspackPlugin {
624
624
  constructor(userOptions = {}) {
625
625
  this.version = HtmlRspackPlugin.version;
@@ -1578,6 +1578,6 @@
1578
1578
  }
1579
1579
  if (typeof __nccwpck_require__ !== "undefined")
1580
1580
  __nccwpck_require__.ab = __dirname + "/";
1581
- var __webpack_exports__ = __nccwpck_require__(185);
1581
+ var __webpack_exports__ = __nccwpck_require__(850);
1582
1582
  module.exports = __webpack_exports__;
1583
1583
  })();
@@ -1,15 +1,15 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 737: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- module.exports = __nccwpck_require__(123)["default"];
4
+ 290: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ module.exports = __nccwpck_require__(896)["default"];
6
6
  },
7
- 123: (__unused_webpack_module, exports, __nccwpck_require__) => {
7
+ 896: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
8
  var __webpack_unused_export__;
9
9
  __webpack_unused_export__ = { value: true };
10
10
  exports["default"] = loader;
11
11
  var _path = _interopRequireDefault(__nccwpck_require__(928));
12
- var _utils = __nccwpck_require__(358);
12
+ var _utils = __nccwpck_require__(681);
13
13
  function _interopRequireDefault(obj) {
14
14
  return obj && obj.__esModule ? obj : { default: obj };
15
15
  }
@@ -179,7 +179,7 @@
179
179
  callback(null, result.css, map, { ast });
180
180
  }
181
181
  },
182
- 358: (module, exports, __nccwpck_require__) => {
182
+ 681: (module, exports, __nccwpck_require__) => {
183
183
  module = __nccwpck_require__.nmd(module);
184
184
  Object.defineProperty(exports, "__esModule", { value: true });
185
185
  exports.exec = exec;
@@ -716,6 +716,6 @@
716
716
  })();
717
717
  if (typeof __nccwpck_require__ !== "undefined")
718
718
  __nccwpck_require__.ab = __dirname + "/";
719
- var __webpack_exports__ = __nccwpck_require__(737);
719
+ var __webpack_exports__ = __nccwpck_require__(290);
720
720
  module.exports = __webpack_exports__;
721
721
  })();
@@ -1,7 +1,7 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 705: (__unused_webpack_module, exports, __nccwpck_require__) => {
4
+ 664: (__unused_webpack_module, exports, __nccwpck_require__) => {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.transformFiles =
7
7
  exports.reduceChunk =
@@ -120,7 +120,7 @@
120
120
  .map(standardizeFilePaths);
121
121
  exports.transformFiles = transformFiles;
122
122
  },
123
- 964: (__unused_webpack_module, exports, __nccwpck_require__) => {
123
+ 289: (__unused_webpack_module, exports, __nccwpck_require__) => {
124
124
  Object.defineProperty(exports, "__esModule", { value: true });
125
125
  exports.normalModuleLoaderHook =
126
126
  exports.getCompilerHooks =
@@ -130,7 +130,7 @@
130
130
  const fs_1 = __nccwpck_require__(896);
131
131
  const path_1 = __nccwpck_require__(928);
132
132
  const lite_tapable_1 = __nccwpck_require__(408);
133
- const helpers_1 = __nccwpck_require__(705);
133
+ const helpers_1 = __nccwpck_require__(664);
134
134
  const compilerHookMap = new WeakMap();
135
135
  const getCompilerHooks = (compiler) => {
136
136
  let hooks = compilerHookMap.get(compiler);
@@ -312,7 +312,7 @@
312
312
  exports.getCompilerHooks =
313
313
  void 0;
314
314
  const path_1 = __nccwpck_require__(928);
315
- const hooks_1 = __nccwpck_require__(964);
315
+ const hooks_1 = __nccwpck_require__(289);
316
316
  Object.defineProperty(exports, "getCompilerHooks", {
317
317
  enumerable: true,
318
318
  get: function () {
package/dist/index.cjs CHANGED
@@ -1297,7 +1297,7 @@ var __webpack_exports__ = {};
1297
1297
  return statsData.warningsCount && (null === (_statsData_warnings = statsData.warnings) || void 0 === _statsData_warnings ? void 0 : _statsData_warnings.length) === 0 ? null === (_statsData_children = statsData.children) || void 0 === _statsData_children ? void 0 : _statsData_children.reduce((warnings, curr)=>warnings.concat(curr.warnings || []), []) : statsData.warnings;
1298
1298
  };
1299
1299
  function getStatsOptions(compiler) {
1300
- if (isMultiCompiler(compiler)) return {
1300
+ if (helpers_isMultiCompiler(compiler)) return {
1301
1301
  children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
1302
1302
  };
1303
1303
  let { stats } = compiler.options;
@@ -1396,8 +1396,8 @@ var __webpack_exports__ = {};
1396
1396
  }
1397
1397
  }
1398
1398
  let applyToCompiler = (compiler, apply)=>{
1399
- isMultiCompiler(compiler) ? compiler.compilers.forEach(apply) : apply(compiler, 0);
1400
- }, upperFirst = (str)=>str ? str.charAt(0).toUpperCase() + str.slice(1) : '', isURL = (str)=>str.startsWith('http') || str.startsWith('//:'), createVirtualModule = (content)=>`data:text/javascript,${content}`, isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
1399
+ helpers_isMultiCompiler(compiler) ? compiler.compilers.forEach(apply) : apply(compiler, 0);
1400
+ }, upperFirst = (str)=>str ? str.charAt(0).toUpperCase() + str.slice(1) : '', isURL = (str)=>str.startsWith('http') || str.startsWith('//:'), createVirtualModule = (content)=>`data:text/javascript,${content}`, helpers_isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
1401
1401
  function pick(obj, keys) {
1402
1402
  return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
1403
1403
  }
@@ -1556,43 +1556,39 @@ var __webpack_exports__ = {};
1556
1556
  merged[key] = merge(x[key], y[key], childPath);
1557
1557
  }
1558
1558
  return merged;
1559
- }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().join(cwd, envDir) : cwd;
1559
+ }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().join(cwd, envDir) : cwd, init_loadConfig = async (root)=>{
1560
+ var _config_server;
1561
+ let { content: config, filePath } = await config_loadConfig({
1562
+ cwd: root,
1563
+ path: commonOpts.config,
1564
+ envMode: commonOpts.envMode,
1565
+ loader: commonOpts.configLoader
1566
+ });
1567
+ return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server.open = commonOpts.open), commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
1568
+ ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
1569
+ {
1570
+ paths: filePath,
1571
+ type: 'reload-server'
1572
+ }
1573
+ ]), config;
1574
+ };
1560
1575
  async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
1561
1576
  cliOptions && (commonOpts = cliOptions);
1562
1577
  try {
1563
- var _config_server, _config_dev, _config_performance;
1564
- let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
1565
- cwd: getEnvDir(root, commonOpts.envDir),
1566
- mode: commonOpts.envMode
1567
- }), { content: config, filePath: configFilePath } = await config_loadConfig({
1578
+ let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, rsbuild = await createRsbuild({
1568
1579
  cwd: root,
1569
- path: commonOpts.config,
1570
- envMode: commonOpts.envMode,
1571
- loader: commonOpts.configLoader
1572
- });
1573
- if (config.source ||= {}, config.source.define = {
1574
- ...envs.publicVars,
1575
- ...config.source.define
1576
- }, commonOpts.base && (config.server ||= {}, config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0), (null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache) && envs.filePaths.length > 0) {
1577
- let { buildCache } = config.performance;
1578
- !0 === buildCache ? config.performance.buildCache = {
1579
- buildDependencies: envs.filePaths
1580
- } : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
1581
- }
1582
- let rsbuild = await createRsbuild({
1583
- cwd: root,
1584
- rsbuildConfig: config,
1585
- environment: commonOpts.environment
1580
+ rsbuildConfig: ()=>init_loadConfig(root),
1581
+ environment: commonOpts.environment,
1582
+ loadEnv: {
1583
+ cwd: getEnvDir(root, commonOpts.envDir),
1584
+ mode: commonOpts.envMode
1585
+ }
1586
1586
  });
1587
1587
  return rsbuild.onBeforeCreateCompiler(()=>{
1588
1588
  let command = process.argv[2];
1589
1589
  if ('dev' === command || isBuildWatch) {
1590
1590
  var _config_dev;
1591
- let files = [
1592
- ...envs.filePaths
1593
- ];
1594
- configFilePath && files.push(configFilePath);
1595
- let config = rsbuild.getNormalizedConfig();
1591
+ let files = [], config = rsbuild.getNormalizedConfig();
1596
1592
  if (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
1597
1593
  if ('reload-server' !== watchFilesConfig.type) continue;
1598
1594
  let paths = castArray(watchFilesConfig.paths);
@@ -1600,7 +1596,7 @@ var __webpack_exports__ = {};
1600
1596
  }
1601
1597
  watchFilesForRestart(files, root, isBuildWatch);
1602
1598
  }
1603
- }), rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup), rsbuild;
1599
+ }), rsbuild;
1604
1600
  } catch (err) {
1605
1601
  if (isRestart) rslog_index_js_namespaceObject.logger.error(err);
1606
1602
  else throw err;
@@ -2143,7 +2139,7 @@ var __webpack_exports__ = {};
2143
2139
  }
2144
2140
  let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isWatch })=>{
2145
2141
  let name = 'rsbuild:beforeCompile';
2146
- if (isMultiCompiler(compiler)) {
2142
+ if (helpers_isMultiCompiler(compiler)) {
2147
2143
  let waitBeforeCompileDone;
2148
2144
  let { compilers } = compiler, doneCompilers = 0;
2149
2145
  for(let index = 0; index < compilers.length; index++){
@@ -2158,7 +2154,7 @@ var __webpack_exports__ = {};
2158
2154
  await (null == beforeCompile ? void 0 : beforeCompile()), await beforeEnvironmentCompiler(0);
2159
2155
  });
2160
2156
  }, onCompileDone = ({ compiler, onDone, onEnvironmentDone, MultiStatsCtor })=>{
2161
- if (isMultiCompiler(compiler)) {
2157
+ if (helpers_isMultiCompiler(compiler)) {
2162
2158
  let { compilers } = compiler, compilerStats = [], doneCompilers = 0;
2163
2159
  for(let index = 0; index < compilers.length; index++){
2164
2160
  let compiler = compilers[index], compilerIndex = index, compilerDone = !1;
@@ -2379,14 +2375,14 @@ var __webpack_exports__ = {};
2379
2375
  });
2380
2376
  }
2381
2377
  }
2382
- async function createContext(options, userConfig, bundlerType) {
2378
+ async function createContext(options, userConfig) {
2383
2379
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
2384
2380
  return {
2385
- version: "1.2.17",
2381
+ version: "1.2.19",
2386
2382
  rootPath,
2387
2383
  distPath: '',
2388
2384
  cachePath,
2389
- bundlerType,
2385
+ bundlerType: userConfig.provider ? 'webpack' : 'rspack',
2390
2386
  environments: {},
2391
2387
  hooks: {
2392
2388
  onExit: createAsyncHook(),
@@ -4901,22 +4897,25 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4901
4897
  };
4902
4898
  }
4903
4899
  var dist = __webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/index.js");
4904
- async function modifyRspackConfig(context, rspackConfig, utils) {
4900
+ async function modifyRspackConfig(context, rspackConfig, chainUtils) {
4905
4901
  var _utils_environment_config_tools;
4906
4902
  rslog_index_js_namespaceObject.logger.debug('modify Rspack config');
4907
- let [modifiedConfig] = await context.hooks.modifyRspackConfig.callChain({
4903
+ let currentConfig = rspackConfig, proxiedConfig = new Proxy({}, {
4904
+ get: (_, prop)=>currentConfig[prop],
4905
+ set: (_, prop, value)=>(currentConfig[prop] = value, !0)
4906
+ }), utils = await getConfigUtils(proxiedConfig, chainUtils);
4907
+ return [currentConfig] = await context.hooks.modifyRspackConfig.callChain({
4908
4908
  environment: utils.environment.name,
4909
4909
  args: [
4910
4910
  rspackConfig,
4911
4911
  utils
4912
4912
  ]
4913
- });
4914
- return (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.rspack) && (modifiedConfig = await reduceConfigsAsyncWithContext({
4915
- initial: modifiedConfig,
4913
+ }), (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.rspack) && (currentConfig = await reduceConfigsAsyncWithContext({
4914
+ initial: currentConfig,
4916
4915
  config: utils.environment.config.tools.rspack,
4917
4916
  ctx: utils,
4918
- mergeFn: utils.mergeConfig
4919
- })), rslog_index_js_namespaceObject.logger.debug('modify Rspack config done'), modifiedConfig;
4917
+ mergeFn: (...args)=>currentConfig = utils.mergeConfig.call(utils, args)
4918
+ })), rslog_index_js_namespaceObject.logger.debug('modify Rspack config done'), currentConfig;
4920
4919
  }
4921
4920
  async function getConfigUtils(config, chainUtils) {
4922
4921
  return {
@@ -4977,7 +4976,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4977
4976
  }
4978
4977
  }
4979
4978
  config.devServer && rslog_index_js_namespaceObject.logger.warn(`[rsbuild:config] Find invalid Rspack config: "${index_js_default().yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`);
4980
- }(rspackConfig = await modifyRspackConfig(context, rspackConfig, await getConfigUtils(rspackConfig, chainUtils))), rspackConfig;
4979
+ }(rspackConfig = await modifyRspackConfig(context, rspackConfig, chainUtils)), rspackConfig;
4981
4980
  }
4982
4981
  async function modifyRsbuildConfig(context) {
4983
4982
  rslog_index_js_namespaceObject.logger.debug('modify Rsbuild config');
@@ -5359,24 +5358,24 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5359
5358
  getStats(name) {
5360
5359
  let curStats = this.stats[name];
5361
5360
  if (!curStats) return null;
5362
- let statsOptions = getStatsOptions(curStats.compilation.compiler);
5363
- return {
5364
- statsJson: curStats.toJson({
5365
- all: !1,
5366
- hash: !0,
5367
- assets: !0,
5368
- warnings: !0,
5369
- warningsCount: !0,
5370
- errors: !0,
5371
- errorsCount: !0,
5372
- errorDetails: !1,
5373
- entrypoints: !0,
5374
- children: !0,
5375
- moduleTrace: !0,
5376
- ...statsOptions
5377
- }),
5361
+ let statsOptions = getStatsOptions(curStats.compilation.compiler), statsJson = curStats.toJson({
5362
+ all: !1,
5363
+ hash: !0,
5364
+ assets: !0,
5365
+ warnings: !0,
5366
+ warningsCount: !0,
5367
+ errors: !0,
5368
+ errorsCount: !0,
5369
+ errorDetails: !1,
5370
+ entrypoints: !0,
5371
+ children: !0,
5372
+ moduleTrace: !0,
5373
+ ...statsOptions
5374
+ });
5375
+ return statsJson ? {
5376
+ statsJson,
5378
5377
  root: curStats.compilation.compiler.options.context
5379
- };
5378
+ } : null;
5380
5379
  }
5381
5380
  sendStats({ force = !1, compilationId }) {
5382
5381
  let result = this.getStats(compilationId);
@@ -5796,7 +5795,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5796
5795
  let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
5797
5796
  ${file.content}
5798
5797
  })`;
5799
- return this.preExecute(code, file), (this._options.runInNewContext ? external_node_vm_default().runInNewContext(code, this.globalContext, file.path) : external_node_vm_default().runInThisContext(code, file.path)).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
5798
+ this.preExecute(code, file);
5799
+ let dynamicImport = Function('specifier', 'return import(specifier)');
5800
+ return external_node_vm_default().runInThisContext(code, {
5801
+ filename: file.path,
5802
+ importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
5803
+ }).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
5800
5804
  };
5801
5805
  }
5802
5806
  }
@@ -6242,7 +6246,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6242
6246
  }) : Promise.resolve(), startCompile = async ()=>{
6243
6247
  let compiler = customCompiler || await createCompiler();
6244
6248
  if (!compiler) throw Error('[rsbuild:server] Failed to get compiler instance.');
6245
- let publicPaths = isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
6249
+ let publicPaths = helpers_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
6246
6250
  getPublicPathFromCompiler(compiler)
6247
6251
  ], compilerDevMiddleware = new CompilerDevMiddleware({
6248
6252
  dev: devConfig,
@@ -6254,7 +6258,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6254
6258
  compiler,
6255
6259
  environments: options.context.environments
6256
6260
  });
6257
- return await compilerDevMiddleware.init(), outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || external_node_fs_default(), {
6261
+ return await compilerDevMiddleware.init(), outputFileSystem = (helpers_isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || external_node_fs_default(), {
6258
6262
  middleware: compilerDevMiddleware.middleware,
6259
6263
  sockWrite: (...args)=>compilerDevMiddleware.sockWrite(...args),
6260
6264
  onUpgrade: (...args)=>compilerDevMiddleware.upgrade(...args),
@@ -6403,7 +6407,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6403
6407
  bundlerConfigs: rspackConfigs,
6404
6408
  environments: context.environments
6405
6409
  }), !await isSatisfyRspackVersion(core_namespaceObject.rspack.rspackVersion)) throw Error(`[rsbuild] The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${index_js_default().green(rspackMinVersion)}`);
6406
- let compiler = 1 === rspackConfigs.length ? (0, core_namespaceObject.rspack)(rspackConfigs[0]) : (0, core_namespaceObject.rspack)(rspackConfigs), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
6410
+ let isMultiCompiler = rspackConfigs.length > 1, compiler = isMultiCompiler ? (0, core_namespaceObject.rspack)(rspackConfigs) : (0, core_namespaceObject.rspack)(rspackConfigs[0]), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
6407
6411
  isVersionLogged || (rslog_index_js_namespaceObject.logger.debug(`use Rspack v${core_namespaceObject.rspack.rspackVersion}`), isVersionLogged = !0);
6408
6412
  };
6409
6413
  compiler.hooks.watchRun.tap('rsbuild:compiling', (compiler)=>{
@@ -6432,13 +6436,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6432
6436
  ...statsOptions
6433
6437
  }), printTime = (c, index)=>{
6434
6438
  if (c.time) {
6435
- let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ? index_js_default().gray(` (${name})`) : '';
6439
+ let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name && isMultiCompiler ? index_js_default().gray(` (${name})`) : '';
6436
6440
  rslog_index_js_namespaceObject.logger.ready(`built in ${time}${suffix}`);
6437
6441
  }
6438
6442
  }, hasErrors = stats.hasErrors();
6439
6443
  if (!hasErrors) {
6440
6444
  var _statsJson_children;
6441
- rspackConfigs.length > 1 && (null === (_statsJson_children = statsJson.children) || void 0 === _statsJson_children ? void 0 : _statsJson_children.length) ? statsJson.children.forEach((c, index)=>{
6445
+ isMultiCompiler && (null === (_statsJson_children = statsJson.children) || void 0 === _statsJson_children ? void 0 : _statsJson_children.length) ? statsJson.children.forEach((c, index)=>{
6442
6446
  printTime(c, index);
6443
6447
  }) : printTime(statsJson, 0);
6444
6448
  }
@@ -6460,7 +6464,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6460
6464
  rspackConfigs
6461
6465
  };
6462
6466
  }
6463
- let build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
6467
+ let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
6464
6468
  let compiler, bundlerConfigs;
6465
6469
  let { context } = initOptions;
6466
6470
  if (customCompiler) compiler = customCompiler;
@@ -6485,7 +6489,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6485
6489
  };
6486
6490
  let { stats } = await new Promise((resolve, reject)=>{
6487
6491
  compiler.run((err, stats)=>{
6488
- err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error('Rspack build failed!')) : compiler.close((closeErr)=>{
6492
+ err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error(RSPACK_BUILD_ERROR)) : compiler.close((closeErr)=>{
6489
6493
  closeErr && rslog_index_js_namespaceObject.logger.error(closeErr), resolve({
6490
6494
  stats
6491
6495
  });
@@ -6781,10 +6785,34 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6781
6785
  }
6782
6786
  async function createRsbuild(options = {}) {
6783
6787
  let plugins;
6784
- let { rsbuildConfig = {} } = options, rsbuildOptions = {
6788
+ let envs = options.loadEnv ? loadEnv({
6789
+ cwd: options.cwd,
6790
+ ...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
6791
+ }) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
6792
+ !function(config, envs) {
6793
+ var _config_performance;
6794
+ if (null !== envs) {
6795
+ if (config.source ||= {}, config.source.define = {
6796
+ ...envs.publicVars,
6797
+ ...config.source.define
6798
+ }, 0 !== envs.filePaths.length && (config.dev ||= {}, config.dev.watchFiles = [
6799
+ ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
6800
+ {
6801
+ paths: envs.filePaths,
6802
+ type: 'reload-server'
6803
+ }
6804
+ ], null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache)) {
6805
+ let { buildCache } = config.performance;
6806
+ !0 === buildCache ? config.performance.buildCache = {
6807
+ buildDependencies: envs.filePaths
6808
+ } : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
6809
+ }
6810
+ }
6811
+ }(config, envs);
6812
+ let resolvedOptions = {
6785
6813
  cwd: process.cwd(),
6786
- rsbuildConfig,
6787
- ...options
6814
+ ...options,
6815
+ rsbuildConfig: config
6788
6816
  }, pluginManager = (plugins = [], {
6789
6817
  getPlugins: (options = {
6790
6818
  environment: RSBUILD_ALL_ENVIRONMENT_SYMBOL
@@ -6836,7 +6864,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6836
6864
  isPluginExists: (pluginName, options = {
6837
6865
  environment: RSBUILD_ALL_ENVIRONMENT_SYMBOL
6838
6866
  })=>!!plugins.find((plugin)=>plugin.instance.name === pluginName && isPluginMatchEnvironment(plugin.environment, options.environment))
6839
- }), context = await createContext(rsbuildOptions, rsbuildOptions.rsbuildConfig, rsbuildConfig.provider ? 'webpack' : 'rspack'), getPluginAPI = function({ context, pluginManager }) {
6867
+ }), context = await createContext(resolvedOptions, config), getPluginAPI = function({ context, pluginManager }) {
6840
6868
  let { hooks } = context, publicContext = function(context) {
6841
6869
  let exposedKeys = [
6842
6870
  'version',
@@ -7017,10 +7045,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7017
7045
  context.getPluginAPI = getPluginAPI;
7018
7046
  let globalPluginAPI = getPluginAPI();
7019
7047
  rslog_index_js_namespaceObject.logger.debug('add default plugins'), await applyDefaultPlugins(pluginManager, context), rslog_index_js_namespaceObject.logger.debug('add default plugins done');
7020
- let provider = rsbuildConfig.provider || rspackProvider, providerInstance = await provider({
7048
+ let provider = config.provider || rspackProvider, providerInstance = await provider({
7021
7049
  context,
7022
7050
  pluginManager,
7023
- rsbuildOptions,
7051
+ rsbuildOptions: resolvedOptions,
7024
7052
  helpers: provider_helpers_namespaceObject
7025
7053
  }), rsbuild = {
7026
7054
  build: async (...args)=>{
@@ -7078,19 +7106,21 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7078
7106
  'initConfigs',
7079
7107
  'inspectConfig'
7080
7108
  ])
7081
- }, getFlattenedPlugins = async (pluginOptions)=>{
7109
+ };
7110
+ envs && (rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup));
7111
+ let getFlattenedPlugins = async (pluginOptions)=>{
7082
7112
  let plugins = pluginOptions;
7083
7113
  do plugins = (await Promise.all(plugins)).flat(Number.POSITIVE_INFINITY);
7084
7114
  while (plugins.some((v)=>(0, types_namespaceObject.isPromise)(v)));
7085
7115
  return plugins;
7086
7116
  };
7087
- if (rsbuildConfig.plugins) {
7088
- let plugins = await getFlattenedPlugins(rsbuildConfig.plugins);
7117
+ if (config.plugins) {
7118
+ let plugins = await getFlattenedPlugins(config.plugins);
7089
7119
  rsbuild.addPlugins(plugins);
7090
7120
  }
7091
- return rsbuildConfig.environments && await Promise.all(Object.entries(rsbuildConfig.environments).map(async ([name, config])=>{
7092
- if (!config.plugins || context.specifiedEnvironments && !context.specifiedEnvironments.includes(name)) return;
7093
- let plugins = await getFlattenedPlugins(config.plugins);
7121
+ return config.environments && await Promise.all(Object.entries(config.environments).map(async ([name, environmentConfig])=>{
7122
+ if (!environmentConfig.plugins || context.specifiedEnvironments && !context.specifiedEnvironments.includes(name)) return;
7123
+ let plugins = await getFlattenedPlugins(environmentConfig.plugins);
7094
7124
  rsbuild.addPlugins(plugins, {
7095
7125
  environment: name
7096
7126
  });
@@ -7424,13 +7454,13 @@ ${section.body}` : section.body).join("\n\n"));
7424
7454
  }
7425
7455
  }(), process.title = 'rsbuild-node';
7426
7456
  let { npm_execpath } = process.env;
7427
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.17\n`);
7457
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.19\n`);
7428
7458
  }();
7429
7459
  try {
7430
7460
  !function() {
7431
7461
  let cli = cac_dist('rsbuild');
7432
- cli.help(), cli.version("1.2.17"), applyCommonOptions(cli);
7433
- let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
7462
+ cli.help(), cli.version("1.2.19"), applyCommonOptions(cli);
7463
+ let devCommand = cli.command('', 'starting the dev server').alias('dev'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
7434
7464
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7435
7465
  try {
7436
7466
  let rsbuild = await init({
@@ -7450,7 +7480,7 @@ ${section.body}` : section.body).join("\n\n"));
7450
7480
  }));
7451
7481
  buildInstance && (options.watch ? onBeforeRestartServer(buildInstance.close) : await buildInstance.close());
7452
7482
  } catch (err) {
7453
- rslog_index_js_namespaceObject.logger.error('Failed to build.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
7483
+ err instanceof Error && err.message === RSPACK_BUILD_ERROR || rslog_index_js_namespaceObject.logger.error('Failed to build.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
7454
7484
  }
7455
7485
  }), previewCommand.action(async (options)=>{
7456
7486
  try {
@@ -7480,7 +7510,7 @@ ${section.body}` : section.body).join("\n\n"));
7480
7510
  rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
7481
7511
  }
7482
7512
  }
7483
- let src_rslib_entry_version = "1.2.17";
7513
+ let src_rslib_entry_version = "1.2.19";
7484
7514
  })();
7485
7515
  var __webpack_export_target__ = exports;
7486
7516
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
package/dist/index.js CHANGED
@@ -1203,7 +1203,7 @@ let getAllStatsErrors = (statsData)=>{
1203
1203
  return statsData.warningsCount && (null === (_statsData_warnings = statsData.warnings) || void 0 === _statsData_warnings ? void 0 : _statsData_warnings.length) === 0 ? null === (_statsData_children = statsData.children) || void 0 === _statsData_children ? void 0 : _statsData_children.reduce((warnings, curr)=>warnings.concat(curr.warnings || []), []) : statsData.warnings;
1204
1204
  };
1205
1205
  function getStatsOptions(compiler) {
1206
- if (isMultiCompiler(compiler)) return {
1206
+ if (helpers_isMultiCompiler(compiler)) return {
1207
1207
  children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
1208
1208
  };
1209
1209
  let { stats } = compiler.options;
@@ -1302,8 +1302,8 @@ function getFilename(config, type, isProd, isServer) {
1302
1302
  }
1303
1303
  }
1304
1304
  let applyToCompiler = (compiler, apply)=>{
1305
- isMultiCompiler(compiler) ? compiler.compilers.forEach(apply) : apply(compiler, 0);
1306
- }, upperFirst = (str)=>str ? str.charAt(0).toUpperCase() + str.slice(1) : '', isURL = (str)=>str.startsWith('http') || str.startsWith('//:'), createVirtualModule = (content)=>`data:text/javascript,${content}`, isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
1305
+ helpers_isMultiCompiler(compiler) ? compiler.compilers.forEach(apply) : apply(compiler, 0);
1306
+ }, upperFirst = (str)=>str ? str.charAt(0).toUpperCase() + str.slice(1) : '', isURL = (str)=>str.startsWith('http') || str.startsWith('//:'), createVirtualModule = (content)=>`data:text/javascript,${content}`, helpers_isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
1307
1307
  function pick(obj, keys) {
1308
1308
  return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
1309
1309
  }
@@ -1458,43 +1458,39 @@ let configCache = {}, OVERRIDE_PATHS = [
1458
1458
  merged[key] = merge(x[key], y[key], childPath);
1459
1459
  }
1460
1460
  return merged;
1461
- }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.isAbsolute(envDir) ? envDir : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(cwd, envDir) : cwd;
1461
+ }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.isAbsolute(envDir) ? envDir : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(cwd, envDir) : cwd, init_loadConfig = async (root)=>{
1462
+ var _config_server;
1463
+ let { content: config, filePath } = await config_loadConfig({
1464
+ cwd: root,
1465
+ path: commonOpts.config,
1466
+ envMode: commonOpts.envMode,
1467
+ loader: commonOpts.configLoader
1468
+ });
1469
+ return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server.open = commonOpts.open), commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
1470
+ ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
1471
+ {
1472
+ paths: filePath,
1473
+ type: 'reload-server'
1474
+ }
1475
+ ]), config;
1476
+ };
1462
1477
  async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
1463
1478
  cliOptions && (commonOpts = cliOptions);
1464
1479
  try {
1465
- var _config_server, _config_dev, _config_performance;
1466
- let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
1467
- cwd: getEnvDir(root, commonOpts.envDir),
1468
- mode: commonOpts.envMode
1469
- }), { content: config, filePath: configFilePath } = await config_loadConfig({
1480
+ let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, rsbuild = await createRsbuild({
1470
1481
  cwd: root,
1471
- path: commonOpts.config,
1472
- envMode: commonOpts.envMode,
1473
- loader: commonOpts.configLoader
1474
- });
1475
- if (config.source ||= {}, config.source.define = {
1476
- ...envs.publicVars,
1477
- ...config.source.define
1478
- }, commonOpts.base && (config.server ||= {}, config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0), (null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache) && envs.filePaths.length > 0) {
1479
- let { buildCache } = config.performance;
1480
- !0 === buildCache ? config.performance.buildCache = {
1481
- buildDependencies: envs.filePaths
1482
- } : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
1483
- }
1484
- let rsbuild = await createRsbuild({
1485
- cwd: root,
1486
- rsbuildConfig: config,
1487
- environment: commonOpts.environment
1482
+ rsbuildConfig: ()=>init_loadConfig(root),
1483
+ environment: commonOpts.environment,
1484
+ loadEnv: {
1485
+ cwd: getEnvDir(root, commonOpts.envDir),
1486
+ mode: commonOpts.envMode
1487
+ }
1488
1488
  });
1489
1489
  return rsbuild.onBeforeCreateCompiler(()=>{
1490
1490
  let command = process.argv[2];
1491
1491
  if ('dev' === command || isBuildWatch) {
1492
1492
  var _config_dev;
1493
- let files = [
1494
- ...envs.filePaths
1495
- ];
1496
- configFilePath && files.push(configFilePath);
1497
- let config = rsbuild.getNormalizedConfig();
1493
+ let files = [], config = rsbuild.getNormalizedConfig();
1498
1494
  if (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
1499
1495
  if ('reload-server' !== watchFilesConfig.type) continue;
1500
1496
  let paths = castArray(watchFilesConfig.paths);
@@ -1502,7 +1498,7 @@ async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
1502
1498
  }
1503
1499
  watchFilesForRestart(files, root, isBuildWatch);
1504
1500
  }
1505
- }), rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup), rsbuild;
1501
+ }), rsbuild;
1506
1502
  } catch (err) {
1507
1503
  if (isRestart) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
1508
1504
  else throw err;
@@ -2045,7 +2041,7 @@ function createAsyncHook() {
2045
2041
  }
2046
2042
  let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isWatch })=>{
2047
2043
  let name = 'rsbuild:beforeCompile';
2048
- if (isMultiCompiler(compiler)) {
2044
+ if (helpers_isMultiCompiler(compiler)) {
2049
2045
  let waitBeforeCompileDone;
2050
2046
  let { compilers } = compiler, doneCompilers = 0;
2051
2047
  for(let index = 0; index < compilers.length; index++){
@@ -2060,7 +2056,7 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
2060
2056
  await (null == beforeCompile ? void 0 : beforeCompile()), await beforeEnvironmentCompiler(0);
2061
2057
  });
2062
2058
  }, onCompileDone = ({ compiler, onDone, onEnvironmentDone, MultiStatsCtor })=>{
2063
- if (isMultiCompiler(compiler)) {
2059
+ if (helpers_isMultiCompiler(compiler)) {
2064
2060
  let { compilers } = compiler, compilerStats = [], doneCompilers = 0;
2065
2061
  for(let index = 0; index < compilers.length; index++){
2066
2062
  let compiler = compilers[index], compilerIndex = index, compilerDone = !1;
@@ -2281,14 +2277,14 @@ async function updateEnvironmentContext(context, configs) {
2281
2277
  });
2282
2278
  }
2283
2279
  }
2284
- async function createContext(options, userConfig, bundlerType) {
2280
+ async function createContext(options, userConfig) {
2285
2281
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
2286
2282
  return {
2287
- version: "1.2.17",
2283
+ version: "1.2.19",
2288
2284
  rootPath,
2289
2285
  distPath: '',
2290
2286
  cachePath,
2291
- bundlerType,
2287
+ bundlerType: userConfig.provider ? 'webpack' : 'rspack',
2292
2288
  environments: {},
2293
2289
  hooks: {
2294
2290
  onExit: createAsyncHook(),
@@ -4791,22 +4787,25 @@ async function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerCo
4791
4787
  };
4792
4788
  }
4793
4789
  var dist = __webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/index.js");
4794
- async function modifyRspackConfig(context, rspackConfig, utils) {
4790
+ async function modifyRspackConfig(context, rspackConfig, chainUtils) {
4795
4791
  var _utils_environment_config_tools;
4796
4792
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rspack config');
4797
- let [modifiedConfig] = await context.hooks.modifyRspackConfig.callChain({
4793
+ let currentConfig = rspackConfig, proxiedConfig = new Proxy({}, {
4794
+ get: (_, prop)=>currentConfig[prop],
4795
+ set: (_, prop, value)=>(currentConfig[prop] = value, !0)
4796
+ }), utils = await getConfigUtils(proxiedConfig, chainUtils);
4797
+ return [currentConfig] = await context.hooks.modifyRspackConfig.callChain({
4798
4798
  environment: utils.environment.name,
4799
4799
  args: [
4800
4800
  rspackConfig,
4801
4801
  utils
4802
4802
  ]
4803
- });
4804
- return (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.rspack) && (modifiedConfig = await reduceConfigsAsyncWithContext({
4805
- initial: modifiedConfig,
4803
+ }), (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.rspack) && (currentConfig = await reduceConfigsAsyncWithContext({
4804
+ initial: currentConfig,
4806
4805
  config: utils.environment.config.tools.rspack,
4807
4806
  ctx: utils,
4808
- mergeFn: utils.mergeConfig
4809
- })), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rspack config done'), modifiedConfig;
4807
+ mergeFn: (...args)=>currentConfig = utils.mergeConfig.call(utils, args)
4808
+ })), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rspack config done'), currentConfig;
4810
4809
  }
4811
4810
  async function getConfigUtils(config, chainUtils) {
4812
4811
  return {
@@ -4867,7 +4866,7 @@ async function generateRspackConfig({ target, context, environment }) {
4867
4866
  }
4868
4867
  }
4869
4868
  config.devServer && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`[rsbuild:config] Find invalid Rspack config: "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`);
4870
- }(rspackConfig = await modifyRspackConfig(context, rspackConfig, await getConfigUtils(rspackConfig, chainUtils))), rspackConfig;
4869
+ }(rspackConfig = await modifyRspackConfig(context, rspackConfig, chainUtils)), rspackConfig;
4871
4870
  }
4872
4871
  async function modifyRsbuildConfig(context) {
4873
4872
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rsbuild config');
@@ -5246,24 +5245,24 @@ class SocketServer {
5246
5245
  getStats(name) {
5247
5246
  let curStats = this.stats[name];
5248
5247
  if (!curStats) return null;
5249
- let statsOptions = getStatsOptions(curStats.compilation.compiler);
5250
- return {
5251
- statsJson: curStats.toJson({
5252
- all: !1,
5253
- hash: !0,
5254
- assets: !0,
5255
- warnings: !0,
5256
- warningsCount: !0,
5257
- errors: !0,
5258
- errorsCount: !0,
5259
- errorDetails: !1,
5260
- entrypoints: !0,
5261
- children: !0,
5262
- moduleTrace: !0,
5263
- ...statsOptions
5264
- }),
5248
+ let statsOptions = getStatsOptions(curStats.compilation.compiler), statsJson = curStats.toJson({
5249
+ all: !1,
5250
+ hash: !0,
5251
+ assets: !0,
5252
+ warnings: !0,
5253
+ warningsCount: !0,
5254
+ errors: !0,
5255
+ errorsCount: !0,
5256
+ errorDetails: !1,
5257
+ entrypoints: !0,
5258
+ children: !0,
5259
+ moduleTrace: !0,
5260
+ ...statsOptions
5261
+ });
5262
+ return statsJson ? {
5263
+ statsJson,
5265
5264
  root: curStats.compilation.compiler.options.context
5266
- };
5265
+ } : null;
5267
5266
  }
5268
5267
  sendStats({ force = !1, compilationId }) {
5269
5268
  let result = this.getStats(compilationId);
@@ -5681,7 +5680,12 @@ class CommonJsRunner extends BasicRunner {
5681
5680
  let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
5682
5681
  ${file.content}
5683
5682
  })`;
5684
- return this.preExecute(code, file), (this._options.runInNewContext ? __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.runInNewContext(code, this.globalContext, file.path) : __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.runInThisContext(code, file.path)).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
5683
+ this.preExecute(code, file);
5684
+ let dynamicImport = Function('specifier', 'return import(specifier)');
5685
+ return __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.runInThisContext(code, {
5686
+ filename: file.path,
5687
+ importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
5688
+ }).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
5685
5689
  };
5686
5690
  }
5687
5691
  }
@@ -6124,7 +6128,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
6124
6128
  }) : Promise.resolve(), startCompile = async ()=>{
6125
6129
  let compiler = customCompiler || await createCompiler();
6126
6130
  if (!compiler) throw Error('[rsbuild:server] Failed to get compiler instance.');
6127
- let publicPaths = isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
6131
+ let publicPaths = helpers_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
6128
6132
  getPublicPathFromCompiler(compiler)
6129
6133
  ], compilerDevMiddleware = new CompilerDevMiddleware({
6130
6134
  dev: devConfig,
@@ -6136,7 +6140,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
6136
6140
  compiler,
6137
6141
  environments: options.context.environments
6138
6142
  });
6139
- return await compilerDevMiddleware.init(), outputFileSystem = (isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default, {
6143
+ return await compilerDevMiddleware.init(), outputFileSystem = (helpers_isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default, {
6140
6144
  middleware: compilerDevMiddleware.middleware,
6141
6145
  sockWrite: (...args)=>compilerDevMiddleware.sockWrite(...args),
6142
6146
  onUpgrade: (...args)=>compilerDevMiddleware.upgrade(...args),
@@ -6285,7 +6289,7 @@ async function createCompiler_createCompiler(options) {
6285
6289
  bundlerConfigs: rspackConfigs,
6286
6290
  environments: context.environments
6287
6291
  }), !await isSatisfyRspackVersion(__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.rspackVersion)) throw Error(`[rsbuild] The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(rspackMinVersion)}`);
6288
- let compiler = 1 === rspackConfigs.length ? (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs[0]) : (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
6292
+ let isMultiCompiler = rspackConfigs.length > 1, compiler = isMultiCompiler ? (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs) : (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs[0]), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
6289
6293
  isVersionLogged || (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`use Rspack v${__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.rspackVersion}`), isVersionLogged = !0);
6290
6294
  };
6291
6295
  compiler.hooks.watchRun.tap('rsbuild:compiling', (compiler)=>{
@@ -6314,13 +6318,13 @@ async function createCompiler_createCompiler(options) {
6314
6318
  ...statsOptions
6315
6319
  }), printTime = (c, index)=>{
6316
6320
  if (c.time) {
6317
- let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(` (${name})`) : '';
6321
+ let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name && isMultiCompiler ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(` (${name})`) : '';
6318
6322
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.ready(`built in ${time}${suffix}`);
6319
6323
  }
6320
6324
  }, hasErrors = stats.hasErrors();
6321
6325
  if (!hasErrors) {
6322
6326
  var _statsJson_children;
6323
- rspackConfigs.length > 1 && (null === (_statsJson_children = statsJson.children) || void 0 === _statsJson_children ? void 0 : _statsJson_children.length) ? statsJson.children.forEach((c, index)=>{
6327
+ isMultiCompiler && (null === (_statsJson_children = statsJson.children) || void 0 === _statsJson_children ? void 0 : _statsJson_children.length) ? statsJson.children.forEach((c, index)=>{
6324
6328
  printTime(c, index);
6325
6329
  }) : printTime(statsJson, 0);
6326
6330
  }
@@ -6342,7 +6346,7 @@ async function createCompiler_createCompiler(options) {
6342
6346
  rspackConfigs
6343
6347
  };
6344
6348
  }
6345
- let build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
6349
+ let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
6346
6350
  let compiler, bundlerConfigs;
6347
6351
  let { context } = initOptions;
6348
6352
  if (customCompiler) compiler = customCompiler;
@@ -6367,7 +6371,7 @@ let build_build = async (initOptions, { watch, compiler: customCompiler } = {})=
6367
6371
  };
6368
6372
  let { stats } = await new Promise((resolve, reject)=>{
6369
6373
  compiler.run((err, stats)=>{
6370
- err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error('Rspack build failed!')) : compiler.close((closeErr)=>{
6374
+ err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error(RSPACK_BUILD_ERROR)) : compiler.close((closeErr)=>{
6371
6375
  closeErr && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(closeErr), resolve({
6372
6376
  stats
6373
6377
  });
@@ -6663,10 +6667,34 @@ async function applyDefaultPlugins(pluginManager, context) {
6663
6667
  }
6664
6668
  async function createRsbuild(options = {}) {
6665
6669
  let plugins;
6666
- let { rsbuildConfig = {} } = options, rsbuildOptions = {
6670
+ let envs = options.loadEnv ? loadEnv({
6671
+ cwd: options.cwd,
6672
+ ...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
6673
+ }) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
6674
+ !function(config, envs) {
6675
+ var _config_performance;
6676
+ if (null !== envs) {
6677
+ if (config.source ||= {}, config.source.define = {
6678
+ ...envs.publicVars,
6679
+ ...config.source.define
6680
+ }, 0 !== envs.filePaths.length && (config.dev ||= {}, config.dev.watchFiles = [
6681
+ ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
6682
+ {
6683
+ paths: envs.filePaths,
6684
+ type: 'reload-server'
6685
+ }
6686
+ ], null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache)) {
6687
+ let { buildCache } = config.performance;
6688
+ !0 === buildCache ? config.performance.buildCache = {
6689
+ buildDependencies: envs.filePaths
6690
+ } : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
6691
+ }
6692
+ }
6693
+ }(config, envs);
6694
+ let resolvedOptions = {
6667
6695
  cwd: process.cwd(),
6668
- rsbuildConfig,
6669
- ...options
6696
+ ...options,
6697
+ rsbuildConfig: config
6670
6698
  }, pluginManager = (plugins = [], {
6671
6699
  getPlugins: (options = {
6672
6700
  environment: RSBUILD_ALL_ENVIRONMENT_SYMBOL
@@ -6718,7 +6746,7 @@ async function createRsbuild(options = {}) {
6718
6746
  isPluginExists: (pluginName, options = {
6719
6747
  environment: RSBUILD_ALL_ENVIRONMENT_SYMBOL
6720
6748
  })=>!!plugins.find((plugin)=>plugin.instance.name === pluginName && isPluginMatchEnvironment(plugin.environment, options.environment))
6721
- }), context = await createContext(rsbuildOptions, rsbuildOptions.rsbuildConfig, rsbuildConfig.provider ? 'webpack' : 'rspack'), getPluginAPI = function({ context, pluginManager }) {
6749
+ }), context = await createContext(resolvedOptions, config), getPluginAPI = function({ context, pluginManager }) {
6722
6750
  let { hooks } = context, publicContext = function(context) {
6723
6751
  let exposedKeys = [
6724
6752
  'version',
@@ -6899,10 +6927,10 @@ async function createRsbuild(options = {}) {
6899
6927
  context.getPluginAPI = getPluginAPI;
6900
6928
  let globalPluginAPI = getPluginAPI();
6901
6929
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('add default plugins'), await applyDefaultPlugins(pluginManager, context), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('add default plugins done');
6902
- let provider = rsbuildConfig.provider || rspackProvider, providerInstance = await provider({
6930
+ let provider = config.provider || rspackProvider, providerInstance = await provider({
6903
6931
  context,
6904
6932
  pluginManager,
6905
- rsbuildOptions,
6933
+ rsbuildOptions: resolvedOptions,
6906
6934
  helpers: provider_helpers_namespaceObject
6907
6935
  }), rsbuild = {
6908
6936
  build: async (...args)=>{
@@ -6960,19 +6988,21 @@ async function createRsbuild(options = {}) {
6960
6988
  'initConfigs',
6961
6989
  'inspectConfig'
6962
6990
  ])
6963
- }, getFlattenedPlugins = async (pluginOptions)=>{
6991
+ };
6992
+ envs && (rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup));
6993
+ let getFlattenedPlugins = async (pluginOptions)=>{
6964
6994
  let plugins = pluginOptions;
6965
6995
  do plugins = (await Promise.all(plugins)).flat(Number.POSITIVE_INFINITY);
6966
6996
  while (plugins.some((v)=>(0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isPromise)(v)));
6967
6997
  return plugins;
6968
6998
  };
6969
- if (rsbuildConfig.plugins) {
6970
- let plugins = await getFlattenedPlugins(rsbuildConfig.plugins);
6999
+ if (config.plugins) {
7000
+ let plugins = await getFlattenedPlugins(config.plugins);
6971
7001
  rsbuild.addPlugins(plugins);
6972
7002
  }
6973
- return rsbuildConfig.environments && await Promise.all(Object.entries(rsbuildConfig.environments).map(async ([name, config])=>{
6974
- if (!config.plugins || context.specifiedEnvironments && !context.specifiedEnvironments.includes(name)) return;
6975
- let plugins = await getFlattenedPlugins(config.plugins);
7003
+ return config.environments && await Promise.all(Object.entries(config.environments).map(async ([name, environmentConfig])=>{
7004
+ if (!environmentConfig.plugins || context.specifiedEnvironments && !context.specifiedEnvironments.includes(name)) return;
7005
+ let plugins = await getFlattenedPlugins(environmentConfig.plugins);
6976
7006
  rsbuild.addPlugins(plugins, {
6977
7007
  environment: name
6978
7008
  });
@@ -7305,13 +7335,13 @@ async function runCLI() {
7305
7335
  }
7306
7336
  }(), process.title = 'rsbuild-node';
7307
7337
  let { npm_execpath } = process.env;
7308
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.17\n`);
7338
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.19\n`);
7309
7339
  }();
7310
7340
  try {
7311
7341
  !function() {
7312
7342
  let cli = cac_dist('rsbuild');
7313
- cli.help(), cli.version("1.2.17"), applyCommonOptions(cli);
7314
- let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
7343
+ cli.help(), cli.version("1.2.19"), applyCommonOptions(cli);
7344
+ let devCommand = cli.command('', 'starting the dev server').alias('dev'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
7315
7345
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7316
7346
  try {
7317
7347
  let rsbuild = await init({
@@ -7331,7 +7361,7 @@ async function runCLI() {
7331
7361
  }));
7332
7362
  buildInstance && (options.watch ? onBeforeRestartServer(buildInstance.close) : await buildInstance.close());
7333
7363
  } catch (err) {
7334
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to build.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err), process.exit(1);
7364
+ err instanceof Error && err.message === RSPACK_BUILD_ERROR || __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to build.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err), process.exit(1);
7335
7365
  }
7336
7366
  }), previewCommand.action(async (options)=>{
7337
7367
  try {
@@ -7361,6 +7391,6 @@ async function runCLI() {
7361
7391
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
7362
7392
  }
7363
7393
  }
7364
- let src_version = "1.2.17";
7394
+ let src_version = "1.2.19";
7365
7395
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
7366
7396
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
@@ -1,4 +1,4 @@
1
- import type { BundlerType, InternalContext, NormalizedEnvironmentConfig, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext } from './types';
1
+ import type { InternalContext, NormalizedEnvironmentConfig, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext } from './types';
2
2
  export declare function getBrowserslist(path: string): Promise<string[] | null>;
3
3
  export declare function getBrowserslistByEnvironment(path: string, config: NormalizedEnvironmentConfig): Promise<string[]>;
4
4
  export declare function updateEnvironmentContext(context: InternalContext, configs: Record<string, NormalizedEnvironmentConfig>): Promise<void>;
@@ -8,4 +8,4 @@ export declare function createPublicContext(context: RsbuildContext): Readonly<R
8
8
  * Generate the actual context used in the build,
9
9
  * which can have a lot of overhead and take some side effects.
10
10
  */
11
- export declare function createContext(options: ResolvedCreateRsbuildOptions, userConfig: RsbuildConfig, bundlerType: BundlerType): Promise<InternalContext>;
11
+ export declare function createContext(options: ResolvedCreateRsbuildOptions, userConfig: RsbuildConfig): Promise<InternalContext>;
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { rspack } from '@rspack/core';
6
6
  import type * as Rspack from '@rspack/core';
7
- export { loadEnv } from './loadEnv';
7
+ export { loadEnv, type LoadEnvOptions, type LoadEnvResult } from './loadEnv';
8
8
  export { createRsbuild } from './createRsbuild';
9
9
  export { loadConfig, defineConfig, type ConfigParams, type LoadConfigOptions, type LoadConfigResult, } from './config';
10
10
  export { runCLI } from './cli';
@@ -18,3 +18,4 @@ export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME } from './constants';
18
18
  export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, Charset, ClientConfig, CliShortcut, CleanDistPath, CleanDistPathObject, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InternalContext, LegalComments, ManifestData, ManifestConfig, ManifestObjectConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigFn, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterEnvironmentCompileFn, OnBeforeEnvironmentCompileFn, OnCloseBuildFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PreloadIncludeType, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
19
19
  export type { ChainIdentifier } from './configChain';
20
20
  export type { RsbuildDevServer } from './server/devServer';
21
+ export type { StartServerResult } from './server/helper';
@@ -21,7 +21,7 @@ export type LoadEnvOptions = {
21
21
  */
22
22
  processEnv?: Record<string, string>;
23
23
  };
24
- export declare function loadEnv({ cwd, mode, prefixes, processEnv, }?: LoadEnvOptions): {
24
+ export type LoadEnvResult = {
25
25
  /**
26
26
  * All env variables in the .env file
27
27
  */
@@ -60,3 +60,4 @@ export declare function loadEnv({ cwd, mode, prefixes, processEnv, }?: LoadEnvOp
60
60
  */
61
61
  cleanup: () => void;
62
62
  };
63
+ export declare function loadEnv({ cwd, mode, prefixes, processEnv, }?: LoadEnvOptions): LoadEnvResult;
@@ -1,3 +1,4 @@
1
1
  import type { Build, BuildOptions } from '../types';
2
2
  import type { InitConfigsOptions } from './initConfigs';
3
+ export declare const RSPACK_BUILD_ERROR = "Rspack build failed.";
3
4
  export declare const build: (initOptions: InitConfigsOptions, { watch, compiler: customCompiler }?: BuildOptions) => Promise<ReturnType<Build>>;
@@ -3,7 +3,6 @@ import type { BasicGlobalContext, BasicModuleScope, BasicRunnerFile, ModuleObjec
3
3
  export interface IBasicRunnerOptions {
4
4
  name: string;
5
5
  isBundleOutput: (modulePath: string) => boolean;
6
- runInNewContext?: boolean;
7
6
  readFileSync: (path: string) => string;
8
7
  dist: string;
9
8
  compilerOptions: CompilerOptions;
@@ -1,4 +1,5 @@
1
1
  import type { Compiler, MultiCompiler } from '@rspack/core';
2
+ import type { LoadEnvOptions } from '../loadEnv';
2
3
  import type * as providerHelpers from '../provider/helpers';
3
4
  import type { RsbuildDevServer } from '../server/devServer';
4
5
  import type { StartServerResult } from '../server/helper';
@@ -53,7 +54,8 @@ export type BuildOptions = {
53
54
  };
54
55
  export type Build = (options?: BuildOptions) => Promise<{
55
56
  /**
56
- * Stop watching when in watch mode.
57
+ * Close the build and call the `onCloseBuild` hook.
58
+ * In watch mode, this method will stop watching.
57
59
  */
58
60
  close: () => Promise<void>;
59
61
  /**
@@ -62,9 +64,27 @@ export type Build = (options?: BuildOptions) => Promise<{
62
64
  stats?: Rspack.Stats | Rspack.MultiStats;
63
65
  }>;
64
66
  export type InspectConfigOptions = {
67
+ /**
68
+ * Inspect the config in the specified mode.
69
+ * Available options: 'development' or 'production'.
70
+ * @default 'development'
71
+ */
65
72
  mode?: RsbuildMode;
73
+ /**
74
+ * Enables verbose mode to display the complete function
75
+ * content in the configuration.
76
+ * @default false
77
+ */
66
78
  verbose?: boolean;
79
+ /**
80
+ * Specify the output path for inspection results.
81
+ * @default 'output.distPath.root'
82
+ */
67
83
  outputPath?: string;
84
+ /**
85
+ * Whether to write the inspection results to disk.
86
+ * @default false
87
+ */
68
88
  writeToDisk?: boolean;
69
89
  };
70
90
  export type InspectConfigResult<B extends 'rspack' | 'webpack' = 'rspack'> = {
@@ -92,10 +112,19 @@ export type CreateRsbuildOptions = {
92
112
  environment?: string[];
93
113
  /**
94
114
  * Rsbuild configurations.
115
+ * Passing a function to load the config asynchronously with custom logic.
95
116
  */
96
- rsbuildConfig?: RsbuildConfig;
117
+ rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
118
+ /**
119
+ * Whether to call `loadEnv` to load environment variables and define them
120
+ * as global variables.
121
+ * @default false
122
+ */
123
+ loadEnv?: boolean | LoadEnvOptions;
124
+ };
125
+ export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, 'cwd'>> & Pick<CreateRsbuildOptions, 'loadEnv' | 'environment'> & {
126
+ rsbuildConfig: RsbuildConfig;
97
127
  };
98
- export type ResolvedCreateRsbuildOptions = CreateRsbuildOptions & Required<Omit<CreateRsbuildOptions, 'environment'>>;
99
128
  export type CreateDevServer = (options?: CreateDevServerOptions) => Promise<RsbuildDevServer>;
100
129
  export type StartDevServer = (options?: StartDevServerOptions) => Promise<StartServerResult>;
101
130
  export type ProviderInstance<B extends 'rspack' | 'webpack' = 'rspack'> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.2.7",
49
+ "@rspack/core": "1.2.8",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.15",
52
52
  "core-js": "~3.41.0",