@rsbuild/core 1.3.17 → 1.3.18

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.
package/dist/index.cjs CHANGED
@@ -1032,6 +1032,7 @@ for(var __webpack_i__ in (()=>{
1032
1032
  "use strict";
1033
1033
  let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin;
1034
1034
  __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
1035
+ loadEnv: ()=>loadEnv,
1035
1036
  logger: ()=>rslog_index_js_namespaceObject.logger,
1036
1037
  createRsbuild: ()=>createRsbuild,
1037
1038
  rspack: ()=>core_namespaceObject.rspack,
@@ -1041,9 +1042,9 @@ for(var __webpack_i__ in (()=>{
1041
1042
  version: ()=>src_version,
1042
1043
  PLUGIN_SWC_NAME: ()=>PLUGIN_SWC_NAME,
1043
1044
  PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
1044
- loadConfig: ()=>config_loadConfig,
1045
1045
  ensureAssetPrefix: ()=>ensureAssetPrefix,
1046
- loadEnv: ()=>loadEnv
1046
+ loadConfig: ()=>config_loadConfig,
1047
+ defaultAllowedOrigins: ()=>defaultAllowedOrigins
1047
1048
  });
1048
1049
  var provider_helpers_namespaceObject = {};
1049
1050
  __webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(provider_helpers_namespaceObject, {
@@ -1593,7 +1594,7 @@ for(var __webpack_i__ in (()=>{
1593
1594
  overlay: !0,
1594
1595
  reconnect: 100
1595
1596
  }
1596
- }), LOCAL_ORIGINS_REGEX = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, getDefaultServerConfig = ()=>({
1597
+ }), defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, getDefaultServerConfig = ()=>({
1597
1598
  port: 3000,
1598
1599
  host: DEFAULT_DEV_HOST,
1599
1600
  open: !1,
@@ -1603,7 +1604,7 @@ for(var __webpack_i__ in (()=>{
1603
1604
  printUrls: !0,
1604
1605
  strictPort: !1,
1605
1606
  cors: {
1606
- origin: LOCAL_ORIGINS_REGEX
1607
+ origin: defaultAllowedOrigins
1607
1608
  },
1608
1609
  middlewareMode: !1
1609
1610
  }), getDefaultSourceConfig = ()=>({
@@ -2256,13 +2257,14 @@ for(var __webpack_i__ in (()=>{
2256
2257
  }
2257
2258
  }
2258
2259
  async function createContext(options, userConfig) {
2259
- 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;
2260
+ 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, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
2260
2261
  return {
2261
- version: "1.3.17",
2262
+ version: "1.3.18",
2262
2263
  rootPath,
2263
2264
  distPath: '',
2264
2265
  cachePath,
2265
- bundlerType: userConfig.provider ? 'webpack' : 'rspack',
2266
+ callerName: options.callerName,
2267
+ bundlerType,
2266
2268
  environments: {},
2267
2269
  hooks: {
2268
2270
  onExit: createAsyncHook(),
@@ -3301,15 +3303,18 @@ for(var __webpack_i__ in (()=>{
3301
3303
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
3302
3304
  let hooks = getHTMLPlugin().getCompilationHooks(compilation);
3303
3305
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
3304
- var _data_plugin_options, _data_plugin_options1;
3305
- let entryName = null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.entryName;
3306
- if (!entryName) return data;
3307
- let { headTags, bodyTags } = data, { favicon, tagConfig, templateContent } = this.options[entryName];
3308
- hasTitle(templateContent) || addTitleTag(headTags, null == (_data_plugin_options1 = data.plugin.options) ? void 0 : _data_plugin_options1.title), favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
3306
+ let extraData = this.getExtraData(data.plugin);
3307
+ if (!extraData) return data;
3308
+ let { headTags, bodyTags } = data, { favicon, context, tagConfig, entryName, environment, templateContent } = extraData;
3309
+ if (!hasTitle(templateContent)) {
3310
+ var _data_plugin_options;
3311
+ addTitleTag(headTags, null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.title);
3312
+ }
3313
+ favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
3309
3314
  let tags = {
3310
3315
  headTags: headTags.map(formatBasicTag),
3311
3316
  bodyTags: bodyTags.map(formatBasicTag)
3312
- }, context = this.getContext(), environment = this.getEnvironment(), [modified] = await context.hooks.modifyHTMLTags.callChain({
3317
+ }, [modified] = await context.hooks.modifyHTMLTags.callChain({
3313
3318
  environment: environment.name,
3314
3319
  args: [
3315
3320
  tags,
@@ -3327,7 +3332,9 @@ for(var __webpack_i__ in (()=>{
3327
3332
  bodyTags: modified.bodyTags.map(fromBasicTag)
3328
3333
  }), tagConfig && applyTagConfig(data, tagConfig, compilation.hash ?? '', entryName), data;
3329
3334
  }), hooks.beforeEmit.tapPromise(this.name, async (data)=>{
3330
- let context = this.getContext(), environment = this.getEnvironment(), [modified] = await context.hooks.modifyHTML.callChain({
3335
+ let extraData = this.getExtraData(data.plugin);
3336
+ if (!extraData) return data;
3337
+ let { context, environment } = extraData, [modified] = await context.hooks.modifyHTML.callChain({
3331
3338
  environment: environment.name,
3332
3339
  args: [
3333
3340
  data.html,
@@ -3346,8 +3353,8 @@ for(var __webpack_i__ in (()=>{
3346
3353
  });
3347
3354
  });
3348
3355
  }
3349
- constructor(options, getEnvironment, getContext){
3350
- RsbuildHtmlPlugin_define_property(this, "name", void 0), RsbuildHtmlPlugin_define_property(this, "getEnvironment", void 0), RsbuildHtmlPlugin_define_property(this, "options", void 0), RsbuildHtmlPlugin_define_property(this, "getContext", void 0), this.name = 'RsbuildHtmlPlugin', this.options = options, this.getEnvironment = getEnvironment, this.getContext = getContext;
3356
+ constructor(getExtraData){
3357
+ RsbuildHtmlPlugin_define_property(this, "name", void 0), RsbuildHtmlPlugin_define_property(this, "getExtraData", void 0), this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
3351
3358
  }
3352
3359
  }
3353
3360
  let getDefaultTemplateContent = (mountId)=>`<!doctype html><html><head></head><body><div id="${mountId}"></div></body></html>`, existTemplatePath = new Set();
@@ -3388,7 +3395,7 @@ for(var __webpack_i__ in (()=>{
3388
3395
  api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID, environment })=>{
3389
3396
  let { config, htmlPaths } = environment;
3390
3397
  if (0 === Object.keys(htmlPaths).length) return;
3391
- let assetPrefix = getPublicPathFromChain(chain, !1), entries = chain.entryPoints.entries() || {}, entryNames = Object.keys(entries).filter((entryName)=>!!htmlPaths[entryName]), htmlInfoMap = {}, finalOptions = await Promise.all(entryNames.map(async (entryName)=>{
3398
+ let assetPrefix = getPublicPathFromChain(chain, !1), entries = chain.entryPoints.entries() || {}, entryNames = Object.keys(entries).filter((entryName)=>!!htmlPaths[entryName]), extraDataList = [], finalOptions = await Promise.all(entryNames.map(async (entryName)=>{
3392
3399
  var entryName1, entryName2, config1, assetPrefix1, entryName3, entryName4;
3393
3400
  let entryValue = entries[entryName].values(), chunks = function(entryName, entryValue) {
3394
3401
  let chunks = [
@@ -3447,10 +3454,14 @@ for(var __webpack_i__ in (()=>{
3447
3454
  scriptLoading: config.html.scriptLoading
3448
3455
  };
3449
3456
  templatePath && (pluginOptions.template = templatePath), chunks.length > 1 && (pluginOptions.chunksSortMode = 'manual');
3450
- let htmlInfo = {};
3451
- htmlInfoMap[entryName] = htmlInfo, templateContent && (htmlInfo.templateContent = templateContent);
3457
+ let extraData = {
3458
+ entryName,
3459
+ context,
3460
+ environment
3461
+ };
3462
+ extraDataList.push(extraData), templateContent && (extraData.templateContent = templateContent);
3452
3463
  let tagConfig = getTagConfig(environment.config);
3453
- tagConfig && (htmlInfo.tagConfig = tagConfig), entryName3 = entryName, pluginOptions.title = reduceConfigsMergeContext({
3464
+ tagConfig && (extraData.tagConfig = tagConfig), entryName3 = entryName, pluginOptions.title = reduceConfigsMergeContext({
3454
3465
  initial: '',
3455
3466
  config: config.html.title,
3456
3467
  ctx: {
@@ -3464,7 +3475,7 @@ for(var __webpack_i__ in (()=>{
3464
3475
  entryName: entryName4
3465
3476
  }
3466
3477
  }));
3467
- favicon && (htmlInfo.favicon = favicon);
3478
+ favicon && (extraData.favicon = favicon);
3468
3479
  let finalOptions = reduceConfigsWithContext({
3469
3480
  initial: pluginOptions,
3470
3481
  config: 'boolean' == typeof config.tools.htmlPlugin ? {} : config.tools.htmlPlugin,
@@ -3474,15 +3485,12 @@ for(var __webpack_i__ in (()=>{
3474
3485
  }
3475
3486
  });
3476
3487
  return finalOptions.template || finalOptions.templateContent || (pluginOptions.template = '', pluginOptions.templateContent = templateContent), finalOptions;
3477
- }));
3488
+ })), extraDataMap = new WeakMap();
3478
3489
  if (entryNames.forEach((entryName, index)=>{
3479
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [
3480
- finalOptions[index]
3481
- ]);
3490
+ let pluginInstance = new HtmlPlugin(finalOptions[index]), extraData = extraDataList.find((item)=>item.entryName === entryName);
3491
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(pluginInstance), extraData && extraDataMap.set(pluginInstance, extraData);
3482
3492
  }), chain.plugin('rsbuild-html-plugin').use(RsbuildHtmlPlugin, [
3483
- htmlInfoMap,
3484
- ()=>environment,
3485
- ()=>context
3493
+ (pluginInstance)=>extraDataMap.get(pluginInstance)
3486
3494
  ]), config.html) {
3487
3495
  let { crossorigin } = config.html;
3488
3496
  crossorigin && chain.output.crossOriginLoading(!0 === crossorigin ? 'anonymous' : crossorigin);
@@ -4392,33 +4400,25 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4392
4400
  }
4393
4401
  });
4394
4402
  }
4395
- }), external_node_inspector_namespaceObject = require("node:inspector");
4396
- var external_node_inspector_default = __webpack_require__.n(external_node_inspector_namespaceObject);
4397
- let stopProfiler = (output, profileSession)=>{
4398
- profileSession && profileSession.post('Profiler.stop', (error, param)=>{
4399
- if (error) return void rslog_index_js_namespaceObject.logger.error('Failed to generate JavaScript CPU profile:', error);
4400
- external_node_fs_default().writeFileSync(output, JSON.stringify(param.profile));
4401
- });
4402
- }, pluginRspackProfile = ()=>({
4403
+ }), pluginRspackProfile = ()=>({
4403
4404
  name: 'rsbuild:rspack-profile',
4404
4405
  async setup (api) {
4405
4406
  var _process_env_RSPACK_PROFILE;
4406
- let profileSession;
4407
4407
  if ('webpack' === api.context.bundlerType) return;
4408
4408
  let RSPACK_PROFILE = null == (_process_env_RSPACK_PROFILE = process.env.RSPACK_PROFILE) ? void 0 : _process_env_RSPACK_PROFILE.toUpperCase();
4409
4409
  if (!RSPACK_PROFILE) return;
4410
- let timestamp = Date.now(), profileDirName = `rspack-profile-${timestamp}`, enableProfileTrace = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('TRACE'), enableCPUProfile = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('CPU'), onStart = async ()=>{
4410
+ let timestamp = Date.now(), profileDirName = `rspack-profile-${timestamp}`, enableProfileTrace = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('TRACE'), onStart = async ()=>{
4411
4411
  let profileDir = external_node_path_default().join(api.context.distPath, profileDirName), traceFilePath = external_node_path_default().join(profileDir, 'trace.json');
4412
4412
  await isFileExists(profileDir) || await external_node_fs_default().promises.mkdir(profileDir, {
4413
4413
  recursive: !0
4414
- }), enableProfileTrace && core_default().experiments.globalTrace.register('trace', 'chrome', traceFilePath), enableCPUProfile && ((profileSession = new (external_node_inspector_default()).Session()).connect(), profileSession.post('Profiler.enable'), profileSession.post('Profiler.start'));
4414
+ }), enableProfileTrace && core_default().experiments.globalTrace.register('trace', 'chrome', traceFilePath);
4415
4415
  };
4416
4416
  api.onBeforeBuild(({ isFirstCompile })=>{
4417
4417
  isFirstCompile && onStart();
4418
4418
  }), api.onBeforeStartDevServer(onStart), api.onExit(()=>{
4419
4419
  enableProfileTrace && core_default().experiments.globalTrace.cleanup();
4420
4420
  let profileDir = external_node_path_default().join(api.context.distPath, profileDirName);
4421
- stopProfiler(external_node_path_default().join(profileDir, 'jscpuprofile.json'), profileSession), rslog_index_js_namespaceObject.logger.info(`profile files saved to ${index_js_default().cyan(profileDir)}`);
4421
+ rslog_index_js_namespaceObject.logger.info(`profile file saved to ${index_js_default().cyan(profileDir)}`);
4422
4422
  });
4423
4423
  }
4424
4424
  }), pluginServer = ()=>({
@@ -6816,9 +6816,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6816
6816
  setup (api) {
6817
6817
  'webpack' !== api.context.bundlerType && (api.modifyRsbuildConfig((config)=>{
6818
6818
  let { moduleFederation } = config;
6819
- if (api.isPluginExists('rsbuild:module-federation-enhanced') && (config.server ||= {}, config.server.cors = !0), (null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
6820
- var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
6821
- config.dev ||= {}, config.server ||= {}, config.server.cors = !0, (null == (_config_server = config.server) ? void 0 : _config_server.port) && !(null == (_config_dev_client = config.dev.client) ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null == (_originalConfig_dev = api.getRsbuildConfig('original').dev) ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null == (_config_server1 = config.server) ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
6819
+ if ((null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
6820
+ var _userConfig_server, _config_server, _config_dev_client, _userConfig_dev, _config_server1;
6821
+ let userConfig = api.getRsbuildConfig('original');
6822
+ config.dev ||= {}, config.server ||= {}, (null == (_userConfig_server = userConfig.server) ? void 0 : _userConfig_server.cors) === void 0 && (config.server.cors = !0), (null == (_config_server = config.server) ? void 0 : _config_server.port) && !(null == (_config_dev_client = config.dev.client) ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null == (_userConfig_dev = userConfig.dev) ? void 0 : _userConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null == (_config_server1 = config.server) ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
6822
6823
  }
6823
6824
  }), api.modifyEnvironmentConfig((config)=>{
6824
6825
  var _config_moduleFederation, _config_performance_chunkSplit, _config_performance;
@@ -6870,6 +6871,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6870
6871
  }
6871
6872
  let resolvedOptions = {
6872
6873
  cwd: process.cwd(),
6874
+ callerName: 'rsbuild',
6873
6875
  ...options,
6874
6876
  rsbuildConfig: config
6875
6877
  }, pluginManager = (plugins = [], {
@@ -6932,6 +6934,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6932
6934
  'distPath',
6933
6935
  'devServer',
6934
6936
  'cachePath',
6937
+ 'callerName',
6935
6938
  'bundlerType'
6936
6939
  ];
6937
6940
  return new Proxy(context, {
@@ -7527,11 +7530,11 @@ ${section.body}` : section.body).join("\n\n"));
7527
7530
  }
7528
7531
  process.title = 'rsbuild-node';
7529
7532
  let { npm_execpath } = process.env;
7530
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.17\n`);
7533
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.18\n`);
7531
7534
  try {
7532
7535
  !function() {
7533
7536
  let cli = cac_dist('rsbuild');
7534
- cli.help(), cli.version("1.3.17"), applyCommonOptions(cli);
7537
+ cli.help(), cli.version("1.3.18"), applyCommonOptions(cli);
7535
7538
  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');
7536
7539
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7537
7540
  try {
@@ -7582,11 +7585,12 @@ ${section.body}` : section.body).join("\n\n"));
7582
7585
  rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
7583
7586
  }
7584
7587
  }
7585
- let src_version = "1.3.17";
7586
- })(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, 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 === [
7588
+ let src_version = "1.3.18";
7589
+ })(), 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 === [
7587
7590
  "PLUGIN_CSS_NAME",
7588
7591
  "PLUGIN_SWC_NAME",
7589
7592
  "createRsbuild",
7593
+ "defaultAllowedOrigins",
7590
7594
  "defineConfig",
7591
7595
  "ensureAssetPrefix",
7592
7596
  "loadConfig",
package/dist/index.js CHANGED
@@ -21,7 +21,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
21
21
  import * as __WEBPACK_EXTERNAL_MODULE_node_zlib_a5bb16fc__ from "node:zlib";
22
22
  import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
23
23
  import * as __WEBPACK_EXTERNAL_MODULE_node_net_0373943e__ from "node:net";
24
- import * as __WEBPACK_EXTERNAL_MODULE_node_inspector_dd9822d6__ from "node:inspector";
25
24
  import * as __WEBPACK_EXTERNAL_MODULE_node_assert_3e74d44e__ from "node:assert";
26
25
  import * as __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__ from "node:readline";
27
26
  import * as __WEBPACK_EXTERNAL_MODULE_node_dns_78d346ee__ from "node:dns";
@@ -1456,7 +1455,7 @@ let configCache = {}, OVERRIDE_PATHS = [
1456
1455
  overlay: !0,
1457
1456
  reconnect: 100
1458
1457
  }
1459
- }), LOCAL_ORIGINS_REGEX = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, getDefaultServerConfig = ()=>({
1458
+ }), defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, getDefaultServerConfig = ()=>({
1460
1459
  port: 3000,
1461
1460
  host: DEFAULT_DEV_HOST,
1462
1461
  open: !1,
@@ -1466,7 +1465,7 @@ let configCache = {}, OVERRIDE_PATHS = [
1466
1465
  printUrls: !0,
1467
1466
  strictPort: !1,
1468
1467
  cors: {
1469
- origin: LOCAL_ORIGINS_REGEX
1468
+ origin: defaultAllowedOrigins
1470
1469
  },
1471
1470
  middlewareMode: !1
1472
1471
  }), getDefaultSourceConfig = ()=>({
@@ -2115,13 +2114,14 @@ async function updateEnvironmentContext(context, configs) {
2115
2114
  }
2116
2115
  }
2117
2116
  async function createContext(options, userConfig) {
2118
- 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;
2117
+ 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, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
2119
2118
  return {
2120
- version: "1.3.17",
2119
+ version: "1.3.18",
2121
2120
  rootPath,
2122
2121
  distPath: '',
2123
2122
  cachePath,
2124
- bundlerType: userConfig.provider ? 'webpack' : 'rspack',
2123
+ callerName: options.callerName,
2124
+ bundlerType,
2125
2125
  environments: {},
2126
2126
  hooks: {
2127
2127
  onExit: createAsyncHook(),
@@ -3157,15 +3157,18 @@ class RsbuildHtmlPlugin {
3157
3157
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
3158
3158
  let hooks = getHTMLPlugin().getCompilationHooks(compilation);
3159
3159
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
3160
- var _data_plugin_options, _data_plugin_options1;
3161
- let entryName = null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.entryName;
3162
- if (!entryName) return data;
3163
- let { headTags, bodyTags } = data, { favicon, tagConfig, templateContent } = this.options[entryName];
3164
- hasTitle(templateContent) || addTitleTag(headTags, null == (_data_plugin_options1 = data.plugin.options) ? void 0 : _data_plugin_options1.title), favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
3160
+ let extraData = this.getExtraData(data.plugin);
3161
+ if (!extraData) return data;
3162
+ let { headTags, bodyTags } = data, { favicon, context, tagConfig, entryName, environment, templateContent } = extraData;
3163
+ if (!hasTitle(templateContent)) {
3164
+ var _data_plugin_options;
3165
+ addTitleTag(headTags, null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.title);
3166
+ }
3167
+ favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
3165
3168
  let tags = {
3166
3169
  headTags: headTags.map(formatBasicTag),
3167
3170
  bodyTags: bodyTags.map(formatBasicTag)
3168
- }, context = this.getContext(), environment = this.getEnvironment(), [modified] = await context.hooks.modifyHTMLTags.callChain({
3171
+ }, [modified] = await context.hooks.modifyHTMLTags.callChain({
3169
3172
  environment: environment.name,
3170
3173
  args: [
3171
3174
  tags,
@@ -3183,7 +3186,9 @@ class RsbuildHtmlPlugin {
3183
3186
  bodyTags: modified.bodyTags.map(fromBasicTag)
3184
3187
  }), tagConfig && applyTagConfig(data, tagConfig, compilation.hash ?? '', entryName), data;
3185
3188
  }), hooks.beforeEmit.tapPromise(this.name, async (data)=>{
3186
- let context = this.getContext(), environment = this.getEnvironment(), [modified] = await context.hooks.modifyHTML.callChain({
3189
+ let extraData = this.getExtraData(data.plugin);
3190
+ if (!extraData) return data;
3191
+ let { context, environment } = extraData, [modified] = await context.hooks.modifyHTML.callChain({
3187
3192
  environment: environment.name,
3188
3193
  args: [
3189
3194
  data.html,
@@ -3202,8 +3207,8 @@ class RsbuildHtmlPlugin {
3202
3207
  });
3203
3208
  });
3204
3209
  }
3205
- constructor(options, getEnvironment, getContext){
3206
- RsbuildHtmlPlugin_define_property(this, "name", void 0), RsbuildHtmlPlugin_define_property(this, "getEnvironment", void 0), RsbuildHtmlPlugin_define_property(this, "options", void 0), RsbuildHtmlPlugin_define_property(this, "getContext", void 0), this.name = 'RsbuildHtmlPlugin', this.options = options, this.getEnvironment = getEnvironment, this.getContext = getContext;
3210
+ constructor(getExtraData){
3211
+ RsbuildHtmlPlugin_define_property(this, "name", void 0), RsbuildHtmlPlugin_define_property(this, "getExtraData", void 0), this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
3207
3212
  }
3208
3213
  }
3209
3214
  let getDefaultTemplateContent = (mountId)=>`<!doctype html><html><head></head><body><div id="${mountId}"></div></body></html>`, existTemplatePath = new Set();
@@ -3244,7 +3249,7 @@ let getTagConfig = (config)=>{
3244
3249
  api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID, environment })=>{
3245
3250
  let { config, htmlPaths } = environment;
3246
3251
  if (0 === Object.keys(htmlPaths).length) return;
3247
- let assetPrefix = getPublicPathFromChain(chain, !1), entries = chain.entryPoints.entries() || {}, entryNames = Object.keys(entries).filter((entryName)=>!!htmlPaths[entryName]), htmlInfoMap = {}, finalOptions = await Promise.all(entryNames.map(async (entryName)=>{
3252
+ let assetPrefix = getPublicPathFromChain(chain, !1), entries = chain.entryPoints.entries() || {}, entryNames = Object.keys(entries).filter((entryName)=>!!htmlPaths[entryName]), extraDataList = [], finalOptions = await Promise.all(entryNames.map(async (entryName)=>{
3248
3253
  let entryValue = entries[entryName].values(), chunks = function(entryName, entryValue) {
3249
3254
  let chunks = [
3250
3255
  entryName
@@ -3302,10 +3307,14 @@ let getTagConfig = (config)=>{
3302
3307
  scriptLoading: config.html.scriptLoading
3303
3308
  };
3304
3309
  templatePath && (pluginOptions.template = templatePath), chunks.length > 1 && (pluginOptions.chunksSortMode = 'manual');
3305
- let htmlInfo = {};
3306
- htmlInfoMap[entryName] = htmlInfo, templateContent && (htmlInfo.templateContent = templateContent);
3310
+ let extraData = {
3311
+ entryName,
3312
+ context,
3313
+ environment
3314
+ };
3315
+ extraDataList.push(extraData), templateContent && (extraData.templateContent = templateContent);
3307
3316
  let tagConfig = getTagConfig(environment.config);
3308
- tagConfig && (htmlInfo.tagConfig = tagConfig), pluginOptions.title = reduceConfigsMergeContext({
3317
+ tagConfig && (extraData.tagConfig = tagConfig), pluginOptions.title = reduceConfigsMergeContext({
3309
3318
  initial: '',
3310
3319
  config: config.html.title,
3311
3320
  ctx: {
@@ -3319,7 +3328,7 @@ let getTagConfig = (config)=>{
3319
3328
  entryName: entryName
3320
3329
  }
3321
3330
  });
3322
- favicon && (htmlInfo.favicon = favicon);
3331
+ favicon && (extraData.favicon = favicon);
3323
3332
  let finalOptions = reduceConfigsWithContext({
3324
3333
  initial: pluginOptions,
3325
3334
  config: 'boolean' == typeof config.tools.htmlPlugin ? {} : config.tools.htmlPlugin,
@@ -3329,15 +3338,12 @@ let getTagConfig = (config)=>{
3329
3338
  }
3330
3339
  });
3331
3340
  return finalOptions.template || finalOptions.templateContent || (pluginOptions.template = '', pluginOptions.templateContent = templateContent), finalOptions;
3332
- }));
3341
+ })), extraDataMap = new WeakMap();
3333
3342
  if (entryNames.forEach((entryName, index)=>{
3334
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [
3335
- finalOptions[index]
3336
- ]);
3343
+ let pluginInstance = new HtmlPlugin(finalOptions[index]), extraData = extraDataList.find((item)=>item.entryName === entryName);
3344
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(pluginInstance), extraData && extraDataMap.set(pluginInstance, extraData);
3337
3345
  }), chain.plugin('rsbuild-html-plugin').use(RsbuildHtmlPlugin, [
3338
- htmlInfoMap,
3339
- ()=>environment,
3340
- ()=>context
3346
+ (pluginInstance)=>extraDataMap.get(pluginInstance)
3341
3347
  ]), config.html) {
3342
3348
  let { crossorigin } = config.html;
3343
3349
  crossorigin && chain.output.crossOriginLoading(!0 === crossorigin ? 'anonymous' : crossorigin);
@@ -4244,31 +4250,25 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4244
4250
  }
4245
4251
  });
4246
4252
  }
4247
- }), stopProfiler = (output, profileSession)=>{
4248
- profileSession && profileSession.post('Profiler.stop', (error, param)=>{
4249
- if (error) return void __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to generate JavaScript CPU profile:', error);
4250
- __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.writeFileSync(output, JSON.stringify(param.profile));
4251
- });
4252
- }, pluginRspackProfile = ()=>({
4253
+ }), pluginRspackProfile = ()=>({
4253
4254
  name: 'rsbuild:rspack-profile',
4254
4255
  async setup (api) {
4255
4256
  var _process_env_RSPACK_PROFILE;
4256
- let profileSession;
4257
4257
  if ('webpack' === api.context.bundlerType) return;
4258
4258
  let RSPACK_PROFILE = null == (_process_env_RSPACK_PROFILE = process.env.RSPACK_PROFILE) ? void 0 : _process_env_RSPACK_PROFILE.toUpperCase();
4259
4259
  if (!RSPACK_PROFILE) return;
4260
- let timestamp = Date.now(), profileDirName = `rspack-profile-${timestamp}`, enableProfileTrace = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('TRACE'), enableCPUProfile = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('CPU'), onStart = async ()=>{
4260
+ let timestamp = Date.now(), profileDirName = `rspack-profile-${timestamp}`, enableProfileTrace = 'ALL' === RSPACK_PROFILE || RSPACK_PROFILE.includes('TRACE'), onStart = async ()=>{
4261
4261
  let profileDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(api.context.distPath, profileDirName), traceFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(profileDir, 'trace.json');
4262
4262
  await isFileExists(profileDir) || await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.mkdir(profileDir, {
4263
4263
  recursive: !0
4264
- }), enableProfileTrace && __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.default.experiments.globalTrace.register('trace', 'chrome', traceFilePath), enableCPUProfile && ((profileSession = new __WEBPACK_EXTERNAL_MODULE_node_inspector_dd9822d6__.default.Session()).connect(), profileSession.post('Profiler.enable'), profileSession.post('Profiler.start'));
4264
+ }), enableProfileTrace && __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.default.experiments.globalTrace.register('trace', 'chrome', traceFilePath);
4265
4265
  };
4266
4266
  api.onBeforeBuild(({ isFirstCompile })=>{
4267
4267
  isFirstCompile && onStart();
4268
4268
  }), api.onBeforeStartDevServer(onStart), api.onExit(()=>{
4269
4269
  enableProfileTrace && __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.default.experiments.globalTrace.cleanup();
4270
4270
  let profileDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(api.context.distPath, profileDirName);
4271
- stopProfiler(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(profileDir, 'jscpuprofile.json'), profileSession), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`profile files saved to ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(profileDir)}`);
4271
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`profile file saved to ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(profileDir)}`);
4272
4272
  });
4273
4273
  }
4274
4274
  }), pluginServer = ()=>({
@@ -6653,9 +6653,10 @@ async function applyDefaultPlugins(pluginManager, context) {
6653
6653
  setup (api) {
6654
6654
  'webpack' !== api.context.bundlerType && (api.modifyRsbuildConfig((config)=>{
6655
6655
  let { moduleFederation } = config;
6656
- if (api.isPluginExists('rsbuild:module-federation-enhanced') && (config.server ||= {}, config.server.cors = !0), (null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
6657
- var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
6658
- config.dev ||= {}, config.server ||= {}, config.server.cors = !0, (null == (_config_server = config.server) ? void 0 : _config_server.port) && !(null == (_config_dev_client = config.dev.client) ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null == (_originalConfig_dev = api.getRsbuildConfig('original').dev) ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null == (_config_server1 = config.server) ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
6656
+ if ((null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
6657
+ var _userConfig_server, _config_server, _config_dev_client, _userConfig_dev, _config_server1;
6658
+ let userConfig = api.getRsbuildConfig('original');
6659
+ config.dev ||= {}, config.server ||= {}, (null == (_userConfig_server = userConfig.server) ? void 0 : _userConfig_server.cors) === void 0 && (config.server.cors = !0), (null == (_config_server = config.server) ? void 0 : _config_server.port) && !(null == (_config_dev_client = config.dev.client) ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null == (_userConfig_dev = userConfig.dev) ? void 0 : _userConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null == (_config_server1 = config.server) ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
6659
6660
  }
6660
6661
  }), api.modifyEnvironmentConfig((config)=>{
6661
6662
  var _config_moduleFederation, _config_performance_chunkSplit, _config_performance;
@@ -6707,6 +6708,7 @@ async function createRsbuild(options = {}) {
6707
6708
  }
6708
6709
  let resolvedOptions = {
6709
6710
  cwd: process.cwd(),
6711
+ callerName: 'rsbuild',
6710
6712
  ...options,
6711
6713
  rsbuildConfig: config
6712
6714
  }, pluginManager = (plugins = [], {
@@ -6768,6 +6770,7 @@ async function createRsbuild(options = {}) {
6768
6770
  'distPath',
6769
6771
  'devServer',
6770
6772
  'cachePath',
6773
+ 'callerName',
6771
6774
  'bundlerType'
6772
6775
  ];
6773
6776
  return new Proxy(context, {
@@ -7362,11 +7365,11 @@ async function runCLI() {
7362
7365
  }
7363
7366
  process.title = 'rsbuild-node';
7364
7367
  let { npm_execpath } = process.env;
7365
- (!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.3.17\n`);
7368
+ (!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.3.18\n`);
7366
7369
  try {
7367
7370
  !function() {
7368
7371
  let cli = cac_dist('rsbuild');
7369
- cli.help(), cli.version("1.3.17"), applyCommonOptions(cli);
7372
+ cli.help(), cli.version("1.3.18"), applyCommonOptions(cli);
7370
7373
  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');
7371
7374
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7372
7375
  try {
@@ -7417,6 +7420,6 @@ async function runCLI() {
7417
7420
  __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);
7418
7421
  }
7419
7422
  }
7420
- let src_version = "1.3.17";
7423
+ let src_version = "1.3.18";
7421
7424
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
7422
- 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 };
7425
+ export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
@@ -4,8 +4,18 @@ import type { InspectConfigOptions, InspectConfigResult, NormalizedConfig, Plugi
4
4
  * - localhost
5
5
  * - 127.0.0.1
6
6
  * - [::1]
7
+ *
8
+ * Can be used in `server.cors.origin` config.
9
+ * @example
10
+ * ```ts
11
+ * server: {
12
+ * cors: {
13
+ * origin: [defaultAllowedOrigins, 'https://example.com'],
14
+ * },
15
+ * }
16
+ * ```
7
17
  */
8
- export declare const LOCAL_ORIGINS_REGEX: RegExp;
18
+ export declare const defaultAllowedOrigins: RegExp;
9
19
  export declare function getDefaultEntry(root: string): RsbuildEntry;
10
20
  export declare const withDefaultConfig: (rootPath: string, config: RsbuildConfig) => Promise<RsbuildConfig>;
11
21
  /**
@@ -14,6 +14,7 @@ export type { Rspack };
14
14
  export { logger } from './logger';
15
15
  export { mergeRsbuildConfig } from './mergeConfig';
16
16
  export { ensureAssetPrefix } from './helpers';
17
+ export { defaultAllowedOrigins } from './config';
17
18
  export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME } from './constants';
18
19
  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, ModifyHTMLContext, ModifyHTMLFn, 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, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProcessAssetsDescriptor, ProcessAssetsHook, ProcessAssetsHandler, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolveHook, ResolveHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, ResourceHintsIncludeType, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformHook, TransformHandler, TransformImport, WatchFiles, } from './types';
19
20
  export type { ChainIdentifier } from './configChain';
@@ -1,4 +1,4 @@
1
- import type { Compiler } from '@rspack/core';
1
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
2
  import type { HtmlRspackPlugin, InternalContext } from '../types';
3
3
  import type { EnvironmentContext, HtmlTag, HtmlTagDescriptor } from '../types';
4
4
  type HtmlTagObject = HtmlRspackPlugin.HtmlTagObject;
@@ -12,12 +12,14 @@ export declare const FILE_ATTRS: {
12
12
  link: string;
13
13
  script: string;
14
14
  };
15
- export type HtmlInfo = {
15
+ export type HtmlExtraData = {
16
+ entryName: string;
17
+ context: InternalContext;
18
+ environment: EnvironmentContext;
16
19
  favicon?: string;
17
20
  tagConfig?: TagConfig;
18
21
  templateContent?: string;
19
22
  };
20
- export type RsbuildHtmlPluginOptions = Record<string, HtmlInfo>;
21
23
  export type AlterAssetTagGroupsData = {
22
24
  headTags: HtmlTagObject[];
23
25
  bodyTags: HtmlTagObject[];
@@ -28,10 +30,8 @@ export type AlterAssetTagGroupsData = {
28
30
  export declare const hasTitle: (html?: string) => boolean;
29
31
  export declare class RsbuildHtmlPlugin {
30
32
  readonly name: string;
31
- readonly getEnvironment: () => EnvironmentContext;
32
- readonly options: RsbuildHtmlPluginOptions;
33
- readonly getContext: () => InternalContext;
34
- constructor(options: RsbuildHtmlPluginOptions, getEnvironment: () => EnvironmentContext, getContext: () => InternalContext);
33
+ readonly getExtraData: (pluginInstance: RspackPluginInstance) => HtmlExtraData | undefined;
34
+ constructor(getExtraData: (pluginInstance: RspackPluginInstance) => HtmlExtraData | undefined);
35
35
  apply(compiler: Compiler): void;
36
36
  }
37
37
  export {};
@@ -30,6 +30,14 @@ export type RsbuildContext = {
30
30
  * The bundler type, can be `rspack` or `webpack`.
31
31
  */
32
32
  bundlerType: BundlerType;
33
+ /**
34
+ * The name of the framework or tool that is currently invoking Rsbuild,
35
+ * same as the `callerName` option in the `createRsbuild` method.
36
+ * @example
37
+ * - `rslib` is set when Rslib calls Rsbuild.
38
+ * - `rspress` is set when Rspress calls Rsbuild.
39
+ */
40
+ callerName: string;
33
41
  };
34
42
  /** The inner context. */
35
43
  export type InternalContext = RsbuildContext & {
@@ -104,6 +104,13 @@ export type CreateRsbuildOptions = {
104
104
  * @default process.cwd()
105
105
  */
106
106
  cwd?: string;
107
+ /**
108
+ * The name of the framework or tool that is currently invoking Rsbuild.
109
+ * This allows plugins to tailor their behavior based on the calling context.
110
+ * Rsbuild plugins can access this value via `api.context.callerName`.
111
+ * @default 'rsbuild'
112
+ */
113
+ callerName?: string;
107
114
  /**
108
115
  * Only build specified environments.
109
116
  * For example, passing `['web']` will only build the `web` environment.
@@ -122,7 +129,7 @@ export type CreateRsbuildOptions = {
122
129
  */
123
130
  loadEnv?: boolean | LoadEnvOptions;
124
131
  };
125
- export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, 'cwd'>> & Pick<CreateRsbuildOptions, 'loadEnv' | 'environment'> & {
132
+ export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, 'cwd' | 'callerName'>> & Pick<CreateRsbuildOptions, 'loadEnv' | 'environment'> & {
126
133
  rsbuildConfig: RsbuildConfig;
127
134
  };
128
135
  export type CreateDevServer = (options?: CreateDevServerOptions) => Promise<RsbuildDevServer>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.3.17",
3
+ "version": "1.3.18",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {