@rsbuild/core 1.4.2 → 1.4.4

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
@@ -866,6 +866,12 @@ var __webpack_modules__ = {
866
866
  module.exports = import("node:vm").then(function(module) {
867
867
  return module;
868
868
  });
869
+ },
870
+ "node:zlib": function(module) {
871
+ "use strict";
872
+ module.exports = import("node:zlib").then(function(module) {
873
+ return module;
874
+ });
869
875
  }
870
876
  }, __webpack_module_cache__ = {};
871
877
  function __webpack_require__(moduleId) {
@@ -946,7 +952,7 @@ for(var __webpack_i__ in (()=>{
946
952
  node: [
947
953
  'node >= 16'
948
954
  ]
949
- }, HTML_REGEX = /\.html$/, JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/, SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, CSS_REGEX = /\.css$/, NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, PLUGIN_SWC_NAME = 'rsbuild:swc', PLUGIN_CSS_NAME = 'rsbuild:css', FONT_EXTENSIONS = [
955
+ }, HTML_REGEX = /\.html$/, JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/, SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, CSS_REGEX = /\.css$/, RAW_QUERY_REGEX = /^\?raw$/, INLINE_QUERY_REGEX = /^\?inline$/, NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, PLUGIN_SWC_NAME = 'rsbuild:swc', PLUGIN_CSS_NAME = 'rsbuild:css', FONT_EXTENSIONS = [
950
956
  'woff',
951
957
  'woff2',
952
958
  'eot',
@@ -2219,7 +2225,7 @@ ${section.body}` : section.body).join("\n\n"));
2219
2225
  }, {});
2220
2226
  async function updateEnvironmentContext(context, configs) {
2221
2227
  for (let [index, [name, config]] of (context.environments ||= {}, Object.entries(configs).entries())){
2222
- let browserslist = await getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), environmentContext = {
2228
+ let browserslist = await getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', environmentContext = {
2223
2229
  index,
2224
2230
  name,
2225
2231
  distPath: function(cwd, config) {
@@ -2230,7 +2236,8 @@ ${section.body}` : section.body).join("\n\n"));
2230
2236
  browserslist,
2231
2237
  htmlPaths,
2232
2238
  tsconfigPath,
2233
- config
2239
+ config,
2240
+ webSocketToken
2234
2241
  };
2235
2242
  context.environments[name] = new Proxy(environmentContext, {
2236
2243
  get: (target, prop)=>target[prop],
@@ -2241,7 +2248,7 @@ ${section.body}` : section.body).join("\n\n"));
2241
2248
  async function createContext(options, userConfig) {
2242
2249
  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';
2243
2250
  return {
2244
- version: "1.4.2",
2251
+ version: "1.4.4",
2245
2252
  rootPath,
2246
2253
  distPath: '',
2247
2254
  cachePath,
@@ -2938,7 +2945,7 @@ ${section.body}` : section.body).join("\n\n"));
2938
2945
  let generatorOptions = {
2939
2946
  filename
2940
2947
  };
2941
- !1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/(__inline=false|url)/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(/inline/), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(/raw/), rule.oneOf(`${assetType}-asset`).type('asset').parser({
2948
+ !1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/^\?(__inline=false|url)$/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(INLINE_QUERY_REGEX), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(RAW_QUERY_REGEX), rule.oneOf(`${assetType}-asset`).type('asset').parser({
2942
2949
  dataUrlCondition: {
2943
2950
  maxSize
2944
2951
  }
@@ -3874,9 +3881,6 @@ ${section.body}` : section.body).join("\n\n"));
3874
3881
  })
3875
3882
  });
3876
3883
  return addressUrls;
3877
- }, COMPILATION_ID_REGEX = /[^a-zA-Z0-9_-]/g, getCompilationId = (compiler)=>{
3878
- let uniqueName = compiler.options.output.uniqueName ?? '';
3879
- return `${compiler.name ?? ''}_${uniqueName.replace(COMPILATION_ID_REGEX, '_')}`;
3880
3884
  };
3881
3885
  function getServerTerminator(server) {
3882
3886
  let listened = !1, pendingSockets = new Set(), onConnection = (socket)=>{
@@ -3941,6 +3945,7 @@ ${section.body}` : section.body).join("\n\n"));
3941
3945
  }
3942
3946
  let openedURLs = [], replacePortPlaceholder = (url, port)=>url.replace(/<port>/g, String(port));
3943
3947
  async function server_open_open({ https, port, routes, config, clearCache }) {
3948
+ if ('true' === process.env.CSB) return;
3944
3949
  let { targets, before } = ((config)=>{
3945
3950
  let { open } = config.server;
3946
3951
  return 'boolean' == typeof open ? {
@@ -4348,13 +4353,15 @@ ${section.body}` : section.body).join("\n\n"));
4348
4353
  }
4349
4354
  let getCompilationMiddleware = async (compiler, options)=>{
4350
4355
  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);
4351
- return applyToCompiler(compiler, (compiler)=>{
4352
- clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig }) {
4356
+ return applyToCompiler(compiler, (compiler, index)=>{
4357
+ var _Object_values_find;
4358
+ let token = null == (_Object_values_find = Object.values(options.environments).find((env)=>env.index === index)) ? void 0 : _Object_values_find.webSocketToken;
4359
+ token && (clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig, token }) {
4353
4360
  if (((compiler)=>{
4354
4361
  let { target } = compiler.options;
4355
4362
  return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
4356
4363
  })(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
4357
- RSBUILD_COMPILATION_NAME: JSON.stringify(getCompilationId(compiler)),
4364
+ RSBUILD_WEB_SOCKET_TOKEN: JSON.stringify(token),
4358
4365
  RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
4359
4366
  RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
4360
4367
  RSBUILD_DEV_LIVE_RELOAD: devConfig.liveReload
@@ -4365,19 +4372,26 @@ ${section.body}` : section.body).join("\n\n"));
4365
4372
  compiler,
4366
4373
  clientPaths,
4367
4374
  devConfig,
4368
- resolvedClientConfig
4369
- }), ((compiler, { onDone, onInvalid })=>{
4375
+ resolvedClientConfig,
4376
+ token
4377
+ }), (({ compiler, token, callbacks: { onDone, onInvalid } })=>{
4370
4378
  if (((compiler)=>{
4371
4379
  let { target } = compiler.options;
4372
4380
  return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
4373
4381
  })(compiler)) return;
4374
4382
  let { compile, invalid, done } = compiler.hooks;
4375
4383
  compile.tap('rsbuild-dev-server', ()=>{
4376
- onInvalid(getCompilationId(compiler));
4384
+ onInvalid(token);
4377
4385
  }), invalid.tap('rsbuild-dev-server', (fileName)=>{
4378
- onInvalid(getCompilationId(compiler), fileName);
4379
- }), done.tap('rsbuild-dev-server', onDone);
4380
- })(compiler, callbacks);
4386
+ onInvalid(token, fileName);
4387
+ }), done.tap('rsbuild-dev-server', (stats)=>{
4388
+ onDone(token, stats);
4389
+ });
4390
+ })({
4391
+ compiler,
4392
+ callbacks,
4393
+ token
4394
+ }));
4381
4395
  }), rsbuildDevMiddleware(compiler, {
4382
4396
  etag: 'weak',
4383
4397
  publicPath: '/',
@@ -4423,6 +4437,10 @@ ${section.body}` : section.body).join("\n\n"));
4423
4437
  writable: !0
4424
4438
  }) : obj[key] = value, obj;
4425
4439
  }
4440
+ let parseQueryString = (req)=>{
4441
+ let queryStr = req.url ? req.url.split('?')[1] : '';
4442
+ return queryStr ? Object.fromEntries(new URLSearchParams(queryStr)) : {};
4443
+ };
4426
4444
  class SocketServer {
4427
4445
  clearHeartbeatTimer() {
4428
4446
  this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null);
@@ -4437,51 +4455,44 @@ ${section.body}` : section.body).join("\n\n"));
4437
4455
  }), this.wsServer.on('error', (err)=>{
4438
4456
  index_js_namespaceObject.logger.error(err);
4439
4457
  }), this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref(), this.wsServer.on('connection', (socket, req)=>{
4440
- let queryStr = req.url ? req.url.split('?')[1] : '';
4441
- this.onConnect(socket, queryStr ? Object.fromEntries(new URLSearchParams(queryStr)) : {});
4458
+ let query = parseQueryString(req);
4459
+ this.onConnect(socket, query.token);
4442
4460
  });
4443
4461
  }
4444
- updateStats(stats) {
4445
- let compilationId = getCompilationId(stats.compilation);
4446
- this.stats[compilationId] = stats, this.sockets.length && this.sendStats({
4447
- compilationId
4462
+ updateStats(stats, token) {
4463
+ this.stats[token] = stats, this.sockets.size && this.sendStats({
4464
+ token
4448
4465
  });
4449
4466
  }
4450
- sockWrite({ type, compilationId, data }) {
4451
- for (let socket of this.sockets)this.send(socket, JSON.stringify({
4452
- type,
4453
- data,
4454
- compilationId
4455
- }));
4467
+ sockWrite(message, token) {
4468
+ let messageStr = JSON.stringify(message);
4469
+ if (token) {
4470
+ let socket = this.sockets.get(token);
4471
+ socket && this.send(socket, messageStr);
4472
+ } else for (let socket of this.sockets.values())this.send(socket, messageStr);
4456
4473
  }
4457
- singleWrite(socket, { type, data, compilationId }) {
4458
- this.send(socket, JSON.stringify({
4459
- type,
4460
- data,
4461
- compilationId
4462
- }));
4474
+ singleWrite(socket, message) {
4475
+ this.send(socket, JSON.stringify(message));
4463
4476
  }
4464
4477
  async close() {
4465
4478
  for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
4466
- for (let socket of this.sockets)socket.close();
4467
- return this.stats = {}, this.initialChunks = {}, this.sockets.length = 0, new Promise((resolve, reject)=>{
4479
+ for (let socket of this.sockets.values())socket.close();
4480
+ return this.stats = {}, this.initialChunks = {}, this.sockets.clear(), new Promise((resolve, reject)=>{
4468
4481
  this.wsServer.close((err)=>{
4469
4482
  err ? reject(err) : resolve();
4470
4483
  });
4471
4484
  });
4472
4485
  }
4473
- onConnect(socket, params) {
4486
+ onConnect(socket, token) {
4474
4487
  socket.isAlive = !0, socket.on('pong', ()=>{
4475
4488
  socket.isAlive = !0;
4476
- }), this.sockets.push(socket), socket.on('close', ()=>{
4477
- let index = this.sockets.indexOf(socket);
4478
- index >= 0 && this.sockets.splice(index, 1);
4489
+ }), this.sockets.set(token, socket), socket.on('close', ()=>{
4490
+ this.sockets.delete(token);
4479
4491
  }), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
4480
- type: 'hot',
4481
- compilationId: params.compilationId
4492
+ type: 'hot'
4482
4493
  }), this.stats && this.sendStats({
4483
4494
  force: !0,
4484
- compilationId: params.compilationId
4495
+ token
4485
4496
  });
4486
4497
  }
4487
4498
  getStats(name) {
@@ -4506,38 +4517,34 @@ ${section.body}` : section.body).join("\n\n"));
4506
4517
  root: curStats.compilation.compiler.options.context
4507
4518
  } : null;
4508
4519
  }
4509
- sendStats({ force = !1, compilationId }) {
4520
+ sendStats({ force = !1, token }) {
4510
4521
  var a, b;
4511
- let result = this.getStats(compilationId);
4522
+ let result = this.getStats(token);
4512
4523
  if (!result) return null;
4513
4524
  let { statsJson, root } = result, newInitialChunks = new Set();
4514
4525
  if (statsJson.entrypoints) for (let entrypoint of Object.values(statsJson.entrypoints)){
4515
4526
  let chunks = entrypoint.chunks;
4516
4527
  if (Array.isArray(chunks)) for (let chunkName of chunks)chunkName && newInitialChunks.add(String(chunkName));
4517
4528
  }
4518
- let initialChunks = this.initialChunks[compilationId], shouldReload = !!statsJson.entrypoints && !!initialChunks && (a = initialChunks, b = newInitialChunks, !(a.size === b.size && [
4529
+ let initialChunks = this.initialChunks[token], shouldReload = !!statsJson.entrypoints && !!initialChunks && (a = initialChunks, b = newInitialChunks, !(a.size === b.size && [
4519
4530
  ...a
4520
4531
  ].every((value)=>b.has(value))));
4521
- if (this.initialChunks[compilationId] = newInitialChunks, shouldReload) return this.sockWrite({
4522
- type: 'static-changed',
4523
- compilationId
4524
- });
4532
+ if (this.initialChunks[token] = newInitialChunks, shouldReload) return this.sockWrite({
4533
+ type: 'static-changed'
4534
+ }, token);
4525
4535
  if (!force && statsJson && !statsJson.errorsCount && statsJson.assets && statsJson.assets.every((asset)=>!asset.emitted)) return this.sockWrite({
4526
- type: 'ok',
4527
- compilationId
4528
- });
4536
+ type: 'ok'
4537
+ }, token);
4529
4538
  if (this.sockWrite({
4530
4539
  type: 'hash',
4531
- compilationId,
4532
4540
  data: statsJson.hash
4533
- }), statsJson.errorsCount) {
4541
+ }, token), statsJson.errorsCount) {
4534
4542
  let { errors: formattedErrors } = formatStatsMessages({
4535
4543
  errors: getAllStatsErrors(statsJson),
4536
4544
  warnings: []
4537
4545
  });
4538
4546
  return this.sockWrite({
4539
4547
  type: 'errors',
4540
- compilationId,
4541
4548
  data: {
4542
4549
  text: formattedErrors,
4543
4550
  html: function(errors, root) {
@@ -4695,7 +4702,7 @@ ${section.body}` : section.body).join("\n\n"));
4695
4702
  `;
4696
4703
  }(formattedErrors, root)
4697
4704
  }
4698
- });
4705
+ }, token);
4699
4706
  }
4700
4707
  if (statsJson.warningsCount) {
4701
4708
  let { warnings: formattedWarnings } = formatStatsMessages({
@@ -4704,29 +4711,30 @@ ${section.body}` : section.body).join("\n\n"));
4704
4711
  });
4705
4712
  return this.sockWrite({
4706
4713
  type: 'warnings',
4707
- compilationId,
4708
4714
  data: {
4709
4715
  text: formattedWarnings
4710
4716
  }
4711
- });
4717
+ }, token);
4712
4718
  }
4713
4719
  return this.sockWrite({
4714
- type: 'ok',
4715
- compilationId
4716
- });
4720
+ type: 'ok'
4721
+ }, token);
4717
4722
  }
4718
4723
  send(connection, message) {
4719
4724
  1 === connection.readyState && connection.send(message);
4720
4725
  }
4721
- constructor(options){
4722
- socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "upgrade", (req, sock, head)=>{
4723
- this.wsServer.shouldHandle(req) && this.wsServer.handleUpgrade(req, sock, head, (connection)=>{
4726
+ constructor(options, environments){
4727
+ socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", new Map()), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "environments", void 0), socketServer_define_property(this, "upgrade", (req, socket, head)=>{
4728
+ if (!this.wsServer.shouldHandle(req)) return;
4729
+ let query = parseQueryString(req);
4730
+ if (!Object.values(this.environments).map((env)=>env.webSocketToken).includes(query.token)) return void socket.destroy();
4731
+ this.wsServer.handleUpgrade(req, socket, head, (connection)=>{
4724
4732
  this.wsServer.emit('connection', connection, req);
4725
4733
  });
4726
4734
  }), socketServer_define_property(this, "checkSockets", ()=>{
4727
4735
  for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
4728
4736
  null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
4729
- }), this.options = options, this.stats = {}, this.initialChunks = {};
4737
+ }), this.options = options, this.stats = {}, this.initialChunks = {}, this.environments = environments;
4730
4738
  }
4731
4739
  }
4732
4740
  function compilationManager_define_property(obj, key, value) {
@@ -4759,29 +4767,28 @@ ${section.body}` : section.body).join("\n\n"));
4759
4767
  });
4760
4768
  }
4761
4769
  async setupCompilationMiddleware() {
4762
- let { devConfig, serverConfig, publicPaths } = this, clientPaths = function(devConfig) {
4770
+ let { devConfig, serverConfig, publicPaths, environments } = this, clientPaths = function(devConfig) {
4763
4771
  var _devConfig_client;
4764
4772
  let clientPaths = [];
4765
4773
  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;
4766
4774
  }(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
4767
4775
  callbacks: {
4768
- onInvalid: (compilationId, fileName)=>{
4776
+ onInvalid: (token, fileName)=>{
4769
4777
  if ('string' == typeof fileName && HTML_REGEX.test(fileName)) return void this.socketServer.sockWrite({
4770
- type: 'static-changed',
4771
- compilationId
4772
- });
4778
+ type: 'static-changed'
4779
+ }, token);
4773
4780
  this.socketServer.sockWrite({
4774
- type: 'invalid',
4775
- compilationId
4776
- });
4781
+ type: 'invalid'
4782
+ }, token);
4777
4783
  },
4778
- onDone: (stats)=>{
4779
- this.socketServer.updateStats(stats);
4784
+ onDone: (token, stats)=>{
4785
+ this.socketServer.updateStats(stats, token);
4780
4786
  }
4781
4787
  },
4782
4788
  clientPaths,
4783
4789
  devConfig,
4784
- serverConfig
4790
+ serverConfig,
4791
+ environments
4785
4792
  }), { base } = serverConfig, assetPrefixes = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
4786
4793
  let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
4787
4794
  assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
@@ -4791,7 +4798,7 @@ ${section.body}` : section.body).join("\n\n"));
4791
4798
  wrapper.close = middleware.close, wrapper.watch = middleware.watch, this.middleware = wrapper;
4792
4799
  }
4793
4800
  constructor({ dev, server, compiler, publicPaths, environments }){
4794
- compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.devConfig = ((config, environments)=>{
4801
+ compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "environments", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.devConfig = ((config, environments)=>{
4795
4802
  let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
4796
4803
  return 1 === new Set(writeToDiskValues).size ? {
4797
4804
  ...config,
@@ -4803,11 +4810,13 @@ ${section.body}` : section.body).join("\n\n"));
4803
4810
  return compilationName && environments[compilationName] && (writeToDisk = environments[compilationName].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
4804
4811
  }
4805
4812
  };
4806
- })(dev, environments), this.serverConfig = server, this.compiler = compiler, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev);
4813
+ })(dev, environments), this.serverConfig = server, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev, environments);
4807
4814
  }
4808
4815
  }
4809
- let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
4810
- let gzip, writeHeadStatus, accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
4816
+ let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ filter, level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
4817
+ let gzip, writeHeadStatus;
4818
+ if (filter && !1 === filter(req, res)) return void next();
4819
+ let accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
4811
4820
  if ('HEAD' === req.method || !encoding) return void next();
4812
4821
  let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
4813
4822
  if (!started) {
@@ -4931,7 +4940,8 @@ ${section.body}` : section.body).join("\n\n"));
4931
4940
  let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
4932
4941
  for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
4933
4942
  }
4934
- if (server.compress && middlewares.push(gzipMiddleware()), 'dev' === context.action && 'rspack' === context.bundlerType && compilationManager) {
4943
+ let { compress } = server;
4944
+ if (compress && middlewares.push(gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && 'rspack' === context.bundlerType && compilationManager) {
4935
4945
  let { compiler } = compilationManager;
4936
4946
  (()=>{
4937
4947
  var _compiler_options_experiments;
@@ -5691,9 +5701,14 @@ ${section.body}` : section.body).join("\n\n"));
5691
5701
  for (let middleware of middlewares)this.middlewares.use(middleware);
5692
5702
  this.app.on('upgrade', upgrade);
5693
5703
  }
5694
- if (compress && this.middlewares.use(gzipMiddleware({
5695
- level: 6
5696
- })), base && '/' !== base && this.middlewares.use(getBaseMiddleware({
5704
+ if (compress) {
5705
+ let { constants } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "node:zlib"));
5706
+ this.middlewares.use(gzipMiddleware({
5707
+ level: constants.Z_DEFAULT_COMPRESSION,
5708
+ ...'object' == typeof compress ? compress : void 0
5709
+ }));
5710
+ }
5711
+ if (base && '/' !== base && this.middlewares.use(getBaseMiddleware({
5697
5712
  base
5698
5713
  })), await this.applyStaticAssetMiddleware(), historyApiFallback) {
5699
5714
  let { default: connectHistoryApiFallback } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect-history-api-fallback/index.js")), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === historyApiFallback ? {} : historyApiFallback);
@@ -6481,8 +6496,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6481
6496
  rule.test(CSS_REGEX).type("javascript/auto").dependency({
6482
6497
  not: 'url'
6483
6498
  }).resourceQuery({
6484
- not: /raw|inline/
6485
- }), inlineRule.test(CSS_REGEX).type("javascript/auto").resourceQuery(/inline/), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(/raw/);
6499
+ not: [
6500
+ RAW_QUERY_REGEX,
6501
+ INLINE_QUERY_REGEX
6502
+ ]
6503
+ }), inlineRule.test(CSS_REGEX).type("javascript/auto").resourceQuery(INLINE_QUERY_REGEX), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(RAW_QUERY_REGEX);
6486
6504
  let emitCss = config1.output.emitCss ?? 'web' === target;
6487
6505
  if (emitCss) if (config1.output.injectStyles) {
6488
6506
  let styleLoaderOptions = reduceConfigs({
@@ -6665,9 +6683,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6665
6683
  let { config, browserslist } = environment, cacheRoot = external_node_path_default().join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto").dependency({
6666
6684
  not: 'url'
6667
6685
  }).resourceQuery({
6668
- not: /raw/
6686
+ not: RAW_QUERY_REGEX
6669
6687
  });
6670
- chain.module.rule(CHAIN_ID.RULE.JS_RAW).test(SCRIPT_REGEX).type('asset/source').resourceQuery(/raw/);
6688
+ chain.module.rule(CHAIN_ID.RULE.JS_RAW).test(SCRIPT_REGEX).type('asset/source').resourceQuery(RAW_QUERY_REGEX);
6671
6689
  let dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
6672
6690
  or: [
6673
6691
  "text/javascript",
@@ -7844,11 +7862,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7844
7862
  ].includes(level) && (index_js_namespaceObject.logger.level = level);
7845
7863
  }
7846
7864
  let { npm_execpath } = process.env;
7847
- (!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.2\n`);
7865
+ (!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.4\n`);
7848
7866
  try {
7849
7867
  !function() {
7850
7868
  let cli = ((name = "")=>new CAC(name))('rsbuild');
7851
- cli.help(), cli.version("1.4.2"), 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`', {
7869
+ cli.help(), cli.version("1.4.4"), 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`', {
7852
7870
  default: 'jiti'
7853
7871
  }).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', {
7854
7872
  type: [
@@ -7906,7 +7924,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7906
7924
  index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), index_js_namespaceObject.logger.error(err);
7907
7925
  }
7908
7926
  }
7909
- let src_version = "1.4.2";
7927
+ let src_version = "1.4.4";
7910
7928
  })(), 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 === [
7911
7929
  "PLUGIN_CSS_NAME",
7912
7930
  "PLUGIN_SWC_NAME",