@rsbuild/core 1.4.12 → 1.4.13

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
@@ -1200,7 +1200,7 @@ __webpack_require__.n = (module)=>{
1200
1200
  var __webpack_exports__ = {};
1201
1201
  for(var __webpack_i__ in (()=>{
1202
1202
  "use strict";
1203
- let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, isDockerCached, cachedResult;
1203
+ let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, isDockerCached, cachedResult, hmrClientPath, overlayClientPath;
1204
1204
  __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
1205
1205
  PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
1206
1206
  createRsbuild: ()=>createRsbuild,
@@ -3039,7 +3039,8 @@ ${section.body}` : section.body).join("\n\n"));
3039
3039
  wasm: 'static/wasm',
3040
3040
  image: 'static/image',
3041
3041
  media: 'static/media',
3042
- assets: 'static/assets'
3042
+ assets: 'static/assets',
3043
+ favicon: './'
3043
3044
  },
3044
3045
  assetPrefix: DEFAULT_ASSET_PREFIX,
3045
3046
  filename: {},
@@ -3322,7 +3323,7 @@ ${section.body}` : section.body).join("\n\n"));
3322
3323
  async function createContext(options, userConfig) {
3323
3324
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(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';
3324
3325
  return {
3325
- version: "1.4.12",
3326
+ version: "1.4.13",
3326
3327
  rootPath,
3327
3328
  distPath: '',
3328
3329
  cachePath,
@@ -3684,6 +3685,14 @@ ${section.body}` : section.body).join("\n\n"));
3684
3685
  }
3685
3686
  return config.devServer && index_js_namespaceObject.logger.warn(`${picocolors_index_js_default().dim('[rsbuild:config]')} Find invalid Rspack config: "${picocolors_index_js_default().yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`), rspackConfig;
3686
3687
  }
3688
+ let allowedEnvironmentDevKeys = [
3689
+ 'hmr',
3690
+ 'liveReload',
3691
+ 'writeToDisk',
3692
+ 'assetPrefix',
3693
+ 'progressBar',
3694
+ 'lazyCompilation'
3695
+ ];
3687
3696
  async function modifyRsbuildConfig(context) {
3688
3697
  var _context_config_plugins, _modified_plugins;
3689
3698
  index_js_namespaceObject.logger.debug('modify Rsbuild config');
@@ -3750,13 +3759,7 @@ ${section.body}` : section.body).join("\n\n"));
3750
3759
  applyEnvironmentDefaultConfig({
3751
3760
  ...mergeRsbuildConfig({
3752
3761
  ...rsbuildSharedConfig,
3753
- dev: pick(dev, [
3754
- 'writeToDisk',
3755
- 'hmr',
3756
- 'assetPrefix',
3757
- 'progressBar',
3758
- 'lazyCompilation'
3759
- ])
3762
+ dev: pick(dev, allowedEnvironmentDevKeys)
3760
3763
  }, config)
3761
3764
  })
3762
3765
  ]));
@@ -3768,24 +3771,18 @@ ${section.body}` : section.body).join("\n\n"));
3768
3771
  return {
3769
3772
  [defaultEnvironmentName]: applyEnvironmentDefaultConfig({
3770
3773
  ...rsbuildSharedConfig,
3771
- dev: pick(dev, [
3772
- 'hmr',
3773
- 'assetPrefix',
3774
- 'progressBar',
3775
- 'lazyCompilation',
3776
- 'writeToDisk'
3777
- ])
3774
+ dev: pick(dev, allowedEnvironmentDevKeys)
3778
3775
  })
3779
3776
  };
3780
- })(normalizedBaseConfig, context.rootPath, context.specifiedEnvironments), { dev: { hmr: _hmr, assetPrefix: _assetPrefix, progressBar: _progressBar, lazyCompilation: _lazyCompilation, writeToDisk: _writeToDisk, ...rsbuildSharedDev }, server } = normalizedBaseConfig, tsconfigPaths = new Set();
3777
+ })(normalizedBaseConfig, context.rootPath, context.specifiedEnvironments), tsconfigPaths = new Set();
3781
3778
  for (let [name, config] of Object.entries(mergedEnvironments)){
3782
3779
  let environmentConfig = await modifyEnvironmentConfig(context, config, name), normalizedEnvironmentConfig = {
3783
3780
  ...environmentConfig,
3784
3781
  dev: {
3785
- ...environmentConfig.dev,
3786
- ...rsbuildSharedDev
3782
+ ...normalizedBaseConfig.dev,
3783
+ ...environmentConfig.dev
3787
3784
  },
3788
- server
3785
+ server: normalizedBaseConfig.server
3789
3786
  }, { tsconfigPath } = normalizedEnvironmentConfig.source;
3790
3787
  if (tsconfigPath) {
3791
3788
  let absoluteTsconfigPath = ensureAbsolutePath(context.rootPath, tsconfigPath);
@@ -4311,22 +4308,26 @@ ${section.body}` : section.body).join("\n\n"));
4311
4308
  }));
4312
4309
  class RsbuildHtmlPlugin {
4313
4310
  apply(compiler) {
4314
- let emitFavicon = async (compilation, favicon)=>{
4311
+ let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
4315
4312
  let buffer, name = external_node_path_default().basename(favicon);
4316
4313
  if (compilation.assets[name]) return name;
4317
4314
  if (!compilation.inputFileSystem) return addCompilationError(compilation, `${picocolors_index_js_default().dim('[rsbuild:html]')} Failed to read the favicon file as ${picocolors_index_js_default().yellow('compilation.inputFileSystem')} is not available.`), null;
4318
- let filename = external_node_path_default().isAbsolute(favicon) ? favicon : external_node_path_default().join(compilation.compiler.context, favicon);
4315
+ let inputFilename = external_node_path_default().isAbsolute(favicon) ? favicon : external_node_path_default().join(compilation.compiler.context, favicon);
4319
4316
  try {
4320
- if (!(buffer = await (0, external_node_util_namespaceObject.promisify)(compilation.inputFileSystem.readFile)(filename))) throw Error('Buffer is undefined');
4317
+ if (!(buffer = await (0, external_node_util_namespaceObject.promisify)(compilation.inputFileSystem.readFile)(inputFilename))) throw Error('Buffer is undefined');
4321
4318
  } catch (error) {
4322
- return index_js_namespaceObject.logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors_index_js_default().dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors_index_js_default().yellow(filename)}.`), null;
4319
+ return index_js_namespaceObject.logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors_index_js_default().dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors_index_js_default().yellow(inputFilename)}.`), null;
4323
4320
  }
4324
- let source = new compiler.webpack.sources.RawSource(buffer, !1);
4325
- return compilation.emitAsset(name, source), name;
4326
- }, addFavicon = async (headTags, favicon, compilation, publicPath)=>{
4321
+ let source = new compiler.webpack.sources.RawSource(buffer, !1), outputFilename = external_node_path_default().posix.join(faviconDistPath, name);
4322
+ return compilation.emitAsset(outputFilename, source), outputFilename;
4323
+ }, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath })=>{
4327
4324
  let href = favicon;
4328
4325
  if (!isURL(favicon)) {
4329
- let name = await emitFavicon(compilation, favicon);
4326
+ let name = await emitFavicon({
4327
+ compilation,
4328
+ favicon,
4329
+ faviconDistPath
4330
+ });
4330
4331
  if (null === name) return;
4331
4332
  href = ensureAssetPrefix(name, publicPath);
4332
4333
  }
@@ -4350,7 +4351,7 @@ ${section.body}` : section.body).join("\n\n"));
4350
4351
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
4351
4352
  let html, extraData = getExtraDataByPlugin(data.plugin);
4352
4353
  if (!extraData) return data;
4353
- let { headTags, bodyTags } = data, { favicon, context, tagConfig, entryName, environment, templateContent } = extraData;
4354
+ let { headTags, bodyTags } = data, { favicon, faviconDistPath, context, tagConfig, entryName, environment, templateContent } = extraData;
4354
4355
  if (!((html = templateContent) && /<title/i.test(html) && /<\/title/i.test(html))) {
4355
4356
  var _data_plugin_options;
4356
4357
  ((headTags, title = '')=>{
@@ -4363,7 +4364,13 @@ ${section.body}` : section.body).join("\n\n"));
4363
4364
  });
4364
4365
  })(headTags, null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.title);
4365
4366
  }
4366
- favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
4367
+ favicon && await addFavicon({
4368
+ headTags,
4369
+ favicon,
4370
+ faviconDistPath,
4371
+ compilation,
4372
+ publicPath: data.publicPath
4373
+ });
4367
4374
  let tags = {
4368
4375
  headTags: headTags.map(formatBasicTag),
4369
4376
  bodyTags: bodyTags.map(formatBasicTag)
@@ -5443,16 +5450,23 @@ ${section.body}` : section.body).join("\n\n"));
5443
5450
  port: serverConfig.port
5444
5451
  };
5445
5452
  }
5446
- let getCompilationMiddleware = async (compiler, options)=>{
5447
- let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), { clientPaths, callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
5453
+ let compilationMiddleware_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), getCompilationMiddleware = async (compiler, options)=>{
5454
+ let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), { callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
5448
5455
  return applyToCompiler(compiler, (compiler, index)=>{
5449
- var _Object_values_find;
5450
- let token = null == (_Object_values_find = Object.values(options.environments).find((env)=>env.index === index)) ? void 0 : _Object_values_find.webSocketToken;
5451
- token && (clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig, token }) {
5452
- if (((compiler)=>{
5456
+ let environment = Object.values(options.environments).find((env)=>env.index === index);
5457
+ if (!environment) return;
5458
+ let token = environment.webSocketToken;
5459
+ token && (!function({ config, compiler, devConfig, resolvedClientConfig, token }) {
5460
+ if (!((compiler)=>{
5453
5461
  let { target } = compiler.options;
5454
5462
  return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
5455
- })(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
5463
+ })(compiler)) return;
5464
+ let clientPaths = function(devConfig) {
5465
+ var _devConfig_client;
5466
+ let clientPaths = [];
5467
+ return (devConfig.hmr || devConfig.liveReload) && (hmrClientPath || (hmrClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/hmr')), clientPaths.push(hmrClientPath), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && (overlayClientPath || (overlayClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/overlay')), clientPaths.push(overlayClientPath))), clientPaths;
5468
+ }(config.dev);
5469
+ if (clientPaths.length) for (let clientPath of (new compiler.webpack.DefinePlugin({
5456
5470
  RSBUILD_WEB_SOCKET_TOKEN: JSON.stringify(token),
5457
5471
  RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
5458
5472
  RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
@@ -5462,10 +5476,10 @@ ${section.body}` : section.body).join("\n\n"));
5462
5476
  }).apply(compiler);
5463
5477
  }({
5464
5478
  compiler,
5465
- clientPaths,
5466
5479
  devConfig,
5467
5480
  resolvedClientConfig,
5468
- token
5481
+ token,
5482
+ config: environment.config
5469
5483
  }), (({ compiler, token, callbacks: { onDone, onInvalid } })=>{
5470
5484
  if (((compiler)=>{
5471
5485
  let { target } = compiler.options;
@@ -5563,9 +5577,6 @@ ${section.body}` : section.body).join("\n\n"));
5563
5577
  socket && this.send(socket, messageStr);
5564
5578
  } else for (let socket of this.sockets.values())this.send(socket, messageStr);
5565
5579
  }
5566
- singleWrite(socket, message) {
5567
- this.send(socket, JSON.stringify(message));
5568
- }
5569
5580
  async close() {
5570
5581
  for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
5571
5582
  for (let socket of this.sockets.values())socket.close();
@@ -5580,8 +5591,6 @@ ${section.body}` : section.body).join("\n\n"));
5580
5591
  socket.isAlive = !0;
5581
5592
  }), this.sockets.set(token, socket), socket.on('close', ()=>{
5582
5593
  this.sockets.delete(token);
5583
- }), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
5584
- type: 'hot'
5585
5594
  }), this.stats && this.sendStats({
5586
5595
  force: !0,
5587
5596
  token
@@ -5627,7 +5636,7 @@ ${section.body}` : section.body).join("\n\n"));
5627
5636
  if (!force && statsJson && !statsJson.errorsCount && statsJson.assets && statsJson.assets.every((asset)=>!asset.emitted)) return void this.sockWrite({
5628
5637
  type: 'ok'
5629
5638
  }, token);
5630
- if (this.sockWrite({
5639
+ if (statsJson.hash && this.sockWrite({
5631
5640
  type: 'hash',
5632
5641
  data: statsJson.hash
5633
5642
  }, token), statsJson.errorsCount) {
@@ -5839,7 +5848,6 @@ ${section.body}` : section.body).join("\n\n"));
5839
5848
  writable: !0
5840
5849
  }) : obj[key] = value, obj;
5841
5850
  }
5842
- let compilationManager_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
5843
5851
  class CompilationManager {
5844
5852
  async init() {
5845
5853
  await this.setupCompilationMiddleware(), await this.socketServer.prepare();
@@ -5861,25 +5869,17 @@ ${section.body}` : section.body).join("\n\n"));
5861
5869
  });
5862
5870
  }
5863
5871
  async setupCompilationMiddleware() {
5864
- let { devConfig, serverConfig, publicPaths, environments } = this, clientPaths = function(devConfig) {
5865
- var _devConfig_client;
5866
- let clientPaths = [];
5867
- return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/hmr')), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/overlay'))), clientPaths;
5868
- }(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
5872
+ let { devConfig, serverConfig, publicPaths, environments } = this, middleware = await getCompilationMiddleware(this.compiler, {
5869
5873
  callbacks: {
5870
5874
  onInvalid: (token, fileName)=>{
5871
5875
  if ('string' == typeof fileName && fileName.endsWith('.html')) return void this.socketServer.sockWrite({
5872
5876
  type: 'static-changed'
5873
5877
  }, token);
5874
- this.socketServer.sockWrite({
5875
- type: 'invalid'
5876
- }, token);
5877
5878
  },
5878
5879
  onDone: (token, stats)=>{
5879
5880
  this.socketServer.updateStats(stats, token);
5880
5881
  }
5881
5882
  },
5882
- clientPaths,
5883
5883
  devConfig,
5884
5884
  serverConfig,
5885
5885
  environments
@@ -6256,12 +6256,12 @@ ${section.body}` : section.body).join("\n\n"));
6256
6256
  'default',
6257
6257
  ...Object.keys(something)
6258
6258
  ])
6259
- ], m = new SyntheticModule(exports1, ()=>{
6260
- for (let name of exports1)m.setExport(name, 'default' === name ? something : something[name]);
6259
+ ], syntheticModule = new SyntheticModule(exports1, ()=>{
6260
+ for (let name of exports1)syntheticModule.setExport(name, 'default' === name ? something : something[name]);
6261
6261
  }, {
6262
6262
  context
6263
6263
  });
6264
- return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
6264
+ return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
6265
6265
  };
6266
6266
  function basic_define_property(obj, key, value) {
6267
6267
  return key in obj ? Object.defineProperty(obj, key, {
@@ -6427,7 +6427,7 @@ ${section.body}` : section.body).join("\n\n"));
6427
6427
  }), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
6428
6428
  if (await esm.link(async (specifier, referencingModule)=>asModule(await _require(external_node_path_default().dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, external_node_url_namespaceObject.fileURLToPath)(referencingModule.url)), specifier, {
6429
6429
  esmMode: type_EsmMode.Unlinked
6430
- }), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
6430
+ }), referencingModule.context, !0)), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
6431
6431
  let ns = esm.namespace;
6432
6432
  return ns.default && ns.default instanceof Promise ? ns.default : ns;
6433
6433
  })();
@@ -7373,7 +7373,8 @@ ${section.body}` : section.body).join("\n\n"));
7373
7373
  let extraData = {
7374
7374
  entryName,
7375
7375
  context: context1,
7376
- environment
7376
+ environment,
7377
+ faviconDistPath: config.output.distPath.favicon
7377
7378
  };
7378
7379
  extraDataMap.set(entryName, extraData), templateContent && (extraData.templateContent = templateContent);
7379
7380
  let tagConfig = ((config)=>{
@@ -9034,11 +9035,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9034
9035
  ].includes(level) && (index_js_namespaceObject.logger.level = level);
9035
9036
  }
9036
9037
  let { npm_execpath } = process.env;
9037
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.12\n`);
9038
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.13\n`);
9038
9039
  try {
9039
9040
  !function() {
9040
9041
  let cli = ((name = "")=>new CAC(name))('rsbuild');
9041
- cli.help(), cli.version("1.4.12"), cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
9042
+ cli.help(), cli.version("1.4.13"), cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
9042
9043
  default: 'jiti'
9043
9044
  }).option('-r, --root <root>', 'specify the project root directory, can be an absolute path or a path relative to cwd').option('-m, --mode <mode>', 'specify the build mode, can be `development`, `production` or `none`').option('--log-level <level>', 'specify the log level, can be `info`, `warn`, `error` or `silent`').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', {
9044
9045
  type: [
@@ -9096,7 +9097,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
9096
9097
  index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), index_js_namespaceObject.logger.error(err);
9097
9098
  }
9098
9099
  }
9099
- let src_version = "1.4.12";
9100
+ let src_version = "1.4.13";
9100
9101
  })(), 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 === [
9101
9102
  "PLUGIN_CSS_NAME",
9102
9103
  "PLUGIN_SWC_NAME",
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, isDockerCached, cachedResult;
2
+ let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, isDockerCached, cachedResult, hmrClientPath, overlayClientPath;
3
3
  import { createRequire } from "node:module";
4
4
  import { logger } from "../compiled/rslog/index.js";
5
5
  import node_path, { dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, sep } from "node:path";
@@ -2846,7 +2846,8 @@ let configCache = {}, OVERRIDE_PATHS = [
2846
2846
  wasm: 'static/wasm',
2847
2847
  image: 'static/image',
2848
2848
  media: 'static/media',
2849
- assets: 'static/assets'
2849
+ assets: 'static/assets',
2850
+ favicon: './'
2850
2851
  },
2851
2852
  assetPrefix: DEFAULT_ASSET_PREFIX,
2852
2853
  filename: {},
@@ -3125,7 +3126,7 @@ async function updateEnvironmentContext(context, configs) {
3125
3126
  async function createContext(options, userConfig) {
3126
3127
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
3127
3128
  return {
3128
- version: "1.4.12",
3129
+ version: "1.4.13",
3129
3130
  rootPath,
3130
3131
  distPath: '',
3131
3132
  cachePath,
@@ -3483,6 +3484,14 @@ async function generateRspackConfig({ target, context, environment }) {
3483
3484
  }
3484
3485
  return config.devServer && logger.warn(`${picocolors.dim('[rsbuild:config]')} Find invalid Rspack config: "${picocolors.yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`), rspackConfig;
3485
3486
  }
3487
+ let allowedEnvironmentDevKeys = [
3488
+ 'hmr',
3489
+ 'liveReload',
3490
+ 'writeToDisk',
3491
+ 'assetPrefix',
3492
+ 'progressBar',
3493
+ 'lazyCompilation'
3494
+ ];
3486
3495
  async function modifyRsbuildConfig(context) {
3487
3496
  var _context_config_plugins, _modified_plugins;
3488
3497
  logger.debug('modify Rsbuild config');
@@ -3549,13 +3558,7 @@ async function initRsbuildConfig({ context, pluginManager }) {
3549
3558
  applyEnvironmentDefaultConfig({
3550
3559
  ...mergeRsbuildConfig({
3551
3560
  ...rsbuildSharedConfig,
3552
- dev: pick(dev, [
3553
- 'writeToDisk',
3554
- 'hmr',
3555
- 'assetPrefix',
3556
- 'progressBar',
3557
- 'lazyCompilation'
3558
- ])
3561
+ dev: pick(dev, allowedEnvironmentDevKeys)
3559
3562
  }, config)
3560
3563
  })
3561
3564
  ]));
@@ -3567,24 +3570,18 @@ async function initRsbuildConfig({ context, pluginManager }) {
3567
3570
  return {
3568
3571
  [defaultEnvironmentName]: applyEnvironmentDefaultConfig({
3569
3572
  ...rsbuildSharedConfig,
3570
- dev: pick(dev, [
3571
- 'hmr',
3572
- 'assetPrefix',
3573
- 'progressBar',
3574
- 'lazyCompilation',
3575
- 'writeToDisk'
3576
- ])
3573
+ dev: pick(dev, allowedEnvironmentDevKeys)
3577
3574
  })
3578
3575
  };
3579
- })(normalizedBaseConfig, context.rootPath, context.specifiedEnvironments), { dev: { hmr: _hmr, assetPrefix: _assetPrefix, progressBar: _progressBar, lazyCompilation: _lazyCompilation, writeToDisk: _writeToDisk, ...rsbuildSharedDev }, server } = normalizedBaseConfig, tsconfigPaths = new Set();
3576
+ })(normalizedBaseConfig, context.rootPath, context.specifiedEnvironments), tsconfigPaths = new Set();
3580
3577
  for (let [name, config] of Object.entries(mergedEnvironments)){
3581
3578
  let environmentConfig = await modifyEnvironmentConfig(context, config, name), normalizedEnvironmentConfig = {
3582
3579
  ...environmentConfig,
3583
3580
  dev: {
3584
- ...environmentConfig.dev,
3585
- ...rsbuildSharedDev
3581
+ ...normalizedBaseConfig.dev,
3582
+ ...environmentConfig.dev
3586
3583
  },
3587
- server
3584
+ server: normalizedBaseConfig.server
3588
3585
  }, { tsconfigPath } = normalizedEnvironmentConfig.source;
3589
3586
  if (tsconfigPath) {
3590
3587
  let absoluteTsconfigPath = ensureAbsolutePath(context.rootPath, tsconfigPath);
@@ -4107,22 +4104,26 @@ let entryNameSymbol = Symbol('entryName'), VOID_TAGS = [
4107
4104
  }));
4108
4105
  class RsbuildHtmlPlugin {
4109
4106
  apply(compiler) {
4110
- let emitFavicon = async (compilation, favicon)=>{
4107
+ let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
4111
4108
  let buffer, name = node_path.basename(favicon);
4112
4109
  if (compilation.assets[name]) return name;
4113
4110
  if (!compilation.inputFileSystem) return addCompilationError(compilation, `${picocolors.dim('[rsbuild:html]')} Failed to read the favicon file as ${picocolors.yellow('compilation.inputFileSystem')} is not available.`), null;
4114
- let filename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
4111
+ let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
4115
4112
  try {
4116
- if (!(buffer = await external_node_util_promisify(compilation.inputFileSystem.readFile)(filename))) throw Error('Buffer is undefined');
4113
+ if (!(buffer = await external_node_util_promisify(compilation.inputFileSystem.readFile)(inputFilename))) throw Error('Buffer is undefined');
4117
4114
  } catch (error) {
4118
- return logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors.dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors.yellow(filename)}.`), null;
4115
+ return logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors.dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors.yellow(inputFilename)}.`), null;
4119
4116
  }
4120
- let source = new compiler.webpack.sources.RawSource(buffer, !1);
4121
- return compilation.emitAsset(name, source), name;
4122
- }, addFavicon = async (headTags, favicon, compilation, publicPath)=>{
4117
+ let source = new compiler.webpack.sources.RawSource(buffer, !1), outputFilename = node_path.posix.join(faviconDistPath, name);
4118
+ return compilation.emitAsset(outputFilename, source), outputFilename;
4119
+ }, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath })=>{
4123
4120
  let href = favicon;
4124
4121
  if (!isURL(favicon)) {
4125
- let name = await emitFavicon(compilation, favicon);
4122
+ let name = await emitFavicon({
4123
+ compilation,
4124
+ favicon,
4125
+ faviconDistPath
4126
+ });
4126
4127
  if (null === name) return;
4127
4128
  href = ensureAssetPrefix(name, publicPath);
4128
4129
  }
@@ -4146,7 +4147,7 @@ class RsbuildHtmlPlugin {
4146
4147
  hooks.alterAssetTagGroups.tapPromise(this.name, async (data)=>{
4147
4148
  let extraData = getExtraDataByPlugin(data.plugin);
4148
4149
  if (!extraData) return data;
4149
- let { headTags, bodyTags } = data, { favicon, context, tagConfig, entryName, environment, templateContent } = extraData;
4150
+ let { headTags, bodyTags } = data, { favicon, faviconDistPath, context, tagConfig, entryName, environment, templateContent } = extraData;
4150
4151
  if (!(templateContent && /<title/i.test(templateContent) && /<\/title/i.test(templateContent))) {
4151
4152
  var _data_plugin_options;
4152
4153
  ((headTags, title = '')=>{
@@ -4159,7 +4160,13 @@ class RsbuildHtmlPlugin {
4159
4160
  });
4160
4161
  })(headTags, null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.title);
4161
4162
  }
4162
- favicon && await addFavicon(headTags, favicon, compilation, data.publicPath);
4163
+ favicon && await addFavicon({
4164
+ headTags,
4165
+ favicon,
4166
+ faviconDistPath,
4167
+ compilation,
4168
+ publicPath: data.publicPath
4169
+ });
4163
4170
  let tags = {
4164
4171
  headTags: headTags.map(formatBasicTag),
4165
4172
  bodyTags: bodyTags.map(formatBasicTag)
@@ -5234,16 +5241,23 @@ async function getResolvedClientConfig(clientConfig, serverConfig) {
5234
5241
  port: serverConfig.port
5235
5242
  };
5236
5243
  }
5237
- let getCompilationMiddleware = async (compiler, options)=>{
5238
- let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js"), { clientPaths, callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
5244
+ let compilationMiddleware_require = createRequire(import.meta.url), getCompilationMiddleware = async (compiler, options)=>{
5245
+ let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js"), { callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
5239
5246
  return applyToCompiler(compiler, (compiler, index)=>{
5240
- var _Object_values_find;
5241
- let token = null == (_Object_values_find = Object.values(options.environments).find((env)=>env.index === index)) ? void 0 : _Object_values_find.webSocketToken;
5242
- token && (clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig, token }) {
5243
- if (((compiler)=>{
5247
+ let environment = Object.values(options.environments).find((env)=>env.index === index);
5248
+ if (!environment) return;
5249
+ let token = environment.webSocketToken;
5250
+ token && (!function({ config, compiler, devConfig, resolvedClientConfig, token }) {
5251
+ if (!((compiler)=>{
5244
5252
  let { target } = compiler.options;
5245
5253
  return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
5246
- })(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
5254
+ })(compiler)) return;
5255
+ let clientPaths = function(devConfig) {
5256
+ var _devConfig_client;
5257
+ let clientPaths = [];
5258
+ return (devConfig.hmr || devConfig.liveReload) && (hmrClientPath || (hmrClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/hmr')), clientPaths.push(hmrClientPath), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && (overlayClientPath || (overlayClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/overlay')), clientPaths.push(overlayClientPath))), clientPaths;
5259
+ }(config.dev);
5260
+ if (clientPaths.length) for (let clientPath of (new compiler.webpack.DefinePlugin({
5247
5261
  RSBUILD_WEB_SOCKET_TOKEN: JSON.stringify(token),
5248
5262
  RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
5249
5263
  RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
@@ -5253,10 +5267,10 @@ let getCompilationMiddleware = async (compiler, options)=>{
5253
5267
  }).apply(compiler);
5254
5268
  }({
5255
5269
  compiler,
5256
- clientPaths,
5257
5270
  devConfig,
5258
5271
  resolvedClientConfig,
5259
- token
5272
+ token,
5273
+ config: environment.config
5260
5274
  }), (({ compiler, token, callbacks: { onDone, onInvalid } })=>{
5261
5275
  if (((compiler)=>{
5262
5276
  let { target } = compiler.options;
@@ -5354,9 +5368,6 @@ class SocketServer {
5354
5368
  socket && this.send(socket, messageStr);
5355
5369
  } else for (let socket of this.sockets.values())this.send(socket, messageStr);
5356
5370
  }
5357
- singleWrite(socket, message) {
5358
- this.send(socket, JSON.stringify(message));
5359
- }
5360
5371
  async close() {
5361
5372
  for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
5362
5373
  for (let socket of this.sockets.values())socket.close();
@@ -5371,8 +5382,6 @@ class SocketServer {
5371
5382
  socket.isAlive = !0;
5372
5383
  }), this.sockets.set(token, socket), socket.on('close', ()=>{
5373
5384
  this.sockets.delete(token);
5374
- }), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
5375
- type: 'hot'
5376
5385
  }), this.stats && this.sendStats({
5377
5386
  force: !0,
5378
5387
  token
@@ -5417,7 +5426,7 @@ class SocketServer {
5417
5426
  if (!force && statsJson && !statsJson.errorsCount && statsJson.assets && statsJson.assets.every((asset)=>!asset.emitted)) return void this.sockWrite({
5418
5427
  type: 'ok'
5419
5428
  }, token);
5420
- if (this.sockWrite({
5429
+ if (statsJson.hash && this.sockWrite({
5421
5430
  type: 'hash',
5422
5431
  data: statsJson.hash
5423
5432
  }, token), statsJson.errorsCount) {
@@ -5629,7 +5638,6 @@ function compilationManager_define_property(obj, key, value) {
5629
5638
  writable: !0
5630
5639
  }) : obj[key] = value, obj;
5631
5640
  }
5632
- let compilationManager_require = createRequire(import.meta.url);
5633
5641
  class CompilationManager {
5634
5642
  async init() {
5635
5643
  await this.setupCompilationMiddleware(), await this.socketServer.prepare();
@@ -5651,25 +5659,17 @@ class CompilationManager {
5651
5659
  });
5652
5660
  }
5653
5661
  async setupCompilationMiddleware() {
5654
- let { devConfig, serverConfig, publicPaths, environments } = this, clientPaths = function(devConfig) {
5655
- var _devConfig_client;
5656
- let clientPaths = [];
5657
- return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/hmr')), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/overlay'))), clientPaths;
5658
- }(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
5662
+ let { devConfig, serverConfig, publicPaths, environments } = this, middleware = await getCompilationMiddleware(this.compiler, {
5659
5663
  callbacks: {
5660
5664
  onInvalid: (token, fileName)=>{
5661
5665
  if ('string' == typeof fileName && fileName.endsWith('.html')) return void this.socketServer.sockWrite({
5662
5666
  type: 'static-changed'
5663
5667
  }, token);
5664
- this.socketServer.sockWrite({
5665
- type: 'invalid'
5666
- }, token);
5667
5668
  },
5668
5669
  onDone: (token, stats)=>{
5669
5670
  this.socketServer.updateStats(stats, token);
5670
5671
  }
5671
5672
  },
5672
- clientPaths,
5673
5673
  devConfig,
5674
5674
  serverConfig,
5675
5675
  environments
@@ -6044,12 +6044,12 @@ let faviconFallbackMiddleware = (req, res, next)=>{
6044
6044
  'default',
6045
6045
  ...Object.keys(something)
6046
6046
  ])
6047
- ], m = new SyntheticModule(exports, ()=>{
6048
- for (let name of exports)m.setExport(name, 'default' === name ? something : something[name]);
6047
+ ], syntheticModule = new SyntheticModule(exports, ()=>{
6048
+ for (let name of exports)syntheticModule.setExport(name, 'default' === name ? something : something[name]);
6049
6049
  }, {
6050
6050
  context
6051
6051
  });
6052
- return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
6052
+ return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
6053
6053
  };
6054
6054
  function basic_define_property(obj, key, value) {
6055
6055
  return key in obj ? Object.defineProperty(obj, key, {
@@ -6212,7 +6212,7 @@ class EsmRunner extends CommonJsRunner {
6212
6212
  }), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
6213
6213
  if (await esm.link(async (specifier, referencingModule)=>asModule(await _require(node_path.dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : fileURLToPath(referencingModule.url)), specifier, {
6214
6214
  esmMode: type_EsmMode.Unlinked
6215
- }), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
6215
+ }), referencingModule.context, !0)), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
6216
6216
  let ns = esm.namespace;
6217
6217
  return ns.default && ns.default instanceof Promise ? ns.default : ns;
6218
6218
  })();
@@ -7152,7 +7152,8 @@ async function applyDefaultPlugins(pluginManager, context) {
7152
7152
  let extraData = {
7153
7153
  entryName,
7154
7154
  context: context,
7155
- environment
7155
+ environment,
7156
+ faviconDistPath: config.output.distPath.favicon
7156
7157
  };
7157
7158
  extraDataMap.set(entryName, extraData), templateContent && (extraData.templateContent = templateContent);
7158
7159
  let tagConfig = ((config)=>{
@@ -8808,11 +8809,11 @@ async function runCLI() {
8808
8809
  ].includes(level) && (logger.level = level);
8809
8810
  }
8810
8811
  let { npm_execpath } = process.env;
8811
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && logger.log(), logger.greet(` Rsbuild v1.4.12\n`);
8812
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && logger.log(), logger.greet(` Rsbuild v1.4.13\n`);
8812
8813
  try {
8813
8814
  !function() {
8814
8815
  let cli = ((name = "")=>new CAC(name))('rsbuild');
8815
- cli.help(), cli.version("1.4.12"), cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
8816
+ cli.help(), cli.version("1.4.13"), cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
8816
8817
  default: 'jiti'
8817
8818
  }).option('-r, --root <root>', 'specify the project root directory, can be an absolute path or a path relative to cwd').option('-m, --mode <mode>', 'specify the build mode, can be `development`, `production` or `none`').option('--log-level <level>', 'specify the log level, can be `info`, `warn`, `error` or `silent`').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', {
8818
8819
  type: [
@@ -8870,5 +8871,5 @@ async function runCLI() {
8870
8871
  logger.error('Failed to start Rsbuild CLI.'), logger.error(err);
8871
8872
  }
8872
8873
  }
8873
- let src_version = "1.4.12";
8874
+ let src_version = "1.4.13";
8874
8875
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger, mergeRsbuildConfig, rspack_rspack as rspack, runCLI, src_version as version };
@@ -2,6 +2,7 @@ export declare const __filename: string;
2
2
  export declare const __dirname: string;
3
3
  export declare const ROOT_DIST_DIR = "dist";
4
4
  export declare const HTML_DIST_DIR = "./";
5
+ export declare const FAVICON_DIST_DIR = "./";
5
6
  export declare const JS_DIST_DIR = "static/js";
6
7
  export declare const CSS_DIST_DIR = "static/css";
7
8
  export declare const SVG_DIST_DIR = "static/svg";
@@ -20,6 +20,7 @@ export type HtmlExtraData = {
20
20
  context: InternalContext;
21
21
  environment: EnvironmentContext;
22
22
  favicon?: string;
23
+ faviconDistPath: string;
23
24
  tagConfig?: TagConfig;
24
25
  templateContent?: string;
25
26
  };