@rsbuild/core 1.2.8 → 1.2.10

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.js CHANGED
@@ -519,38 +519,39 @@ function formatMessage(stats, verbose) {
519
519
  return !verbose && message.includes(innerError) && (message = message.split(innerError)[0]), (message = (message = hintNodePolyfill(message = function(message) {
520
520
  let hint = 'You may need an appropriate loader to handle this file type.';
521
521
  if (-1 === message.indexOf(hint)) return message;
522
+ let createPluginHint = (packageName, keyword)=>`To enable support for ${keyword}, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(`@rsbuild/plugin-${packageName}`)}" ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(`(https://www.npmjs.com/package/@rsbuild/plugin-${packageName})`)}.`;
522
523
  for (let plugin of [
523
524
  {
524
525
  test: /File: .+\.s(c|a)ss/,
525
- hint: `To enable support for Sass, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-sass')}".`
526
+ hint: createPluginHint('sass', 'Sass')
526
527
  },
527
528
  {
528
529
  test: /File: .+\.less/,
529
- hint: `To enable support for Less, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-less')}".`
530
+ hint: createPluginHint('less', 'Less')
530
531
  },
531
532
  {
532
533
  test: /File: .+\.styl(us)?/,
533
- hint: `To enable support for Stylus, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-stylus')}".`
534
+ hint: createPluginHint('stylus', 'Stylus')
534
535
  },
535
536
  {
536
537
  test: /File: .+\.vue?/,
537
- hint: `To enable support for Vue, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-vue')}".`
538
+ hint: createPluginHint('vue', 'Vue')
538
539
  },
539
540
  {
540
541
  test: /File: .+\.svelte?/,
541
- hint: `To enable support for Svelte, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-svelte')}".`
542
+ hint: createPluginHint('svelte', 'Svelte')
542
543
  },
543
544
  {
544
545
  test: /File: .+\.mdx/,
545
- hint: `To enable support for MDX, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-mdx')}".`
546
+ hint: createPluginHint('mdx', 'MDX')
546
547
  },
547
548
  {
548
549
  test: /File: .+\.toml/,
549
- hint: `To enable support for TOML, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-toml')}".`
550
+ hint: createPluginHint('toml', 'TOML')
550
551
  },
551
552
  {
552
553
  test: /File: .+\.yaml/,
553
- hint: `To enable support for YAML, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-yaml')}".`
554
+ hint: createPluginHint('yaml', 'YAML')
554
555
  }
555
556
  ])if (plugin.test.test(message)) return message.replace(hint, plugin.hint);
556
557
  return message;
@@ -827,7 +828,7 @@ let configCache = {}, OVERRIDE_PATHS = [
827
828
  async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
828
829
  cliOptions && (commonOpts = cliOptions);
829
830
  try {
830
- var _config_server, _config_dev;
831
+ var _config_server, _config_dev, _config_performance;
831
832
  let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
832
833
  cwd: getEnvDir(root, commonOpts.envDir),
833
834
  mode: commonOpts.envMode
@@ -837,10 +838,15 @@ async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
837
838
  envMode: commonOpts.envMode,
838
839
  loader: commonOpts.configLoader
839
840
  });
840
- config.source ||= {}, config.source.define = {
841
+ if (config.source ||= {}, config.source.define = {
841
842
  ...envs.publicVars,
842
843
  ...config.source.define
843
- }, commonOpts.base && (config.server ||= {}, config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0);
844
+ }, commonOpts.base && (config.server ||= {}, config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0), (null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache) && envs.filePaths.length > 0) {
845
+ let { buildCache } = config.performance;
846
+ !0 === buildCache ? config.performance.buildCache = {
847
+ buildDependencies: envs.filePaths
848
+ } : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
849
+ }
844
850
  let rsbuild = await createRsbuild({
845
851
  cwd: root,
846
852
  rsbuildConfig: config,
@@ -1343,7 +1349,7 @@ function createEnvironmentAsyncHook() {
1343
1349
  tap: (handler)=>tapEnvironment({
1344
1350
  handler
1345
1351
  }),
1346
- callInEnvironment: async ({ environment, args: params })=>{
1352
+ callChain: async ({ environment, args: params })=>{
1347
1353
  for (let callback of [
1348
1354
  ...preGroup,
1349
1355
  ...defaultGroup,
@@ -1354,6 +1360,19 @@ function createEnvironmentAsyncHook() {
1354
1360
  void 0 !== result && (params[0] = result);
1355
1361
  }
1356
1362
  return params;
1363
+ },
1364
+ callBatch: async ({ environment, args: params })=>{
1365
+ let results = [];
1366
+ for (let callback of [
1367
+ ...preGroup,
1368
+ ...defaultGroup,
1369
+ ...postGroup
1370
+ ]){
1371
+ if (callback.environment && environment && !isPluginMatchEnvironment(callback.environment, environment)) continue;
1372
+ let result = await callback.handler(...params);
1373
+ results.push(result);
1374
+ }
1375
+ return results;
1357
1376
  }
1358
1377
  };
1359
1378
  }
@@ -1363,7 +1382,7 @@ function createAsyncHook() {
1363
1382
  tap: (cb)=>{
1364
1383
  isFunction(cb) ? defaultGroup.push(cb) : 'pre' === cb.order ? preGroup.push(cb.handler) : 'post' === cb.order ? postGroup.push(cb.handler) : defaultGroup.push(cb.handler);
1365
1384
  },
1366
- call: async (...params)=>{
1385
+ callChain: async (...params)=>{
1367
1386
  for (let callback of [
1368
1387
  ...preGroup,
1369
1388
  ...defaultGroup,
@@ -1373,6 +1392,18 @@ function createAsyncHook() {
1373
1392
  void 0 !== result && (params[0] = result);
1374
1393
  }
1375
1394
  return params;
1395
+ },
1396
+ callBatch: async (...params)=>{
1397
+ let results = [];
1398
+ for (let callback of [
1399
+ ...preGroup,
1400
+ ...defaultGroup,
1401
+ ...postGroup
1402
+ ]){
1403
+ let result = await callback(...params);
1404
+ results.push(result);
1405
+ }
1406
+ return results;
1376
1407
  }
1377
1408
  };
1378
1409
  }
@@ -1410,7 +1441,7 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
1410
1441
  });
1411
1442
  }, registerBuildHook = ({ context, isWatch, compiler, bundlerConfigs, MultiStatsCtor })=>{
1412
1443
  let isFirstCompile = !0, environmentList = Object.values(context.environments).reduce((prev, curr)=>(prev[curr.index] = curr, prev), []), onDone = async (stats)=>{
1413
- let p = context.hooks.onAfterBuild.call({
1444
+ let p = context.hooks.onAfterBuild.callBatch({
1414
1445
  isFirstCompile,
1415
1446
  stats,
1416
1447
  environments: context.environments,
@@ -1418,7 +1449,7 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
1418
1449
  });
1419
1450
  isFirstCompile = !1, await p;
1420
1451
  }, onEnvironmentDone = async (buildIndex, stats)=>{
1421
- await context.hooks.onAfterEnvironmentCompile.callInEnvironment({
1452
+ await context.hooks.onAfterEnvironmentCompile.callBatch({
1422
1453
  environment: environmentList[buildIndex].name,
1423
1454
  args: [
1424
1455
  {
@@ -1432,13 +1463,13 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
1432
1463
  };
1433
1464
  onBeforeCompile({
1434
1465
  compiler,
1435
- beforeCompile: async ()=>await context.hooks.onBeforeBuild.call({
1466
+ beforeCompile: async ()=>await context.hooks.onBeforeBuild.callBatch({
1436
1467
  bundlerConfigs,
1437
1468
  environments: context.environments,
1438
1469
  isWatch,
1439
1470
  isFirstCompile
1440
1471
  }),
1441
- beforeEnvironmentCompiler: async (buildIndex)=>await context.hooks.onBeforeEnvironmentCompile.callInEnvironment({
1472
+ beforeEnvironmentCompiler: async (buildIndex)=>await context.hooks.onBeforeEnvironmentCompile.callBatch({
1442
1473
  environment: environmentList[buildIndex].name,
1443
1474
  args: [
1444
1475
  {
@@ -1458,14 +1489,14 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
1458
1489
  });
1459
1490
  }, registerDevHook = ({ context, compiler, bundlerConfigs, MultiStatsCtor })=>{
1460
1491
  let isFirstCompile = !0, environmentList = Object.values(context.environments).reduce((prev, curr)=>(prev[curr.index] = curr, prev), []), onDone = async (stats)=>{
1461
- let p = context.hooks.onDevCompileDone.call({
1492
+ let p = context.hooks.onDevCompileDone.callBatch({
1462
1493
  isFirstCompile,
1463
1494
  stats,
1464
1495
  environments: context.environments
1465
1496
  });
1466
1497
  isFirstCompile = !1, await p;
1467
1498
  }, onEnvironmentDone = async (buildIndex, stats)=>{
1468
- await context.hooks.onAfterEnvironmentCompile.callInEnvironment({
1499
+ await context.hooks.onAfterEnvironmentCompile.callBatch({
1469
1500
  environment: environmentList[buildIndex].name,
1470
1501
  args: [
1471
1502
  {
@@ -1479,7 +1510,7 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
1479
1510
  };
1480
1511
  onBeforeCompile({
1481
1512
  compiler,
1482
- beforeEnvironmentCompiler: async (buildIndex)=>await context.hooks.onBeforeEnvironmentCompile.callInEnvironment({
1513
+ beforeEnvironmentCompiler: async (buildIndex)=>await context.hooks.onBeforeEnvironmentCompile.callBatch({
1483
1514
  environment: environmentList[buildIndex].name,
1484
1515
  args: [
1485
1516
  {
@@ -1617,7 +1648,7 @@ async function updateEnvironmentContext(context, configs) {
1617
1648
  async function createContext(options, userConfig, bundlerType) {
1618
1649
  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;
1619
1650
  return {
1620
- version: "1.2.8",
1651
+ version: "1.2.10",
1621
1652
  rootPath,
1622
1653
  distPath: '',
1623
1654
  cachePath,
@@ -1750,7 +1781,7 @@ let pluginAppIcon = ()=>({
1750
1781
  async function modifyBundlerChain(context, utils) {
1751
1782
  var _utils_environment_config_tools;
1752
1783
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify bundler chain');
1753
- let bundlerChain = new __WEBPACK_EXTERNAL_MODULE__compiled_rspack_chain_index_js_b67fefbd__.default(), [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.callInEnvironment({
1784
+ let bundlerChain = new __WEBPACK_EXTERNAL_MODULE__compiled_rspack_chain_index_js_b67fefbd__.default(), [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.callChain({
1754
1785
  environment: utils.environment.name,
1755
1786
  args: [
1756
1787
  bundlerChain,
@@ -3282,7 +3313,7 @@ let getJsAsyncPath = (jsPath, isServer, jsAsync)=>void 0 !== jsAsync ? jsAsync :
3282
3313
  api.modifyBundlerChain(async (chain, { CHAIN_ID, target, isProd, isServer, environment })=>{
3283
3314
  let { distPath, config } = environment, publicPath = function({ isProd, config, context }) {
3284
3315
  var _context_devServer, _context_devServer1, _context_devServer2;
3285
- let { dev, output, server } = config, publicPath = DEFAULT_ASSET_PREFIX, port = (null === (_context_devServer = context.devServer) || void 0 === _context_devServer ? void 0 : _context_devServer.port) || 3000;
3316
+ let { dev, output, server } = config, publicPath = DEFAULT_ASSET_PREFIX, port = (null === (_context_devServer = context.devServer) || void 0 === _context_devServer ? void 0 : _context_devServer.port) || server.port || 3000;
3286
3317
  if (isProd) 'string' == typeof output.assetPrefix && (publicPath = output.assetPrefix);
3287
3318
  else if ('string' == typeof dev.assetPrefix) publicPath = dev.assetPrefix;
3288
3319
  else if (!0 === dev.assetPrefix) {
@@ -4094,7 +4125,7 @@ async function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerCo
4094
4125
  async function modifyRspackConfig(context, rspackConfig, utils) {
4095
4126
  var _utils_environment_config_tools;
4096
4127
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rspack config');
4097
- let [modifiedConfig] = await context.hooks.modifyRspackConfig.callInEnvironment({
4128
+ let [modifiedConfig] = await context.hooks.modifyRspackConfig.callChain({
4098
4129
  environment: utils.environment.name,
4099
4130
  args: [
4100
4131
  rspackConfig,
@@ -4172,14 +4203,14 @@ async function generateRspackConfig({ target, context, environment }) {
4172
4203
  }
4173
4204
  async function modifyRsbuildConfig(context) {
4174
4205
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rsbuild config');
4175
- let [modified] = await context.hooks.modifyRsbuildConfig.call(context.config, {
4206
+ let [modified] = await context.hooks.modifyRsbuildConfig.callChain(context.config, {
4176
4207
  mergeRsbuildConfig: mergeRsbuildConfig
4177
4208
  });
4178
4209
  context.config = modified, __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rsbuild config done');
4179
4210
  }
4180
4211
  async function modifyEnvironmentConfig(context, config, name) {
4181
4212
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`modify Rsbuild environment(${name}) config`);
4182
- let [modified] = await context.hooks.modifyEnvironmentConfig.callInEnvironment({
4213
+ let [modified] = await context.hooks.modifyEnvironmentConfig.callChain({
4183
4214
  environment: name,
4184
4215
  args: [
4185
4216
  config,
@@ -5128,6 +5159,12 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
5128
5159
  };
5129
5160
  }, notFoundMiddleware = (_req, res, _next)=>{
5130
5161
  res.statusCode = 404, res.end();
5162
+ }, optionsFallbackMiddleware = (req, res, next)=>{
5163
+ if ('OPTIONS' === req.method) {
5164
+ res.statusCode = 204, res.setHeader('Content-Length', '0'), res.end();
5165
+ return;
5166
+ }
5167
+ next();
5131
5168
  }, middlewares_isFileExists = async (filePath, outputFileSystem)=>new Promise((resolve)=>{
5132
5169
  outputFileSystem.stat(filePath, (_error, stats)=>{
5133
5170
  resolve(null == stats ? void 0 : stats.isFile());
@@ -5246,12 +5283,11 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
5246
5283
  let opts = {
5247
5284
  context,
5248
5285
  changeOrigin: !0,
5249
- logLevel: 'warn'
5286
+ logLevel: 'warn',
5287
+ logProvider: ()=>__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger
5250
5288
  };
5251
5289
  'string' == typeof options ? opts.target = options : Object.assign(opts, options), ret.push(opts);
5252
5290
  }
5253
- let handleError = (err)=>__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
5254
- for (let opts of ret)opts.onError ??= handleError;
5255
5291
  return ret;
5256
5292
  }(proxyOptions), proxyMiddlewares = [], middlewares = [], { createProxyMiddleware: baseMiddleware } = await import("../compiled/http-proxy-middleware/index.js");
5257
5293
  for (let opts of formattedOptions){
@@ -5280,7 +5316,7 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
5280
5316
  before,
5281
5317
  after
5282
5318
  };
5283
- }, applyDefaultMiddlewares = async ({ middlewares, server, compileMiddlewareAPI, output, pwd, outputFileSystem, environments })=>{
5319
+ }, applyDefaultMiddlewares = async ({ middlewares, server, compileMiddlewareAPI, output, pwd, outputFileSystem, environments, postCallbacks })=>{
5284
5320
  let upgradeEvents = [];
5285
5321
  if (server.compress && middlewares.push(gzipMiddleware()), middlewares.push((req, res, next)=>{
5286
5322
  var _parseUrl;
@@ -5323,6 +5359,7 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
5323
5359
  });
5324
5360
  middlewares.push(assetMiddleware);
5325
5361
  }
5362
+ for (let callback of postCallbacks)callback();
5326
5363
  if (compileMiddlewareAPI && middlewares.push(getHtmlFallbackMiddleware({
5327
5364
  distPath,
5328
5365
  callback: compileMiddlewareAPI.middleware,
@@ -5332,13 +5369,7 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
5332
5369
  let { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js"), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === server.historyApiFallback ? {} : server.historyApiFallback);
5333
5370
  middlewares.push(historyApiFallbackMiddleware), (null == compileMiddlewareAPI ? void 0 : compileMiddlewareAPI.middleware) && middlewares.push(compileMiddlewareAPI.middleware);
5334
5371
  }
5335
- return middlewares.push(faviconFallbackMiddleware), middlewares.push((req, res, next)=>{
5336
- if ('OPTIONS' === req.method) {
5337
- res.statusCode = 204, res.setHeader('Content-Length', '0'), res.end();
5338
- return;
5339
- }
5340
- next();
5341
- }), {
5372
+ return middlewares.push(faviconFallbackMiddleware), {
5342
5373
  onUpgrade: (...args)=>{
5343
5374
  for (let cb of upgradeEvents)cb(...args);
5344
5375
  }
@@ -5428,7 +5459,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5428
5459
  config,
5429
5460
  clearCache: !0
5430
5461
  }), closeServer = async ()=>{
5431
- await options.context.hooks.onCloseDevServer.call(), await Promise.all([
5462
+ await options.context.hooks.onCloseDevServer.callBatch(), await Promise.all([
5432
5463
  null == devMiddlewares ? void 0 : devMiddlewares.close(),
5433
5464
  null == fileWatcher ? void 0 : fileWatcher.close()
5434
5465
  ]);
@@ -5463,22 +5494,23 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5463
5494
  environment
5464
5495
  }))
5465
5496
  }
5466
- ])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), devServerAPI = {
5497
+ ])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), httpServer = await createHttpServer({
5498
+ serverConfig: config.server,
5499
+ middlewares
5500
+ }), devServerAPI = {
5467
5501
  port,
5468
5502
  middlewares,
5469
5503
  environments: environmentAPI,
5504
+ httpServer,
5470
5505
  listen: async ()=>{
5471
- let httpServer = await createHttpServer({
5472
- serverConfig: config.server,
5473
- middlewares
5474
- }), serverTerminator = getServerTerminator(httpServer);
5506
+ let serverTerminator = getServerTerminator(httpServer);
5475
5507
  return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server'), options.context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
5476
5508
  httpServer.listen({
5477
5509
  host,
5478
5510
  port
5479
5511
  }, async (err)=>{
5480
5512
  if (err) throw err;
5481
- middlewares.use(notFoundMiddleware), devMiddlewares && httpServer.on('upgrade', devMiddlewares.onUpgrade), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server done'), await devServerAPI.afterListen(), onBeforeRestartServer(devServerAPI.close), resolve({
5513
+ middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), devMiddlewares && httpServer.on('upgrade', devMiddlewares.onUpgrade), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server done'), await devServerAPI.afterListen(), onBeforeRestartServer(devServerAPI.close), resolve({
5482
5514
  port,
5483
5515
  urls: urls.map((item)=>item.url),
5484
5516
  server: {
@@ -5489,7 +5521,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5489
5521
  });
5490
5522
  },
5491
5523
  afterListen: async ()=>{
5492
- await options.context.hooks.onAfterStartDevServer.call({
5524
+ await options.context.hooks.onAfterStartDevServer.callBatch({
5493
5525
  port,
5494
5526
  routes,
5495
5527
  environments: options.context.environments
@@ -5501,11 +5533,11 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5501
5533
  close: closeServer,
5502
5534
  printUrls,
5503
5535
  open: openPage
5504
- };
5505
- await options.context.hooks.onBeforeStartDevServer.call({
5536
+ }, postCallbacks = (await options.context.hooks.onBeforeStartDevServer.callBatch({
5506
5537
  server: devServerAPI,
5507
5538
  environments: options.context.environments
5508
- }), runCompile ? options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
5539
+ })).filter((item)=>'function' == typeof item);
5540
+ runCompile ? options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
5509
5541
  let compileMiddlewareAPI = runCompile ? await startCompile() : void 0;
5510
5542
  for (let item of (fileWatcher = await setupWatchFiles({
5511
5543
  dev: devConfig,
@@ -5521,14 +5553,15 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5521
5553
  output: {
5522
5554
  distPath: options.context.distPath || ROOT_DIST_DIR
5523
5555
  },
5524
- outputFileSystem
5556
+ outputFileSystem,
5557
+ postCallbacks
5525
5558
  })).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
5526
5559
  return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server done'), devServerAPI;
5527
5560
  }
5528
5561
  async function createCompiler_createCompiler(options) {
5529
5562
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create compiler');
5530
5563
  let { context } = options, { rspackConfigs } = await initConfigs(options);
5531
- if (await context.hooks.onBeforeCreateCompiler.call({
5564
+ if (await context.hooks.onBeforeCreateCompiler.callBatch({
5532
5565
  bundlerConfigs: rspackConfigs,
5533
5566
  environments: context.environments
5534
5567
  }), !await isSatisfyRspackVersion(__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.rspackVersion)) throw Error(`[rsbuild] The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(rspackMinVersion)}`);
@@ -5567,7 +5600,7 @@ async function createCompiler_createCompiler(options) {
5567
5600
  compiler,
5568
5601
  bundlerConfigs: rspackConfigs,
5569
5602
  MultiStatsCtor: __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.MultiStats
5570
- }), await context.hooks.onAfterCreateCompiler.call({
5603
+ }), await context.hooks.onAfterCreateCompiler.callBatch({
5571
5604
  compiler,
5572
5605
  environments: context.environments
5573
5606
  }), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create compiler done'), {
@@ -5697,7 +5730,7 @@ class RsbuildProdServer {
5697
5730
  let { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js"), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === historyApiFallback ? {} : historyApiFallback);
5698
5731
  this.middlewares.use(historyApiFallbackMiddleware), await this.applyStaticAssetMiddleware();
5699
5732
  }
5700
- this.middlewares.use(faviconFallbackMiddleware);
5733
+ this.middlewares.use(faviconFallbackMiddleware), this.middlewares.use(optionsFallbackMiddleware), this.middlewares.use(notFoundMiddleware);
5701
5734
  }
5702
5735
  async applyStaticAssetMiddleware() {
5703
5736
  let { output: { path, assetPrefixes }, serverConfig: { htmlFallback } } = this.options, { default: sirv } = await import("../compiled/sirv/index.js"), assetMiddleware = sirv(path, {
@@ -5731,7 +5764,7 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
5731
5764
  },
5732
5765
  serverConfig
5733
5766
  }, middlewares);
5734
- await context.hooks.onBeforeStartProdServer.call();
5767
+ await context.hooks.onBeforeStartProdServer.callBatch();
5735
5768
  let httpServer = await createHttpServer({
5736
5769
  serverConfig,
5737
5770
  middlewares: server.middlewares
@@ -5742,7 +5775,7 @@ async function startProdServer(context, config, { getPortSilently } = {}) {
5742
5775
  port
5743
5776
  }, async ()=>{
5744
5777
  let routes = getRoutes(context);
5745
- await context.hooks.onAfterStartProdServer.call({
5778
+ await context.hooks.onAfterStartProdServer.callBatch({
5746
5779
  port,
5747
5780
  routes,
5748
5781
  environments: context.environments
@@ -5801,7 +5834,7 @@ async function applyDefaultPlugins(pluginManager, context) {
5801
5834
  pluginFileSize(),
5802
5835
  pluginCleanOutput(),
5803
5836
  pluginAsset(),
5804
- pluginHtml((environment)=>async (...args)=>(await context.hooks.modifyHTMLTags.callInEnvironment({
5837
+ pluginHtml((environment)=>async (...args)=>(await context.hooks.modifyHTMLTags.callChain({
5805
5838
  environment,
5806
5839
  args
5807
5840
  }))[0]),
@@ -6071,7 +6104,7 @@ async function createRsbuild(options = {}) {
6071
6104
  });
6072
6105
  }, onExitListened = !1, onExit = (cb)=>{
6073
6106
  onExitListened || (process.on('exit', ()=>{
6074
- hooks.onExit.call();
6107
+ hooks.onExit.callBatch();
6075
6108
  }), onExitListened = !0), hooks.onExit.tap(cb);
6076
6109
  };
6077
6110
  return (environment)=>({
@@ -6149,7 +6182,7 @@ async function createRsbuild(options = {}) {
6149
6182
  return {
6150
6183
  ...buildInstance,
6151
6184
  close: async ()=>{
6152
- await context.hooks.onCloseBuild.call(), await buildInstance.close();
6185
+ await context.hooks.onCloseBuild.callBatch(), await buildInstance.close();
6153
6186
  }
6154
6187
  };
6155
6188
  },
@@ -6543,12 +6576,12 @@ async function runCLI() {
6543
6576
  }
6544
6577
  }(), process.title = 'rsbuild-node';
6545
6578
  let { npm_execpath } = process.env;
6546
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.8\n`);
6579
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.10\n`);
6547
6580
  }();
6548
6581
  try {
6549
6582
  !function() {
6550
6583
  let cli = dist('rsbuild');
6551
- cli.help(), cli.version("1.2.8"), applyCommonOptions(cli);
6584
+ cli.help(), cli.version("1.2.10"), applyCommonOptions(cli);
6552
6585
  let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
6553
6586
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
6554
6587
  try {
@@ -6599,6 +6632,6 @@ async function runCLI() {
6599
6632
  __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);
6600
6633
  }
6601
6634
  }
6602
- let src_version = "1.2.8";
6635
+ let src_version = "1.2.10";
6603
6636
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
6604
6637
  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 };
@@ -5,7 +5,17 @@ import type { CreateCompiler, CreateDevServerOptions, EnvironmentAPI, InternalCo
5
5
  type HTTPServer = Server | Http2SecureServer;
6
6
  export type RsbuildDevServer = {
7
7
  /**
8
- * Listen the Rsbuild server.
8
+ * The `connect` app instance.
9
+ * Can be used to attach custom middlewares to the dev server.
10
+ */
11
+ middlewares: Connect.Server;
12
+ /**
13
+ * The Node.js HTTP server instance.
14
+ * Will be `Http2SecureServer` if `server.https` config is used.
15
+ */
16
+ httpServer: import('node:http').Server | import('node:http2').Http2SecureServer | null;
17
+ /**
18
+ * Start listening on the Rsbuild dev server.
9
19
  * Do not call this method if you are using a custom server.
10
20
  */
11
21
  listen: () => Promise<{
@@ -24,11 +34,6 @@ export type RsbuildDevServer = {
24
34
  * By default, Rsbuild server listens on port `3000` and automatically increments the port number if the port is occupied.
25
35
  */
26
36
  port: number;
27
- /**
28
- * The `connect` app instance.
29
- * Can be used to attach custom middlewares to the dev server.
30
- */
31
- middlewares: Connect.Server;
32
37
  /**
33
38
  * Notify that the Rsbuild server has been started.
34
39
  * Rsbuild will trigger `onAfterStartDevServer` hook in this stage.
@@ -16,6 +16,10 @@ export type RsbuildDevMiddlewareOptions = {
16
16
  output: {
17
17
  distPath: string;
18
18
  };
19
+ /**
20
+ * Callbacks returned by the `onBeforeStartDevServer` hook.
21
+ */
22
+ postCallbacks: (() => void)[];
19
23
  };
20
24
  export type Middlewares = Array<RequestHandler | [string, RequestHandler]>;
21
25
  export type GetMiddlewaresResult = {
@@ -3,6 +3,7 @@ import type { EnvironmentAPI, HtmlFallback, RequestHandler as Middleware, Rspack
3
3
  export declare const faviconFallbackMiddleware: Middleware;
4
4
  export declare const getRequestLoggerMiddleware: () => Promise<Connect.NextHandleFunction>;
5
5
  export declare const notFoundMiddleware: Middleware;
6
+ export declare const optionsFallbackMiddleware: Middleware;
6
7
  /**
7
8
  * Support access HTML without suffix
8
9
  */
@@ -42,7 +42,7 @@ export type OnBeforeStartDevServerFn = (params: {
42
42
  * A read-only object that provides some context information about different environments.
43
43
  */
44
44
  environments: Record<string, EnvironmentContext>;
45
- }) => MaybePromise<void>;
45
+ }) => MaybePromise<(() => void) | void>;
46
46
  export type OnBeforeStartProdServerFn = () => MaybePromise<void>;
47
47
  export type Routes = Array<{
48
48
  entryName: string;
@@ -14,27 +14,82 @@ export type HookDescriptor<T extends (...args: any[]) => any> = {
14
14
  handler: T;
15
15
  order: HookOrder;
16
16
  };
17
- export type EnvironmentAsyncHook<Callback extends (...args: any[]) => any> = {
17
+ export type EnvironmentAsyncHook<Callback extends (...args: any[]) => T, T = any> = {
18
+ /**
19
+ * Registers a callback function to be executed when the hook is triggered.
20
+ * The callback can be a plain function or a HookDescriptor that includes execution order.
21
+ * The callback will be executed in all environments by default.
22
+ * If you need to specify the environment, please use `tapEnvironment`
23
+ * @param cb The callback function or hook descriptor to register
24
+ */
25
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
26
+ /**
27
+ * Registers a callback function to be executed when the hook is triggered.
28
+ * The callback will only be executed under the specified environment.
29
+ */
18
30
  tapEnvironment: (params: {
19
31
  /**
20
- * Specify that the callback will only be executed under the specified environment
32
+ * Specify the environment that the callback will be executed under.
21
33
  */
22
34
  environment?: string;
35
+ /**
36
+ * The callback function or hook descriptor to register
37
+ */
23
38
  handler: Callback | HookDescriptor<Callback>;
24
39
  }) => void;
25
40
  /**
26
- * Triggered in all environments by default.
27
- * If you need to specify the environment, please use `tapEnvironment`
41
+ * Executes callbacks in sequence independently and collects all their results into an array.
42
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
43
+ * @returns A promise that resolves with an array containing the results of all callbacks
28
44
  */
29
- tap: (cb: Callback | HookDescriptor<Callback>) => void;
30
- callInEnvironment: (params: {
45
+ callChain: (params: {
46
+ /**
47
+ * Specify the environment for filtering callbacks.
48
+ */
31
49
  environment?: string;
50
+ /**
51
+ * The parameters to pass to each callback
52
+ */
32
53
  args: Parameters<Callback>;
33
54
  }) => Promise<Parameters<Callback>>;
55
+ /**
56
+ * Executes callbacks in sequence independently and collects all their results into an array.
57
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
58
+ * @returns A promise that resolves with an array containing the results of all callbacks
59
+ */
60
+ callBatch: (params: {
61
+ /**
62
+ * Specify the environment for filtering callbacks.
63
+ */
64
+ environment?: string;
65
+ /**
66
+ * The parameters to pass to each callback
67
+ */
68
+ args: Parameters<Callback>;
69
+ }) => Promise<Awaited<ReturnType<Callback>>[]>;
34
70
  };
35
- export type AsyncHook<Callback extends (...args: any[]) => any> = {
71
+ export type AsyncHook<Callback extends (...args: any[]) => T, T = any> = {
72
+ /**
73
+ * Registers a callback function to be executed when the hook is triggered.
74
+ * The callback can be a plain function or a HookDescriptor that includes execution order.
75
+ * @param cb The callback function or hook descriptor to register
76
+ */
36
77
  tap: (cb: Callback | HookDescriptor<Callback>) => void;
37
- call: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
78
+ /**
79
+ * Executes callbacks in sequence, passing the result of each callback as the first argument
80
+ * to the next callback in the chain. If a callback returns undefined, the original arguments
81
+ * will be passed to the next callback.
82
+ * @param params The initial parameters to pass to the first callback
83
+ * @returns A promise that resolves with the final parameters after all callbacks have executed
84
+ */
85
+ callChain: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
86
+ /**
87
+ * Executes callbacks in sequence independently and collects all their results into an array.
88
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
89
+ * @param params The parameters to pass to each callback
90
+ * @returns A promise that resolves with an array containing the results of all callbacks
91
+ */
92
+ callBatch: (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>[]>;
38
93
  };
39
94
  export type ModifyRspackConfigFn = (config: Rspack.Configuration, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
40
95
  export type ModifyWebpackChainUtils = ModifyChainUtils & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.2.3",
49
+ "@rspack/core": "1.2.5",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.15",
52
52
  "core-js": "~3.40.0"
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@rslib/core": "0.4.1",
56
56
  "@types/connect": "3.4.38",
57
- "@types/node": "^22.13.1",
57
+ "@types/node": "^22.13.4",
58
58
  "@types/on-finished": "2.3.4",
59
59
  "@types/webpack-bundle-analyzer": "4.7.0",
60
60
  "@types/ws": "^8.5.14",
@@ -71,7 +71,7 @@
71
71
  "html-rspack-plugin": "6.0.2",
72
72
  "http-proxy-middleware": "^2.0.6",
73
73
  "jiti": "^1.21.7",
74
- "launch-editor-middleware": "^2.9.1",
74
+ "launch-editor-middleware": "^2.10.0",
75
75
  "mrmime": "^2.0.0",
76
76
  "on-finished": "2.4.1",
77
77
  "open": "^8.4.0",