@rsbuild/core 1.6.0 → 1.6.2

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
- 9796: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 2502: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const loader = __nccwpck_require__(5802);
5
+ const loader = __nccwpck_require__(2476);
6
6
  module.exports = loader.default;
7
7
  module.exports.defaultGetLocalIdent =
8
- __nccwpck_require__(5499).defaultGetLocalIdent;
8
+ __nccwpck_require__(8645).defaultGetLocalIdent;
9
9
  },
10
- 5802: (__unused_webpack_module, exports, __nccwpck_require__) => {
10
+ 2476: (__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__(1259));
15
- var _plugins = __nccwpck_require__(4617);
16
- var _utils = __nccwpck_require__(5499);
15
+ var _plugins = __nccwpck_require__(5923);
16
+ var _utils = __nccwpck_require__(8645);
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
- 4617: (__unused_webpack_module, exports, __nccwpck_require__) => {
239
+ 5923: (__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,22 @@
258
258
  },
259
259
  });
260
260
  var _postcssImportParser = _interopRequireDefault(
261
- __nccwpck_require__(2818),
261
+ __nccwpck_require__(6584),
262
262
  );
263
263
  var _postcssIcssParser = _interopRequireDefault(
264
- __nccwpck_require__(9499),
264
+ __nccwpck_require__(3965),
265
265
  );
266
- var _postcssUrlParser = _interopRequireDefault(__nccwpck_require__(334));
266
+ var _postcssUrlParser = _interopRequireDefault(__nccwpck_require__(9836));
267
267
  function _interopRequireDefault(obj) {
268
268
  return obj && obj.__esModule ? obj : { default: obj };
269
269
  }
270
270
  },
271
- 9499: (__unused_webpack_module, exports, __nccwpck_require__) => {
271
+ 3965: (__unused_webpack_module, exports, __nccwpck_require__) => {
272
272
  "use strict";
273
273
  Object.defineProperty(exports, "__esModule", { value: true });
274
274
  exports["default"] = void 0;
275
275
  var _icssUtils = __nccwpck_require__(229);
276
- var _utils = __nccwpck_require__(5499);
276
+ var _utils = __nccwpck_require__(8645);
277
277
  const plugin = (options = {}) => ({
278
278
  postcssPlugin: "postcss-icss-parser",
279
279
  async OnceExit(root) {
@@ -372,14 +372,14 @@
372
372
  plugin.postcss = true;
373
373
  var _default = (exports["default"] = plugin);
374
374
  },
375
- 2818: (__unused_webpack_module, exports, __nccwpck_require__) => {
375
+ 6584: (__unused_webpack_module, exports, __nccwpck_require__) => {
376
376
  "use strict";
377
377
  Object.defineProperty(exports, "__esModule", { value: true });
378
378
  exports["default"] = void 0;
379
379
  var _postcssValueParser = _interopRequireDefault(
380
380
  __nccwpck_require__(5245),
381
381
  );
382
- var _utils = __nccwpck_require__(5499);
382
+ var _utils = __nccwpck_require__(8645);
383
383
  function _interopRequireDefault(obj) {
384
384
  return obj && obj.__esModule ? obj : { default: obj };
385
385
  }
@@ -684,14 +684,14 @@
684
684
  plugin.postcss = true;
685
685
  var _default = (exports["default"] = plugin);
686
686
  },
687
- 334: (__unused_webpack_module, exports, __nccwpck_require__) => {
687
+ 9836: (__unused_webpack_module, exports, __nccwpck_require__) => {
688
688
  "use strict";
689
689
  Object.defineProperty(exports, "__esModule", { value: true });
690
690
  exports["default"] = void 0;
691
691
  var _postcssValueParser = _interopRequireDefault(
692
692
  __nccwpck_require__(5245),
693
693
  );
694
- var _utils = __nccwpck_require__(5499);
694
+ var _utils = __nccwpck_require__(8645);
695
695
  function _interopRequireDefault(obj) {
696
696
  return obj && obj.__esModule ? obj : { default: obj };
697
697
  }
@@ -1034,7 +1034,7 @@
1034
1034
  plugin.postcss = true;
1035
1035
  var _default = (exports["default"] = plugin);
1036
1036
  },
1037
- 5499: (__unused_webpack_module, exports, __nccwpck_require__) => {
1037
+ 8645: (__unused_webpack_module, exports, __nccwpck_require__) => {
1038
1038
  "use strict";
1039
1039
  Object.defineProperty(exports, "__esModule", { value: true });
1040
1040
  exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
@@ -8098,6 +8098,6 @@
8098
8098
  }
8099
8099
  if (typeof __nccwpck_require__ !== "undefined")
8100
8100
  __nccwpck_require__.ab = __dirname + "/";
8101
- var __webpack_exports__ = __nccwpck_require__(9796);
8101
+ var __webpack_exports__ = __nccwpck_require__(2502);
8102
8102
  module.exports = __webpack_exports__;
8103
8103
  })();
@@ -1,8 +1,8 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 480: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 837: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const { HtmlWebpackChildCompiler } = __nccwpck_require__(397);
5
+ const { HtmlWebpackChildCompiler } = __nccwpck_require__(726);
6
6
  const compilerMap = new WeakMap();
7
7
  class CachedChildCompilation {
8
8
  constructor(compiler) {
@@ -311,7 +311,7 @@
311
311
  }
312
312
  module.exports = { CachedChildCompilation };
313
313
  },
314
- 397: (module) => {
314
+ 726: (module) => {
315
315
  "use strict";
316
316
  class HtmlWebpackChildCompiler {
317
317
  constructor(templates) {
@@ -480,7 +480,7 @@
480
480
  }
481
481
  module.exports = { HtmlWebpackChildCompiler };
482
482
  },
483
- 835: (module) => {
483
+ 926: (module) => {
484
484
  "use strict";
485
485
  module.exports = {};
486
486
  module.exports.none = (chunks) => chunks;
@@ -499,7 +499,7 @@
499
499
  };
500
500
  module.exports.auto = module.exports.none;
501
501
  },
502
- 542: (module) => {
502
+ 393: (module) => {
503
503
  "use strict";
504
504
  module.exports = function (err) {
505
505
  return {
@@ -520,7 +520,7 @@
520
520
  };
521
521
  };
522
522
  },
523
- 605: (module, __unused_webpack_exports, __nccwpck_require__) => {
523
+ 616: (module, __unused_webpack_exports, __nccwpck_require__) => {
524
524
  "use strict";
525
525
  const { AsyncSeriesWaterfallHook } = __nccwpck_require__(408);
526
526
  const htmlWebpackPluginHooksMap = new WeakMap();
@@ -546,7 +546,7 @@
546
546
  }
547
547
  module.exports = { getHtmlRspackPluginHooks };
548
548
  },
549
- 468: (module) => {
549
+ 813: (module) => {
550
550
  const voidTags = [
551
551
  "area",
552
552
  "base",
@@ -614,19 +614,19 @@
614
614
  htmlTagObjectToString,
615
615
  };
616
616
  },
617
- 33: (module, __unused_webpack_exports, __nccwpck_require__) => {
617
+ 440: (module, __unused_webpack_exports, __nccwpck_require__) => {
618
618
  "use strict";
619
619
  const promisify = __nccwpck_require__(23).promisify;
620
620
  const vm = __nccwpck_require__(154);
621
621
  const fs = __nccwpck_require__(896);
622
622
  const path = __nccwpck_require__(928);
623
- const { CachedChildCompilation } = __nccwpck_require__(480);
623
+ const { CachedChildCompilation } = __nccwpck_require__(837);
624
624
  const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } =
625
- __nccwpck_require__(468);
626
- const prettyError = __nccwpck_require__(542);
627
- const chunkSorter = __nccwpck_require__(835);
625
+ __nccwpck_require__(813);
626
+ const prettyError = __nccwpck_require__(393);
627
+ const chunkSorter = __nccwpck_require__(926);
628
628
  const getHtmlRspackPluginHooks =
629
- __nccwpck_require__(605).getHtmlRspackPluginHooks;
629
+ __nccwpck_require__(616).getHtmlRspackPluginHooks;
630
630
  const WITH_PLACEHOLDER = "function __with_placeholder__";
631
631
  class HtmlRspackPlugin {
632
632
  constructor(userOptions = {}) {
@@ -1597,6 +1597,6 @@
1597
1597
  }
1598
1598
  if (typeof __nccwpck_require__ !== "undefined")
1599
1599
  __nccwpck_require__.ab = __dirname + "/";
1600
- var __webpack_exports__ = __nccwpck_require__(33);
1600
+ var __webpack_exports__ = __nccwpck_require__(440);
1601
1601
  module.exports = __webpack_exports__;
1602
1602
  })();
@@ -1,15 +1,15 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 993: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- module.exports = __nccwpck_require__(443)["default"];
4
+ 450: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ module.exports = __nccwpck_require__(288)["default"];
6
6
  },
7
- 443: (__unused_webpack_module, exports, __nccwpck_require__) => {
7
+ 288: (__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 _nodePath = _interopRequireDefault(__nccwpck_require__(760));
12
- var _utils = __nccwpck_require__(566);
12
+ var _utils = __nccwpck_require__(681);
13
13
  function _interopRequireDefault(e) {
14
14
  return e && e.__esModule ? e : { default: e };
15
15
  }
@@ -179,7 +179,7 @@
179
179
  callback(null, result.css, map, { ast });
180
180
  }
181
181
  },
182
- 566: (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;
@@ -715,6 +715,6 @@
715
715
  })();
716
716
  if (typeof __nccwpck_require__ !== "undefined")
717
717
  __nccwpck_require__.ab = __dirname + "/";
718
- var __webpack_exports__ = __nccwpck_require__(993);
718
+ var __webpack_exports__ = __nccwpck_require__(450);
719
719
  module.exports = __webpack_exports__;
720
720
  })();
@@ -1,7 +1,7 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 843: (__unused_webpack_module, exports, __nccwpck_require__) => {
4
+ 724: (__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
- 550: (__unused_webpack_module, exports, __nccwpck_require__) => {
123
+ 629: (__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 node_fs_1 = __nccwpck_require__(24);
131
131
  const node_path_1 = __nccwpck_require__(760);
132
132
  const lite_tapable_1 = __nccwpck_require__(408);
133
- const helpers_1 = __nccwpck_require__(843);
133
+ const helpers_1 = __nccwpck_require__(724);
134
134
  const compilerHookMap = new WeakMap();
135
135
  const getCompilerHooks = (compiler) => {
136
136
  let hooks = compilerHookMap.get(compiler);
@@ -313,7 +313,7 @@
313
313
  exports.getCompilerHooks =
314
314
  void 0;
315
315
  const node_path_1 = __nccwpck_require__(760);
316
- const hooks_1 = __nccwpck_require__(550);
316
+ const hooks_1 = __nccwpck_require__(629);
317
317
  Object.defineProperty(exports, "getCompilerHooks", {
318
318
  enumerable: true,
319
319
  get: function () {
@@ -1,4 +1,4 @@
1
- let ignoreCssLoader = function(source) {
1
+ let loader_ignoreCssLoader = function(source) {
2
2
  return (this?.cacheable(!0), source.includes('___CSS_LOADER_EXPORT___')) ? '' : source;
3
3
  };
4
- export { ignoreCssLoader as default };
4
+ export { loader_ignoreCssLoader as default };
package/dist/index.cjs CHANGED
@@ -1694,19 +1694,19 @@ for(var __webpack_i__ in (()=>{
1694
1694
  "use strict";
1695
1695
  let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, hmrClientPath, overlayClientPath;
1696
1696
  __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
1697
- PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
1698
- createRsbuild: ()=>createRsbuild,
1699
- logger: ()=>logger,
1700
- mergeRsbuildConfig: ()=>mergeRsbuildConfig,
1701
- loadConfig: ()=>loadConfig_loadConfig,
1702
1697
  PLUGIN_SWC_NAME: ()=>PLUGIN_SWC_NAME,
1703
- defaultAllowedOrigins: ()=>defaultAllowedOrigins,
1704
1698
  ensureAssetPrefix: ()=>ensureAssetPrefix,
1699
+ loadConfig: ()=>loadConfig_loadConfig,
1700
+ createRsbuild: ()=>createRsbuild,
1701
+ logger: ()=>logger,
1702
+ version: ()=>src_version,
1705
1703
  loadEnv: ()=>loadEnv,
1706
- rspack: ()=>rspack_rspack,
1704
+ PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
1707
1705
  runCLI: ()=>runCLI,
1706
+ rspack: ()=>rspack_rspack,
1708
1707
  defineConfig: ()=>defineConfig,
1709
- version: ()=>src_version
1708
+ mergeRsbuildConfig: ()=>mergeRsbuildConfig,
1709
+ defaultAllowedOrigins: ()=>defaultAllowedOrigins
1710
1710
  });
1711
1711
  var superClass, superClass1, provider_helpers_namespaceObject = {};
1712
1712
  __webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(provider_helpers_namespaceObject, {
@@ -1714,7 +1714,7 @@ for(var __webpack_i__ in (()=>{
1714
1714
  formatStats: ()=>formatStats,
1715
1715
  getChainUtils: ()=>getChainUtils,
1716
1716
  getConfigUtils: ()=>getConfigUtils,
1717
- getHTMLPlugin: ()=>getHTMLPlugin,
1717
+ getHTMLPlugin: ()=>pluginHelper_getHTMLPlugin,
1718
1718
  getRsbuildStats: ()=>getRsbuildStats,
1719
1719
  initRsbuildConfig: ()=>initRsbuildConfig,
1720
1720
  inspectConfig: ()=>inspectConfig_inspectConfig,
@@ -2827,7 +2827,7 @@ ${section.body}` : section.body).join("\n\n"));
2827
2827
  }
2828
2828
  let setNodeEnv = (env)=>{
2829
2829
  process.env.NODE_ENV = env;
2830
- }, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && Object.getPrototypeOf(obj) === objectPrototype, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
2830
+ }, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, getProto = Object.getPrototypeOf, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && getProto(obj) === objectPrototype, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
2831
2831
  arr
2832
2832
  ], cloneDeep = (value)=>null == value ? value : cjs_default()({}, value, {
2833
2833
  isMergeableObject: isPlainObject
@@ -3399,7 +3399,7 @@ ${section.body}` : section.body).join("\n\n"));
3399
3399
  logger.debug(`failed to empty dir: ${dir}`), logger.debug(err);
3400
3400
  }
3401
3401
  }
3402
- let OVERRIDE_PATHS = [
3402
+ let OVERRIDE_PATHS = new Set([
3403
3403
  'performance.removeConsole',
3404
3404
  'output.inlineScripts',
3405
3405
  'output.inlineStyles',
@@ -3411,26 +3411,32 @@ ${section.body}` : section.body).join("\n\n"));
3411
3411
  'resolve.conditionNames',
3412
3412
  'resolve.mainFields',
3413
3413
  'provider'
3414
- ], merge = (x, y, path = '')=>{
3414
+ ]), merge = (x, y, path = '')=>{
3415
3415
  if (((key)=>{
3416
3416
  if (key.startsWith('environments.')) {
3417
3417
  let realKey = key.split('.').slice(2).join('.');
3418
- return OVERRIDE_PATHS.includes(realKey);
3418
+ return OVERRIDE_PATHS.has(realKey);
3419
3419
  }
3420
- return OVERRIDE_PATHS.includes(key) || key.startsWith('output.filename.');
3420
+ return OVERRIDE_PATHS.has(key) || key.startsWith('output.filename.');
3421
3421
  })(path)) return y ?? x;
3422
3422
  if (void 0 === x) return isPlainObject(y) ? cloneDeep(y) : y;
3423
3423
  if (void 0 === y) return isPlainObject(x) ? cloneDeep(x) : x;
3424
- if ('boolean' == typeof x || 'boolean' == typeof y) return y;
3425
- let pair = [
3426
- x,
3424
+ let typeX = typeof x, typeY = typeof y;
3425
+ if ('boolean' === typeX || 'boolean' === typeY) return y;
3426
+ let isArrayX = Array.isArray(x), isArrayY = Array.isArray(y);
3427
+ if (isArrayX && isArrayY) return x.concat(y);
3428
+ if (isArrayX) return [
3429
+ ...x,
3427
3430
  y
3428
3431
  ];
3429
- if (pair.some(Array.isArray)) return [
3430
- ...helpers_castArray(x),
3431
- ...helpers_castArray(y)
3432
+ if (isArrayY) return [
3433
+ x,
3434
+ ...y
3435
+ ];
3436
+ if ('function' === typeX || 'function' === typeY) return [
3437
+ x,
3438
+ y
3432
3439
  ];
3433
- if (pair.some(isFunction)) return pair;
3434
3440
  if (!isPlainObject(x) || !isPlainObject(y)) return y;
3435
3441
  let merged = {};
3436
3442
  for (let key of new Set([
@@ -3442,22 +3448,20 @@ ${section.body}` : section.body).join("\n\n"));
3442
3448
  }
3443
3449
  return merged;
3444
3450
  }, normalizeConfigStructure = (config)=>{
3445
- let { dev, output, ...rest } = config;
3451
+ let { dev, output } = config, normalizedConfig = {
3452
+ ...config
3453
+ };
3446
3454
  return output && (Array.isArray((output = {
3447
3455
  ...output
3448
3456
  }).copy) && (output.copy = {
3449
3457
  patterns: output.copy
3450
3458
  }), 'string' == typeof output.distPath && (output.distPath = {
3451
3459
  root: output.distPath
3452
- })), dev && (dev = {
3460
+ }), normalizedConfig.output = output), dev && ((dev = {
3453
3461
  ...dev
3454
3462
  }).watchFiles && !Array.isArray(dev.watchFiles) && (dev.watchFiles = [
3455
3463
  dev.watchFiles
3456
- ]), {
3457
- ...rest,
3458
- dev,
3459
- output
3460
- };
3464
+ ]), normalizedConfig.dev = dev), normalizedConfig;
3461
3465
  }, mergeRsbuildConfig = (...originalConfigs)=>{
3462
3466
  let configs = originalConfigs.map(normalizeConfigStructure);
3463
3467
  return 2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {});
@@ -3506,7 +3510,8 @@ ${section.body}` : section.body).join("\n\n"));
3506
3510
  mountId: 'root',
3507
3511
  crossorigin: !1,
3508
3512
  outputStructure: 'flat',
3509
- scriptLoading: 'defer'
3513
+ scriptLoading: 'defer',
3514
+ implementation: 'js'
3510
3515
  },
3511
3516
  resolve: (swcHelpersPath || (swcHelpersPath = (0, external_node_path_.dirname)(defaultConfig_require.resolve('@swc/helpers/package.json'))), {
3512
3517
  alias: {
@@ -3830,7 +3835,7 @@ ${section.body}` : section.body).join("\n\n"));
3830
3835
  async function createContext(options, userConfig) {
3831
3836
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
3832
3837
  return {
3833
- version: "1.6.0",
3838
+ version: "1.6.2",
3834
3839
  rootPath,
3835
3840
  distPath: '',
3836
3841
  cachePath,
@@ -4113,7 +4118,7 @@ ${section.body}` : section.body).join("\n\n"));
4113
4118
  }
4114
4119
  }, setHTMLPlugin = (plugin)=>{
4115
4120
  plugin && (pluginHelper_htmlPlugin = plugin);
4116
- }, getHTMLPlugin = ()=>(pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = requireCompiledPackage('html-rspack-plugin')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
4121
+ }, pluginHelper_getHTMLPlugin = (config)=>config?.html.implementation === 'native' ? rspack_rspack.HtmlRspackPlugin : (pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = requireCompiledPackage('html-rspack-plugin')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
4117
4122
  cssExtractPlugin = plugin;
4118
4123
  }, getCssExtractPlugin = ()=>cssExtractPlugin || rspack_rspack.CssExtractRspackPlugin;
4119
4124
  async function modifyRspackConfig(context, rspackConfig, chainUtils) {
@@ -4176,7 +4181,7 @@ ${section.body}` : section.body).join("\n\n"));
4176
4181
  isServer: 'node' === target,
4177
4182
  isWebWorker: 'web-worker' === target,
4178
4183
  CHAIN_ID: configChain_CHAIN_ID,
4179
- HtmlPlugin: getHTMLPlugin()
4184
+ HtmlPlugin: pluginHelper_getHTMLPlugin(environment.config)
4180
4185
  };
4181
4186
  }
4182
4187
  async function generateRspackConfig({ target, context, environment }) {
@@ -4237,20 +4242,17 @@ ${section.body}` : section.body).join("\n\n"));
4237
4242
  };
4238
4243
  async function initRsbuildConfig({ context, pluginManager }) {
4239
4244
  var config, rootPath, context1;
4240
- let distPaths;
4245
+ let defaultConfig, distPaths;
4241
4246
  if (context.normalizedConfig) return context.normalizedConfig;
4242
4247
  await initPlugins({
4243
4248
  context,
4244
4249
  pluginManager
4245
4250
  }), await modifyRsbuildConfig(context);
4246
- let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.publicDir = normalizePublicDirs(rootPath, config.server.publicDir), mergeRsbuildConfig({
4247
- ...createDefaultConfig(),
4248
- mode: (()=>{
4249
- if (config.mode) return config.mode;
4250
- let nodeEnv = process.env.NODE_ENV || '';
4251
- return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none';
4252
- })()
4253
- }, config)), environments = {}, mergedEnvironments = ((normalizedConfig, rootPath, specifiedEnvironments)=>{
4251
+ let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.publicDir = normalizePublicDirs(rootPath, config.server.publicDir), (defaultConfig = createDefaultConfig()).mode = (()=>{
4252
+ if (config.mode) return config.mode;
4253
+ let nodeEnv = process.env.NODE_ENV || '';
4254
+ return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none';
4255
+ })(), mergeRsbuildConfig(defaultConfig, config)), environments = {}, mergedEnvironments = ((normalizedConfig, rootPath, specifiedEnvironments)=>{
4254
4256
  let defaultEntry, { environments, dev, server: _server, provider: _provider, ...baseConfig } = normalizedConfig, isEnvironmentEnabled = (name)=>!specifiedEnvironments || specifiedEnvironments.includes(name), applyEnvironmentDefaultConfig = (config)=>{
4255
4257
  var root;
4256
4258
  let entryFile;
@@ -4828,8 +4830,9 @@ ${section.body}` : section.body).join("\n\n"));
4828
4830
  class RsbuildHtmlPlugin {
4829
4831
  name;
4830
4832
  getExtraData;
4831
- constructor(getExtraData){
4832
- this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
4833
+ getHTMLPlugin;
4834
+ constructor(getExtraData, getHTMLPlugin){
4835
+ this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData, this.getHTMLPlugin = getHTMLPlugin;
4833
4836
  }
4834
4837
  apply(compiler) {
4835
4838
  let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
@@ -4871,7 +4874,7 @@ ${section.body}` : section.body).join("\n\n"));
4871
4874
  if (entryName) return this.getExtraData(entryName);
4872
4875
  };
4873
4876
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
4874
- let hooks = getHTMLPlugin().getCompilationHooks(compilation);
4877
+ let hooks = this.getHTMLPlugin().getCompilationHooks(compilation);
4875
4878
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
4876
4879
  let html, extraData = getExtraDataByPlugin(data.plugin);
4877
4880
  if (!extraData) return data;
@@ -5319,15 +5322,16 @@ ${section.body}` : section.body).join("\n\n"));
5319
5322
  type;
5320
5323
  HTMLCount;
5321
5324
  isDev;
5322
- constructor(options, type, HTMLCount, isDev){
5325
+ getHTMLPlugin;
5326
+ constructor(options, type, HTMLCount, isDev, getHTMLPlugin){
5323
5327
  this.options = {
5324
5328
  ...HtmlResourceHintsPlugin_defaultOptions,
5325
5329
  ...options
5326
- }, this.type = type, this.HTMLCount = HTMLCount, this.isDev = isDev;
5330
+ }, this.type = type, this.HTMLCount = HTMLCount, this.isDev = isDev, this.getHTMLPlugin = getHTMLPlugin;
5327
5331
  }
5328
5332
  apply(compiler) {
5329
5333
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
5330
- let pluginHooks = getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
5334
+ let pluginHooks = this.getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
5331
5335
  pluginHooks.beforeAssetTagGeneration.tap(pluginName, (data)=>(this.resourceHints = function(options, type, compilation, data, HTMLCount, isDev) {
5332
5336
  let extractedChunks = function(compilation, includeType) {
5333
5337
  let chunks = [
@@ -7860,16 +7864,16 @@ ${section.body}` : section.body).join("\n\n"));
7860
7864
  {
7861
7865
  name: 'rsbuild:source-map',
7862
7866
  setup (api) {
7863
- let sourceMapFilenameTemplate = ({ absoluteResourcePath })=>absoluteResourcePath, enableCssSourceMap = (config)=>{
7867
+ let DEFAULT_SOURCE_MAP_TEMPLATE = '[absolute-resource-path]', enableCssSourceMap = (config)=>{
7864
7868
  let { sourceMap } = config.output;
7865
7869
  return 'object' == typeof sourceMap && sourceMap.css;
7866
7870
  };
7867
- api.modifyBundlerChain((chain, { bundler, environment })=>{
7871
+ api.modifyBundlerChain((chain, { bundler, environment, isDev, target })=>{
7868
7872
  let { config } = environment, devtool = ((config)=>{
7869
7873
  let { sourceMap } = config.output, isProd = 'production' === config.mode;
7870
7874
  return !1 !== sourceMap && (!0 === sourceMap ? isProd ? 'source-map' : 'cheap-module-source-map' : void 0 === sourceMap.js ? !isProd && 'cheap-module-source-map' : sourceMap.js);
7871
7875
  })(config);
7872
- chain.devtool(devtool).output.devtoolModuleFilenameTemplate(sourceMapFilenameTemplate), !devtool && enableCssSourceMap(config) && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
7876
+ chain.devtool(devtool), isDev && 'web' === target ? chain.output.devtoolModuleFilenameTemplate((info)=>toPosixPath(info.absoluteResourcePath)) : chain.output.devtoolModuleFilenameTemplate(DEFAULT_SOURCE_MAP_TEMPLATE), !devtool && enableCssSourceMap(config) && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
7873
7877
  {
7874
7878
  test: /\.css$/,
7875
7879
  filename: '[file].map[query]'
@@ -7878,7 +7882,7 @@ ${section.body}` : section.body).join("\n\n"));
7878
7882
  }), api.processAssets({
7879
7883
  stage: 'optimize-transfer'
7880
7884
  }, ({ assets, compilation, sources, environment })=>{
7881
- if (!compilation.options.devtool && !enableCssSourceMap(environment.config) || compilation.outputOptions.devtoolModuleFilenameTemplate !== sourceMapFilenameTemplate) return;
7885
+ if (!compilation.options.devtool && !enableCssSourceMap(environment.config) || compilation.outputOptions.devtoolModuleFilenameTemplate !== DEFAULT_SOURCE_MAP_TEMPLATE) return;
7882
7886
  let { distPath } = environment;
7883
7887
  for (let [filename, asset] of Object.entries(assets)){
7884
7888
  let map;
@@ -8303,7 +8307,8 @@ ${section.body}` : section.body).join("\n\n"));
8303
8307
  }
8304
8308
  ]);
8305
8309
  }), chain.plugin('rsbuild-html-plugin').use(RsbuildHtmlPlugin, [
8306
- (entryName)=>extraDataMap.get(entryName)
8310
+ (entryName)=>extraDataMap.get(entryName),
8311
+ ()=>HtmlPlugin
8307
8312
  ]), config.html) {
8308
8313
  let { crossorigin } = config.html;
8309
8314
  crossorigin && chain.output.crossOriginLoading(!0 === crossorigin ? 'anonymous' : crossorigin);
@@ -9034,7 +9039,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9034
9039
  options,
9035
9040
  'prefetch',
9036
9041
  HTMLCount,
9037
- isDev
9042
+ isDev,
9043
+ ()=>pluginHelper_getHTMLPlugin(config)
9038
9044
  ]);
9039
9045
  }
9040
9046
  if (preload) {
@@ -9046,7 +9052,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9046
9052
  options,
9047
9053
  'preload',
9048
9054
  HTMLCount,
9049
- isDev
9055
+ isDev,
9056
+ ()=>pluginHelper_getHTMLPlugin(config)
9050
9057
  ]);
9051
9058
  }
9052
9059
  });
@@ -9627,11 +9634,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9627
9634
  }
9628
9635
  !function() {
9629
9636
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9630
- logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.0\n`);
9637
+ logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.2\n`);
9631
9638
  }();
9632
9639
  try {
9633
9640
  let cli, devDescription, devCommand, buildCommand, previewCommand, inspectCommand;
9634
- (cli = ((name = "")=>new CAC(name))('rsbuild')).version("1.6.0"), 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)', {
9641
+ (cli = ((name = "")=>new CAC(name))('rsbuild')).version("1.6.2"), 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)', {
9635
9642
  default: 'auto'
9636
9643
  }).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', {
9637
9644
  type: [
@@ -9683,13 +9690,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9683
9690
  logger.error('Failed to inspect config.'), logger.error(err), process.exit(1);
9684
9691
  }
9685
9692
  }), cli.help((sections)=>{
9686
- for (let section of (sections.shift(), sections))'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title = color.cyan(section.title);
9693
+ for (let section of (sections.shift(), sections))'Usage' === section.title && (section.body = section.body.replace('$ rsbuild', color.yellow("$ rsbuild [command] [options]"))), 'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title = color.cyan(section.title);
9687
9694
  }), cli.parse();
9688
9695
  } catch (err) {
9689
9696
  logger.error('Failed to start Rsbuild CLI.'), logger.error(err);
9690
9697
  }
9691
9698
  }
9692
- let src_version = "1.6.0";
9699
+ let src_version = "1.6.2";
9693
9700
  })(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
9694
9701
  "PLUGIN_CSS_NAME",
9695
9702
  "PLUGIN_SWC_NAME",
package/dist/index.js CHANGED
@@ -1588,7 +1588,7 @@ __webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(p
1588
1588
  formatStats: ()=>formatStats,
1589
1589
  getChainUtils: ()=>getChainUtils,
1590
1590
  getConfigUtils: ()=>getConfigUtils,
1591
- getHTMLPlugin: ()=>getHTMLPlugin,
1591
+ getHTMLPlugin: ()=>pluginHelper_getHTMLPlugin,
1592
1592
  getRsbuildStats: ()=>getRsbuildStats,
1593
1593
  initRsbuildConfig: ()=>initRsbuildConfig,
1594
1594
  inspectConfig: ()=>inspectConfig_inspectConfig,
@@ -2700,7 +2700,7 @@ class src_class extends ChainedMap {
2700
2700
  }
2701
2701
  let setNodeEnv = (env)=>{
2702
2702
  process.env.NODE_ENV = env;
2703
- }, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && Object.getPrototypeOf(obj) === objectPrototype, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
2703
+ }, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, getProto1 = Object.getPrototypeOf, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && getProto1(obj) === objectPrototype, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
2704
2704
  arr
2705
2705
  ], cloneDeep = (value)=>null == value ? value : cjs_default()({}, value, {
2706
2706
  isMergeableObject: isPlainObject
@@ -3269,7 +3269,7 @@ async function emptyDir(dir, keep = [], checkExists = !0) {
3269
3269
  logger.debug(`failed to empty dir: ${dir}`), logger.debug(err);
3270
3270
  }
3271
3271
  }
3272
- let OVERRIDE_PATHS = [
3272
+ let OVERRIDE_PATHS = new Set([
3273
3273
  'performance.removeConsole',
3274
3274
  'output.inlineScripts',
3275
3275
  'output.inlineStyles',
@@ -3281,26 +3281,32 @@ let OVERRIDE_PATHS = [
3281
3281
  'resolve.conditionNames',
3282
3282
  'resolve.mainFields',
3283
3283
  'provider'
3284
- ], merge = (x, y, path = '')=>{
3284
+ ]), merge = (x, y, path = '')=>{
3285
3285
  if (((key)=>{
3286
3286
  if (key.startsWith('environments.')) {
3287
3287
  let realKey = key.split('.').slice(2).join('.');
3288
- return OVERRIDE_PATHS.includes(realKey);
3288
+ return OVERRIDE_PATHS.has(realKey);
3289
3289
  }
3290
- return OVERRIDE_PATHS.includes(key) || key.startsWith('output.filename.');
3290
+ return OVERRIDE_PATHS.has(key) || key.startsWith('output.filename.');
3291
3291
  })(path)) return y ?? x;
3292
3292
  if (void 0 === x) return isPlainObject(y) ? cloneDeep(y) : y;
3293
3293
  if (void 0 === y) return isPlainObject(x) ? cloneDeep(x) : x;
3294
- if ('boolean' == typeof x || 'boolean' == typeof y) return y;
3295
- let pair = [
3296
- x,
3294
+ let typeX = typeof x, typeY = typeof y;
3295
+ if ('boolean' === typeX || 'boolean' === typeY) return y;
3296
+ let isArrayX = Array.isArray(x), isArrayY = Array.isArray(y);
3297
+ if (isArrayX && isArrayY) return x.concat(y);
3298
+ if (isArrayX) return [
3299
+ ...x,
3297
3300
  y
3298
3301
  ];
3299
- if (pair.some(Array.isArray)) return [
3300
- ...helpers_castArray(x),
3301
- ...helpers_castArray(y)
3302
+ if (isArrayY) return [
3303
+ x,
3304
+ ...y
3305
+ ];
3306
+ if ('function' === typeX || 'function' === typeY) return [
3307
+ x,
3308
+ y
3302
3309
  ];
3303
- if (pair.some(isFunction)) return pair;
3304
3310
  if (!isPlainObject(x) || !isPlainObject(y)) return y;
3305
3311
  let merged = {};
3306
3312
  for (let key of new Set([
@@ -3312,22 +3318,20 @@ let OVERRIDE_PATHS = [
3312
3318
  }
3313
3319
  return merged;
3314
3320
  }, normalizeConfigStructure = (config)=>{
3315
- let { dev, output, ...rest } = config;
3321
+ let { dev, output } = config, normalizedConfig = {
3322
+ ...config
3323
+ };
3316
3324
  return output && (Array.isArray((output = {
3317
3325
  ...output
3318
3326
  }).copy) && (output.copy = {
3319
3327
  patterns: output.copy
3320
3328
  }), 'string' == typeof output.distPath && (output.distPath = {
3321
3329
  root: output.distPath
3322
- })), dev && (dev = {
3330
+ }), normalizedConfig.output = output), dev && ((dev = {
3323
3331
  ...dev
3324
3332
  }).watchFiles && !Array.isArray(dev.watchFiles) && (dev.watchFiles = [
3325
3333
  dev.watchFiles
3326
- ]), {
3327
- ...rest,
3328
- dev,
3329
- output
3330
- };
3334
+ ]), normalizedConfig.dev = dev), normalizedConfig;
3331
3335
  }, mergeRsbuildConfig = (...originalConfigs)=>{
3332
3336
  let configs = originalConfigs.map(normalizeConfigStructure);
3333
3337
  return 2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {});
@@ -3376,7 +3380,8 @@ let OVERRIDE_PATHS = [
3376
3380
  mountId: 'root',
3377
3381
  crossorigin: !1,
3378
3382
  outputStructure: 'flat',
3379
- scriptLoading: 'defer'
3383
+ scriptLoading: 'defer',
3384
+ implementation: 'js'
3380
3385
  },
3381
3386
  resolve: (swcHelpersPath || (swcHelpersPath = (0, external_node_path_.dirname)(defaultConfig_require.resolve('@swc/helpers/package.json'))), {
3382
3387
  alias: {
@@ -3679,7 +3684,7 @@ async function updateEnvironmentContext(context, configs) {
3679
3684
  async function createContext(options, userConfig) {
3680
3685
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
3681
3686
  return {
3682
- version: "1.6.0",
3687
+ version: "1.6.2",
3683
3688
  rootPath,
3684
3689
  distPath: '',
3685
3690
  cachePath,
@@ -3959,7 +3964,7 @@ let configChain_CHAIN_ID = {
3959
3964
  }
3960
3965
  }, setHTMLPlugin = (plugin)=>{
3961
3966
  plugin && (pluginHelper_htmlPlugin = plugin);
3962
- }, getHTMLPlugin = ()=>(pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = requireCompiledPackage('html-rspack-plugin')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
3967
+ }, pluginHelper_getHTMLPlugin = (config)=>config?.html.implementation === 'native' ? rspack_rspack.HtmlRspackPlugin : (pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = requireCompiledPackage('html-rspack-plugin')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
3963
3968
  cssExtractPlugin = plugin;
3964
3969
  };
3965
3970
  async function modifyRspackConfig(context, rspackConfig, chainUtils) {
@@ -4022,7 +4027,7 @@ function getChainUtils(target, environment) {
4022
4027
  isServer: 'node' === target,
4023
4028
  isWebWorker: 'web-worker' === target,
4024
4029
  CHAIN_ID: configChain_CHAIN_ID,
4025
- HtmlPlugin: getHTMLPlugin()
4030
+ HtmlPlugin: pluginHelper_getHTMLPlugin(environment.config)
4026
4031
  };
4027
4032
  }
4028
4033
  async function generateRspackConfig({ target, context, environment }) {
@@ -4083,7 +4088,7 @@ let createEnvironmentNotFoundError = (environments = [])=>{
4083
4088
  };
4084
4089
  async function initRsbuildConfig({ context, pluginManager }) {
4085
4090
  var config, rootPath;
4086
- let distPaths;
4091
+ let defaultConfig, distPaths;
4087
4092
  if (context.normalizedConfig) return context.normalizedConfig;
4088
4093
  await initPlugins({
4089
4094
  context,
@@ -4110,14 +4115,11 @@ async function initRsbuildConfig({ context, pluginManager }) {
4110
4115
  return Array.isArray(publicDir) ? publicDir.map((options)=>mergeWithDefault(options)) : [
4111
4116
  mergeWithDefault(publicDir)
4112
4117
  ];
4113
- })(rootPath, config.server.publicDir), mergeRsbuildConfig({
4114
- ...createDefaultConfig(),
4115
- mode: (()=>{
4116
- if (config.mode) return config.mode;
4117
- let nodeEnv = process.env.NODE_ENV || '';
4118
- return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none';
4119
- })()
4120
- }, config)), environments = {}, mergedEnvironments = ((normalizedConfig, rootPath, specifiedEnvironments)=>{
4118
+ })(rootPath, config.server.publicDir), (defaultConfig = createDefaultConfig()).mode = (()=>{
4119
+ if (config.mode) return config.mode;
4120
+ let nodeEnv = process.env.NODE_ENV || '';
4121
+ return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none';
4122
+ })(), mergeRsbuildConfig(defaultConfig, config)), environments = {}, mergedEnvironments = ((normalizedConfig, rootPath, specifiedEnvironments)=>{
4121
4123
  let defaultEntry, { environments, dev, server: _server, provider: _provider, ...baseConfig } = normalizedConfig, isEnvironmentEnabled = (name)=>!specifiedEnvironments || specifiedEnvironments.includes(name), applyEnvironmentDefaultConfig = (config)=>{
4122
4124
  let entryFile;
4123
4125
  config.source.entry && 0 !== Object.keys(config.source.entry).length || (config.source.entry = (defaultEntry || (defaultEntry = (entryFile = findExists([
@@ -4684,8 +4686,9 @@ let entryNameSymbol = Symbol('entryName'), VOID_TAGS = [
4684
4686
  class RsbuildHtmlPlugin {
4685
4687
  name;
4686
4688
  getExtraData;
4687
- constructor(getExtraData){
4688
- this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
4689
+ getHTMLPlugin;
4690
+ constructor(getExtraData, getHTMLPlugin){
4691
+ this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData, this.getHTMLPlugin = getHTMLPlugin;
4689
4692
  }
4690
4693
  apply(compiler) {
4691
4694
  let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
@@ -4727,7 +4730,7 @@ class RsbuildHtmlPlugin {
4727
4730
  if (entryName) return this.getExtraData(entryName);
4728
4731
  };
4729
4732
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
4730
- let hooks = getHTMLPlugin().getCompilationHooks(compilation);
4733
+ let hooks = this.getHTMLPlugin().getCompilationHooks(compilation);
4731
4734
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
4732
4735
  let extraData = getExtraDataByPlugin(data.plugin);
4733
4736
  if (!extraData) return data;
@@ -5174,15 +5177,16 @@ class HtmlResourceHintsPlugin {
5174
5177
  type;
5175
5178
  HTMLCount;
5176
5179
  isDev;
5177
- constructor(options, type, HTMLCount, isDev){
5180
+ getHTMLPlugin;
5181
+ constructor(options, type, HTMLCount, isDev, getHTMLPlugin){
5178
5182
  this.options = {
5179
5183
  ...HtmlResourceHintsPlugin_defaultOptions,
5180
5184
  ...options
5181
- }, this.type = type, this.HTMLCount = HTMLCount, this.isDev = isDev;
5185
+ }, this.type = type, this.HTMLCount = HTMLCount, this.isDev = isDev, this.getHTMLPlugin = getHTMLPlugin;
5182
5186
  }
5183
5187
  apply(compiler) {
5184
5188
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
5185
- let pluginHooks = getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
5189
+ let pluginHooks = this.getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
5186
5190
  pluginHooks.beforeAssetTagGeneration.tap(pluginName, (data)=>(this.resourceHints = function(options, type, compilation, data, HTMLCount, isDev) {
5187
5191
  let extractedChunks = function(compilation, includeType) {
5188
5192
  let chunks = [
@@ -7699,16 +7703,16 @@ async function createRsbuild(options = {}) {
7699
7703
  {
7700
7704
  name: 'rsbuild:source-map',
7701
7705
  setup (api) {
7702
- let sourceMapFilenameTemplate = ({ absoluteResourcePath })=>absoluteResourcePath, enableCssSourceMap = (config)=>{
7706
+ let DEFAULT_SOURCE_MAP_TEMPLATE = '[absolute-resource-path]', enableCssSourceMap = (config)=>{
7703
7707
  let { sourceMap } = config.output;
7704
7708
  return 'object' == typeof sourceMap && sourceMap.css;
7705
7709
  };
7706
- api.modifyBundlerChain((chain, { bundler, environment })=>{
7710
+ api.modifyBundlerChain((chain, { bundler, environment, isDev, target })=>{
7707
7711
  let { config } = environment, devtool = ((config)=>{
7708
7712
  let { sourceMap } = config.output, isProd = 'production' === config.mode;
7709
7713
  return !1 !== sourceMap && (!0 === sourceMap ? isProd ? 'source-map' : 'cheap-module-source-map' : void 0 === sourceMap.js ? !isProd && 'cheap-module-source-map' : sourceMap.js);
7710
7714
  })(config);
7711
- chain.devtool(devtool).output.devtoolModuleFilenameTemplate(sourceMapFilenameTemplate), !devtool && enableCssSourceMap(config) && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
7715
+ chain.devtool(devtool), isDev && 'web' === target ? chain.output.devtoolModuleFilenameTemplate((info)=>toPosixPath(info.absoluteResourcePath)) : chain.output.devtoolModuleFilenameTemplate(DEFAULT_SOURCE_MAP_TEMPLATE), !devtool && enableCssSourceMap(config) && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
7712
7716
  {
7713
7717
  test: /\.css$/,
7714
7718
  filename: '[file].map[query]'
@@ -7717,7 +7721,7 @@ async function createRsbuild(options = {}) {
7717
7721
  }), api.processAssets({
7718
7722
  stage: 'optimize-transfer'
7719
7723
  }, ({ assets, compilation, sources, environment })=>{
7720
- if (!compilation.options.devtool && !enableCssSourceMap(environment.config) || compilation.outputOptions.devtoolModuleFilenameTemplate !== sourceMapFilenameTemplate) return;
7724
+ if (!compilation.options.devtool && !enableCssSourceMap(environment.config) || compilation.outputOptions.devtoolModuleFilenameTemplate !== DEFAULT_SOURCE_MAP_TEMPLATE) return;
7721
7725
  let { distPath } = environment;
7722
7726
  for (let [filename, asset] of Object.entries(assets)){
7723
7727
  let map;
@@ -8140,7 +8144,8 @@ async function createRsbuild(options = {}) {
8140
8144
  }
8141
8145
  ]);
8142
8146
  }), chain.plugin('rsbuild-html-plugin').use(RsbuildHtmlPlugin, [
8143
- (entryName)=>extraDataMap.get(entryName)
8147
+ (entryName)=>extraDataMap.get(entryName),
8148
+ ()=>HtmlPlugin
8144
8149
  ]), config.html) {
8145
8150
  let { crossorigin } = config.html;
8146
8151
  crossorigin && chain.output.crossOriginLoading(!0 === crossorigin ? 'anonymous' : crossorigin);
@@ -8870,7 +8875,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
8870
8875
  options,
8871
8876
  'prefetch',
8872
8877
  HTMLCount,
8873
- isDev
8878
+ isDev,
8879
+ ()=>pluginHelper_getHTMLPlugin(config)
8874
8880
  ]);
8875
8881
  }
8876
8882
  if (preload) {
@@ -8882,7 +8888,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
8882
8888
  options,
8883
8889
  'preload',
8884
8890
  HTMLCount,
8885
- isDev
8891
+ isDev,
8892
+ ()=>pluginHelper_getHTMLPlugin(config)
8886
8893
  ]);
8887
8894
  }
8888
8895
  });
@@ -9462,11 +9469,11 @@ function runCLI() {
9462
9469
  }
9463
9470
  !function() {
9464
9471
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9465
- logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.0\n`);
9472
+ logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.6.2\n`);
9466
9473
  }();
9467
9474
  try {
9468
9475
  let cli, devDescription, devCommand, buildCommand, previewCommand, inspectCommand;
9469
- (cli = ((name = "")=>new CAC(name))('rsbuild')).version("1.6.0"), 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)', {
9476
+ (cli = ((name = "")=>new CAC(name))('rsbuild')).version("1.6.2"), 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)', {
9470
9477
  default: 'auto'
9471
9478
  }).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', {
9472
9479
  type: [
@@ -9518,13 +9525,13 @@ function runCLI() {
9518
9525
  logger.error('Failed to inspect config.'), logger.error(err), process.exit(1);
9519
9526
  }
9520
9527
  }), cli.help((sections)=>{
9521
- for (let section of (sections.shift(), sections))'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title = color.cyan(section.title);
9528
+ for (let section of (sections.shift(), sections))'Usage' === section.title && (section.body = section.body.replace('$ rsbuild', color.yellow("$ rsbuild [command] [options]"))), 'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title = color.cyan(section.title);
9522
9529
  }), cli.parse();
9523
9530
  } catch (err) {
9524
9531
  logger.error('Failed to start Rsbuild CLI.'), logger.error(err);
9525
9532
  }
9526
9533
  }
9527
- let src_version = "1.6.0";
9534
+ let src_version = "1.6.2";
9528
9535
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
9529
9536
  import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
9530
9537
  import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
@@ -5,7 +5,7 @@ let constants_dirname = dirname(fileURLToPath(import.meta.url));
5
5
  process.platform, join(constants_dirname), join(constants_dirname, '../static');
6
6
  let COMPILED_PATH = join(constants_dirname, '../compiled'), vendors_require = createRequire(import.meta.url), requireCompiledPackage = (name)=>vendors_require(`${COMPILED_PATH}/${name}/index.js`);
7
7
  requireCompiledPackage('picocolors');
8
- let transformLoader = async function(source, map) {
8
+ let loader_transformLoader = async function(source, map) {
9
9
  let callback = this.async(), bypass = ()=>{
10
10
  callback(null, source, map);
11
11
  }, { id: transformId, getEnvironment } = this.getOptions();
@@ -39,4 +39,4 @@ let transformLoader = async function(source, map) {
39
39
  error instanceof Error ? callback(error) : callback(Error(String(error)));
40
40
  }
41
41
  };
42
- export { transformLoader as default };
42
+ export { loader_transformLoader as default };
@@ -2,11 +2,11 @@
2
2
  * This file is used to get/set the global instance for html-plugin and css-extract plugin.
3
3
  */
4
4
  import { rspack } from './rspack';
5
- import type { HtmlRspackPlugin } from './types';
5
+ import type { HtmlRspackPlugin, NormalizedEnvironmentConfig } from './types';
6
6
  /**
7
7
  * This method is used to override the Rsbuild default html-plugin (html-rspack-plugin).
8
8
  */
9
9
  export declare const setHTMLPlugin: (plugin: typeof HtmlRspackPlugin) => void;
10
- export declare const getHTMLPlugin: () => typeof HtmlRspackPlugin;
10
+ export declare const getHTMLPlugin: (config?: NormalizedEnvironmentConfig) => typeof HtmlRspackPlugin;
11
11
  export declare const setCssExtractPlugin: (plugin: unknown) => void;
12
12
  export declare const getCssExtractPlugin: () => typeof rspack.CssExtractRspackPlugin;
@@ -31,7 +31,8 @@ export declare const hasTitle: (html?: string) => boolean;
31
31
  export declare class RsbuildHtmlPlugin {
32
32
  readonly name: string;
33
33
  readonly getExtraData: (entryName: string) => HtmlExtraData | undefined;
34
- constructor(getExtraData: (entryName: string) => HtmlExtraData | undefined);
34
+ readonly getHTMLPlugin: () => typeof HtmlRspackPlugin;
35
+ constructor(getExtraData: (entryName: string) => HtmlExtraData | undefined, getHTMLPlugin: () => typeof HtmlRspackPlugin);
35
36
  apply(compiler: Compiler): void;
36
37
  }
37
38
  export {};
@@ -25,7 +25,8 @@ export declare class HtmlResourceHintsPlugin implements RspackPluginInstance {
25
25
  type: LinkType;
26
26
  HTMLCount: number;
27
27
  isDev: boolean;
28
- constructor(options: ResourceHintsOptions, type: LinkType, HTMLCount: number, isDev: boolean);
28
+ getHTMLPlugin: () => typeof HtmlRspackPlugin;
29
+ constructor(options: ResourceHintsOptions, type: LinkType, HTMLCount: number, isDev: boolean, getHTMLPlugin: () => typeof HtmlRspackPlugin);
29
30
  apply(compiler: Compiler): void;
30
31
  }
31
32
  export {};
@@ -1,2 +1,2 @@
1
- import type { SourceTextModule } from 'node:vm';
2
- export declare const asModule: (something: Record<string, any>, context: Record<string, any>, unlinked?: boolean) => Promise<SourceTextModule>;
1
+ import type { Module, SyntheticModule } from 'node:vm';
2
+ export declare const asModule: (something: Record<string, any>, context: Record<string, any>, unlinked?: boolean) => Promise<Module | SyntheticModule>;
@@ -1281,6 +1281,7 @@ export type AppIcon = {
1281
1281
  */
1282
1282
  filename?: string;
1283
1283
  };
1284
+ type HtmlImplementation = 'js' | 'native';
1284
1285
  export interface HtmlConfig {
1285
1286
  /**
1286
1287
  * Configure the `<meta>` tag of the HTML.
@@ -1366,6 +1367,19 @@ export interface HtmlConfig {
1366
1367
  * @default 'defer'. If `output.module` is enabled, the value is always `'module'`.
1367
1368
  */
1368
1369
  scriptLoading?: ScriptLoading;
1370
+ /**
1371
+ * Specifies which implementation to use for generating HTML files.
1372
+ *
1373
+ * - `'js'` (default) - Use the JavaScript-based `html-rspack-plugin`.
1374
+ * - `'native'` - Use Rspack's built-in `HtmlRspackPlugin` implemented in Rust.
1375
+ *
1376
+ * This option is experimental and may affect the available options in `tools.htmlPlugin`,
1377
+ * since the two implementations are not fully compatible.
1378
+ *
1379
+ * @default 'js'
1380
+ * @experimental
1381
+ */
1382
+ implementation?: HtmlImplementation;
1369
1383
  }
1370
1384
  export type NormalizedHtmlConfig = HtmlConfig & {
1371
1385
  meta: ChainedHtmlOption<MetaOptions>;
@@ -1375,6 +1389,7 @@ export type NormalizedHtmlConfig = HtmlConfig & {
1375
1389
  crossorigin: boolean | CrossOrigin;
1376
1390
  outputStructure: OutputStructure;
1377
1391
  scriptLoading: ScriptLoading;
1392
+ implementation: HtmlImplementation;
1378
1393
  };
1379
1394
  export type ProgressBarConfig = {
1380
1395
  id?: string;
@@ -209,11 +209,12 @@ type TransformResult = string | {
209
209
  code: string;
210
210
  map?: string | Rspack.RawSourceMap | null;
211
211
  };
212
- export type TransformContext = {
212
+ export type TransformContext<Raw extends boolean = false> = {
213
213
  /**
214
214
  * The code of the module.
215
+ * When `raw` is true, this will be a Buffer instead of a string.
215
216
  */
216
- code: string;
217
+ code: Raw extends true ? Buffer : string;
217
218
  /**
218
219
  * The directory path of the currently processed module,
219
220
  * which changes with the location of each processed module.
@@ -274,7 +275,7 @@ export type TransformContext = {
274
275
  */
275
276
  resolve: Rspack.LoaderContext['resolve'];
276
277
  };
277
- export type TransformHandler = (context: TransformContext) => MaybePromise<TransformResult>;
278
+ export type TransformHandler<Raw extends boolean = false> = (context: TransformContext<Raw>) => MaybePromise<TransformResult>;
278
279
  export type TransformDescriptor = {
279
280
  /**
280
281
  * Include modules that match the test assertion, the same as `rule.test`
@@ -349,7 +350,7 @@ export type TransformDescriptor = {
349
350
  */
350
351
  order?: HookOrder;
351
352
  };
352
- export type TransformHook = (descriptor: TransformDescriptor, handler: TransformHandler) => void;
353
+ export type TransformHook = <T extends TransformDescriptor>(descriptor: T, handler: TransformHandler<T['raw'] extends true ? true : false>) => void;
353
354
  export type ProcessAssetsStage = 'additional' | 'pre-process' | 'derived' | 'additions' | 'none' | 'optimize' | 'optimize-count' | 'optimize-compatibility' | 'optimize-size' | 'dev-tooling' | 'optimize-inline' | 'summarize' | 'optimize-hash' | 'optimize-transfer' | 'analyse' | 'report';
354
355
  export type ProcessAssetsDescriptor = {
355
356
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.6.0",
49
+ "@rspack/core": "1.6.1",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.17",
52
52
  "core-js": "~3.46.0",
@@ -55,10 +55,10 @@
55
55
  "devDependencies": {
56
56
  "@jridgewell/remapping": "^2.3.5",
57
57
  "@jridgewell/trace-mapping": "^0.3.31",
58
- "@rslib/core": "0.16.1",
58
+ "@rslib/core": "0.17.0",
59
59
  "@types/connect": "3.4.38",
60
60
  "@types/cors": "^2.8.19",
61
- "@types/node": "^22.18.12",
61
+ "@types/node": "^24.9.2",
62
62
  "@types/on-finished": "2.3.5",
63
63
  "@types/range-parser": "^1.2.7",
64
64
  "@types/webpack-bundle-analyzer": "4.7.0",