@rsbuild/core 1.2.7 → 1.2.8

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
@@ -1617,7 +1617,7 @@ async function updateEnvironmentContext(context, configs) {
1617
1617
  async function createContext(options, userConfig, bundlerType) {
1618
1618
  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
1619
  return {
1620
- version: "1.2.7",
1620
+ version: "1.2.8",
1621
1621
  rootPath,
1622
1622
  distPath: '',
1623
1623
  cachePath,
@@ -1944,7 +1944,7 @@ async function validateWebpackCache(cacheDirectory, buildDependencies) {
1944
1944
  recursive: !0
1945
1945
  }), await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.writeFile(configFile, JSON.stringify(buildDependencies));
1946
1946
  }
1947
- async function getBuildDependencies(context, config, environmentContext) {
1947
+ async function getBuildDependencies(context, config, environmentContext, userBuildDependencies) {
1948
1948
  var _config__privateMeta;
1949
1949
  let rootPackageJson = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.rootPath, 'package.json'), browserslistConfig = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.rootPath, '.browserslistrc'), buildDependencies = {};
1950
1950
  await isFileExists(rootPackageJson) && (buildDependencies.packageJson = [
@@ -1966,7 +1966,10 @@ async function getBuildDependencies(context, config, environmentContext) {
1966
1966
  ].map((ext)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.rootPath, `tailwind.config.${ext}`)));
1967
1967
  return tailwindConfig && (buildDependencies.tailwindcss = [
1968
1968
  tailwindConfig
1969
- ]), buildDependencies;
1969
+ ]), {
1970
+ ...buildDependencies,
1971
+ ...userBuildDependencies
1972
+ };
1970
1973
  }
1971
1974
  let pluginCache = ()=>({
1972
1975
  name: 'rsbuild:cache',
@@ -1979,7 +1982,9 @@ let pluginCache = ()=>({
1979
1982
  cacheEnabled = !0;
1980
1983
  let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = function({ cacheDirectory }, context) {
1981
1984
  return cacheDirectory ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.rootPath, cacheDirectory) : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.cachePath, context.bundlerType);
1982
- }(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment);
1985
+ }(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies ? {
1986
+ userBuildDependencies: cacheConfig.buildDependencies
1987
+ } : {});
1983
1988
  'webpack' === bundlerType && await validateWebpackCache(cacheDirectory, buildDependencies);
1984
1989
  let cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${digest = cacheConfig.cacheDigest, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.default.createHash('md5').update(JSON.stringify(digest)).digest('hex').slice(0, 8)}` : `${environment.name}-${env}`;
1985
1990
  'rspack' === bundlerType ? (chain.cache(!0), chain.experiments({
@@ -2271,7 +2276,7 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
2271
2276
  async function gzipSize(input) {
2272
2277
  return (await fileSize_gzip(input)).length;
2273
2278
  }
2274
- let excludeAsset = (asset)=>/\.(?:map|LICENSE\.txt)$/.test(asset.name), getAssetColor = (size)=>size > 300000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.red : size > 100000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green, calcFileSize = (len)=>{
2279
+ let EXCLUDE_ASSET_REGEX = /\.(?:map|LICENSE\.txt|d\.ts)$/, excludeAsset = (asset)=>EXCLUDE_ASSET_REGEX.test(asset.name), getAssetColor = (size)=>size > 300000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.red : size > 100000 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green, calcFileSize = (len)=>{
2275
2280
  let val = len / 1000;
2276
2281
  return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
2277
2282
  }, coloringAssetName = (assetName)=>JS_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(assetName) : CSS_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(assetName) : HTML_REGEX.test(assetName) ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(assetName) : __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.magenta(assetName), COMPRESSIBLE_REGEX = /\.(?:js|css|html|json|svg|txt|xml|xhtml|wasm|manifest)$/i, isCompressible = (assetName)=>COMPRESSIBLE_REGEX.test(assetName);
@@ -2330,7 +2335,7 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
2330
2335
  let totalSize = 0, totalGzipSize = 0;
2331
2336
  for (let asset of assets){
2332
2337
  let { sizeLabel } = asset, { name, folder, gzipSizeLabel } = asset, fileNameLength = (folder + __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.sep + name).length, sizeLength = sizeLabel.length;
2333
- if (totalSize += asset.size, asset.gzippedSize && (totalGzipSize += asset.gzippedSize), !1 !== options.detail) {
2338
+ if (totalSize += asset.size, options.compressed && (totalGzipSize += asset.gzippedSize ?? asset.size), !1 !== options.detail) {
2334
2339
  sizeLength < longestLabelLength && (sizeLabel += ' '.repeat(longestLabelLength - sizeLength));
2335
2340
  let fileNameLabel = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(asset.folder + __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.sep) + coloringAssetName(asset.name);
2336
2341
  fileNameLength < longestFileLength && (fileNameLabel += ' '.repeat(longestFileLength - fileNameLength));
@@ -3450,7 +3455,8 @@ function HtmlPreloadOrPrefetchPlugin_define_property(obj, key, value) {
3450
3455
  }) : obj[key] = value, obj;
3451
3456
  }
3452
3457
  let HtmlPreloadOrPrefetchPlugin_defaultOptions = {
3453
- type: 'async-chunks'
3458
+ type: 'async-chunks',
3459
+ dedupe: !0
3454
3460
  };
3455
3461
  class HtmlPreloadOrPrefetchPlugin {
3456
3462
  apply(compiler) {
@@ -3527,7 +3533,7 @@ class HtmlPreloadOrPrefetchPlugin {
3527
3533
  if (this.resourceHints) {
3528
3534
  var resourceHints, scripts;
3529
3535
  htmlPluginData.assetTags.styles = [
3530
- ...(resourceHints = this.resourceHints, scripts = htmlPluginData.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))),
3536
+ ...this.options.dedupe ? (resourceHints = this.resourceHints, scripts = htmlPluginData.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))) : this.resourceHints,
3531
3537
  ...htmlPluginData.assetTags.styles
3532
3538
  ];
3533
3539
  }
@@ -4879,15 +4885,12 @@ class BasicRunner {
4879
4885
  content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
4880
4886
  subPath: ''
4881
4887
  };
4882
- if (isRelativePath(modulePath)) {
4883
- let p = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, modulePath);
4884
- return {
4885
- path: p,
4886
- content: this._options.readFileSync(p),
4887
- subPath: getSubPath(modulePath)
4888
- };
4889
- }
4890
- return null;
4888
+ let joinedPath = isRelativePath(modulePath) ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, modulePath) : modulePath;
4889
+ return this._options.isBundleOutput(joinedPath) ? {
4890
+ path: joinedPath,
4891
+ content: this._options.readFileSync(joinedPath),
4892
+ subPath: getSubPath(modulePath)
4893
+ } : null;
4891
4894
  }
4892
4895
  preExecute(_code, _file) {}
4893
4896
  postExecute(_m, _file) {}
@@ -4941,7 +4944,14 @@ class CommonJsRunner extends BasicRunner {
4941
4944
  this.requirers.set('miss', this.createMissRequirer()), this.requirers.set('entry', this.createCjsRequirer());
4942
4945
  }
4943
4946
  createMissRequirer() {
4944
- return (_currentDirectory, modulePath, _context = {})=>cjs_require(modulePath.startsWith('node:') ? modulePath.slice(5) : modulePath);
4947
+ return (_currentDirectory, modulePath, _context = {})=>{
4948
+ let resolvedPath = cjs_require.resolve(modulePath, {
4949
+ paths: [
4950
+ _currentDirectory
4951
+ ]
4952
+ });
4953
+ return cjs_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
4954
+ };
4945
4955
  }
4946
4956
  createCjsRequirer() {
4947
4957
  let requireCache = Object.create(null);
@@ -4963,10 +4973,12 @@ class CommonJsRunner extends BasicRunner {
4963
4973
  var type_EsmMode = ((EsmMode = {})[EsmMode.Unknown = 0] = "Unknown", EsmMode[EsmMode.Evaluated = 1] = "Evaluated", EsmMode[EsmMode.Unlinked = 2] = "Unlinked", EsmMode);
4964
4974
  class EsmRunner extends CommonJsRunner {
4965
4975
  createRunner() {
4966
- super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer()), this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
4967
- var _this__options_compilerOptions_experiments;
4976
+ var _this__options_compilerOptions_experiments;
4977
+ super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
4978
+ let outputModule = null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule;
4979
+ this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
4968
4980
  let file = this.getFile(modulePath, currentDirectory);
4969
- return file ? file.path.endsWith('.mjs') && (null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule) ? this.requirers.get('esm')(currentDirectory, modulePath, {
4981
+ return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
4970
4982
  ...context,
4971
4983
  file
4972
4984
  }) : this.requirers.get('cjs')(currentDirectory, modulePath, {
@@ -5008,16 +5020,14 @@ class EsmRunner extends CommonJsRunner {
5008
5020
  }
5009
5021
  }
5010
5022
  class BasicRunnerFactory {
5011
- create(compilerOptions, dist, readFileSync) {
5012
- return this.createRunner(compilerOptions, dist, readFileSync);
5023
+ create(options) {
5024
+ return this.createRunner(options);
5013
5025
  }
5014
- createRunner(compilerOptions, dist, readFileSync) {
5026
+ createRunner(options) {
5015
5027
  let runnerOptions = {
5016
5028
  name: this.name,
5017
- dist,
5018
- compilerOptions,
5019
- readFileSync
5020
- };
5029
+ ...options
5030
+ }, { compilerOptions } = options;
5021
5031
  if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`[rsbuild:runner] Not support run "${compilerOptions.target}" resource in Rsbuild server`);
5022
5032
  return new EsmRunner(runnerOptions);
5023
5033
  }
@@ -5031,7 +5041,7 @@ class BasicRunnerFactory {
5031
5041
  }) : this[key] = value, this.name = name;
5032
5042
  }
5033
5043
  }
5034
- let runner_run = async (bundlePath, outputPath, compilerOptions, readFileSync)=>new BasicRunnerFactory(bundlePath).create(compilerOptions, outputPath, readFileSync).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
5044
+ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
5035
5045
  let { chunks, entrypoints, outputPath } = stats.toJson({
5036
5046
  all: !1,
5037
5047
  chunks: !0,
@@ -5048,7 +5058,14 @@ let runner_run = async (bundlePath, outputPath, compilerOptions, readFileSync)=>
5048
5058
  }, []);
5049
5059
  if (0 === files.length) throw Error(`[rsbuild:loadBundle] Failed to get bundle by entryName: "${entryName}"`);
5050
5060
  if (files.length > 1) throw Error(`[rsbuild:loadBundle] Only support load single entry chunk, but got ${files.length}: ${files.join(',')}`);
5051
- return await runner_run(files[0], outputPath, stats.compilation.options, utils.readFileSync);
5061
+ let allChunkFiles = (null == chunks ? void 0 : chunks.flatMap((c)=>c.files).map((file)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, file))) || [];
5062
+ return await runner_run({
5063
+ bundlePath: files[0],
5064
+ dist: outputPath,
5065
+ compilerOptions: stats.compilation.options,
5066
+ readFileSync: utils.readFileSync,
5067
+ isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
5068
+ });
5052
5069
  }, getTransformedHtml = async (entryName, utils)=>{
5053
5070
  let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
5054
5071
  if (!htmlPath) throw Error(`[rsbuild:getTransformedHtml] Failed to get HTML file by entryName: "${entryName}"`);
@@ -5359,11 +5376,11 @@ let runner_run = async (bundlePath, outputPath, compilerOptions, readFileSync)=>
5359
5376
  return createServer(middlewares);
5360
5377
  }, devServer_formatDevConfig = (config, port)=>('<port>' === config.client.port && (config.client.port = String(port)), config);
5361
5378
  async function devServer_createDevServer(options, createCompiler, config, { compiler: customCompiler, getPortSilently, runCompile = !0 } = {}) {
5362
- let lastStats;
5379
+ let lastStats, fileWatcher, devMiddlewares;
5363
5380
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server');
5364
5381
  let { port, host, https, portTip } = await getServerConfig({
5365
5382
  config
5366
- }), devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(options.context);
5383
+ }), devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(options.context), root = options.context.rootPath;
5367
5384
  options.context.devServer = {
5368
5385
  hostname: host,
5369
5386
  port,
@@ -5397,11 +5414,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5397
5414
  protocol,
5398
5415
  port,
5399
5416
  host
5400
- });
5401
- await options.context.hooks.onBeforeStartDevServer.call({
5402
- environments: options.context.environments
5403
- });
5404
- let cliShortcutsEnabled = isCliShortcutsEnabled(devConfig), printUrls = ()=>printServerURLs({
5417
+ }), cliShortcutsEnabled = isCliShortcutsEnabled(devConfig), printUrls = ()=>printServerURLs({
5405
5418
  urls,
5406
5419
  port,
5407
5420
  routes,
@@ -5416,7 +5429,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5416
5429
  clearCache: !0
5417
5430
  }), closeServer = async ()=>{
5418
5431
  await options.context.hooks.onCloseDevServer.call(), await Promise.all([
5419
- devMiddlewares.close(),
5432
+ null == devMiddlewares ? void 0 : devMiddlewares.close(),
5420
5433
  null == fileWatcher ? void 0 : fileWatcher.close()
5421
5434
  ]);
5422
5435
  }, beforeCreateCompiler = ()=>{
@@ -5434,14 +5447,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5434
5447
  options.context.hooks.onCloseDevServer.tap(cleanup);
5435
5448
  }
5436
5449
  !getPortSilently && portTip && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(portTip);
5437
- };
5438
- runCompile ? options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
5439
- let compileMiddlewareAPI = runCompile ? await startCompile() : void 0, root = options.context.rootPath, fileWatcher = await setupWatchFiles({
5440
- dev: devConfig,
5441
- server: config.server,
5442
- compileMiddlewareAPI,
5443
- root
5444
- }), readFileSync = (fileName)=>'readFileSync' in outputFileSystem ? outputFileSystem.readFileSync(fileName, 'utf-8') : __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(fileName, 'utf-8'), cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>getTransformedHtml(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(options.context.environments).map(([name, environment])=>[
5450
+ }, readFileSync = (fileName)=>'readFileSync' in outputFileSystem ? outputFileSystem.readFileSync(fileName, 'utf-8') : __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(fileName, 'utf-8'), cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>getTransformedHtml(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(options.context.environments).map(([name, environment])=>[
5445
5451
  name,
5446
5452
  {
5447
5453
  getStats: async ()=>{
@@ -5457,19 +5463,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5457
5463
  environment
5458
5464
  }))
5459
5465
  }
5460
- ])), devMiddlewares = await getMiddlewares({
5461
- pwd: root,
5462
- compileMiddlewareAPI,
5463
- dev: devConfig,
5464
- server: config.server,
5465
- environments: environmentAPI,
5466
- output: {
5467
- distPath: options.context.distPath || ROOT_DIST_DIR
5468
- },
5469
- outputFileSystem
5470
- }), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect();
5471
- for (let item of devMiddlewares.middlewares)Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
5472
- let devServerAPI = {
5466
+ ])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), devServerAPI = {
5473
5467
  port,
5474
5468
  middlewares,
5475
5469
  environments: environmentAPI,
@@ -5484,7 +5478,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5484
5478
  port
5485
5479
  }, async (err)=>{
5486
5480
  if (err) throw err;
5487
- middlewares.use(notFoundMiddleware), 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({
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({
5488
5482
  port,
5489
5483
  urls: urls.map((item)=>item.url),
5490
5484
  server: {
@@ -5502,12 +5496,33 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
5502
5496
  });
5503
5497
  },
5504
5498
  connectWebSocket: ({ server })=>{
5505
- server.on('upgrade', devMiddlewares.onUpgrade);
5499
+ devMiddlewares && server.on('upgrade', devMiddlewares.onUpgrade);
5506
5500
  },
5507
5501
  close: closeServer,
5508
5502
  printUrls,
5509
5503
  open: openPage
5510
5504
  };
5505
+ await options.context.hooks.onBeforeStartDevServer.call({
5506
+ server: devServerAPI,
5507
+ environments: options.context.environments
5508
+ }), runCompile ? options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
5509
+ let compileMiddlewareAPI = runCompile ? await startCompile() : void 0;
5510
+ for (let item of (fileWatcher = await setupWatchFiles({
5511
+ dev: devConfig,
5512
+ server: config.server,
5513
+ compileMiddlewareAPI,
5514
+ root
5515
+ }), (devMiddlewares = await getMiddlewares({
5516
+ pwd: root,
5517
+ compileMiddlewareAPI,
5518
+ dev: devConfig,
5519
+ server: config.server,
5520
+ environments: environmentAPI,
5521
+ output: {
5522
+ distPath: options.context.distPath || ROOT_DIST_DIR
5523
+ },
5524
+ outputFileSystem
5525
+ })).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
5511
5526
  return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server done'), devServerAPI;
5512
5527
  }
5513
5528
  async function createCompiler_createCompiler(options) {
@@ -6504,7 +6519,7 @@ class CAC extends __WEBPACK_EXTERNAL_MODULE_events__.EventEmitter {
6504
6519
  }), actionArgs.push(options), command.commandAction.apply(this, actionArgs);
6505
6520
  }
6506
6521
  }
6507
- let cac_dist = (name = "")=>new CAC(name), applyCommonOptions = (cli)=>{
6522
+ let dist = (name = "")=>new CAC(name), applyCommonOptions = (cli)=>{
6508
6523
  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`', {
6509
6524
  default: 'jiti'
6510
6525
  }).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('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', {
@@ -6528,12 +6543,12 @@ async function runCLI() {
6528
6543
  }
6529
6544
  }(), process.title = 'rsbuild-node';
6530
6545
  let { npm_execpath } = process.env;
6531
- (!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.7\n`);
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`);
6532
6547
  }();
6533
6548
  try {
6534
6549
  !function() {
6535
- let cli = cac_dist('rsbuild');
6536
- cli.help(), cli.version("1.2.7"), applyCommonOptions(cli);
6550
+ let cli = dist('rsbuild');
6551
+ cli.help(), cli.version("1.2.8"), applyCommonOptions(cli);
6537
6552
  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');
6538
6553
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
6539
6554
  try {
@@ -6584,6 +6599,6 @@ async function runCLI() {
6584
6599
  __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);
6585
6600
  }
6586
6601
  }
6587
- let src_version = "1.2.7";
6602
+ let src_version = "1.2.8";
6588
6603
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
6589
6604
  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 };
@@ -1,2 +1,5 @@
1
1
  import type { CreateRsbuildOptions, RsbuildInstance } from './types';
2
+ /**
3
+ * Create an Rsbuild instance.
4
+ */
2
5
  export declare function createRsbuild(options?: CreateRsbuildOptions): Promise<RsbuildInstance>;
@@ -16,15 +16,15 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import type { Compiler, RspackPluginInstance } from '@rspack/core';
19
- import type { HtmlRspackPlugin, PreloadOrPreFetchOption } from '../../types';
19
+ import type { HtmlRspackPlugin, PreloadOrPrefetchOption } from '../../types';
20
20
  type LinkType = 'preload' | 'prefetch';
21
21
  export declare class HtmlPreloadOrPrefetchPlugin implements RspackPluginInstance {
22
- readonly options: PreloadOrPreFetchOption;
22
+ readonly options: PreloadOrPrefetchOption;
23
23
  name: string;
24
24
  resourceHints: HtmlRspackPlugin.HtmlTagObject[];
25
25
  type: LinkType;
26
26
  HTMLCount: number;
27
- constructor(options: true | PreloadOrPreFetchOption, type: LinkType, HTMLCount: number);
27
+ constructor(options: true | PreloadOrPrefetchOption, type: LinkType, HTMLCount: number);
28
28
  apply(compiler: Compiler): void;
29
29
  }
30
30
  export {};
@@ -16,13 +16,13 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import type { Chunk, Compilation } from '@rspack/core';
19
- import type { PreloadOrPreFetchOption } from '../../../types';
19
+ import type { PreloadOrPrefetchOption } from '../../../types';
20
20
  import type { BeforeAssetTagGenerationHtmlPluginData } from './type';
21
21
  interface DoesChunkBelongToHtmlOptions {
22
22
  chunk: Chunk;
23
23
  compilation?: Compilation;
24
24
  htmlPluginData: BeforeAssetTagGenerationHtmlPluginData;
25
- pluginOptions?: PreloadOrPreFetchOption;
25
+ pluginOptions?: PreloadOrPrefetchOption;
26
26
  }
27
27
  export declare function recursiveChunkEntryNames(chunk: Chunk): string[];
28
28
  export declare function doesChunkBelongToHtml({ chunk, htmlPluginData, }: DoesChunkBelongToHtmlOptions): boolean;
@@ -18,8 +18,9 @@ export type RsbuildDevMiddlewareOptions = {
18
18
  };
19
19
  };
20
20
  export type Middlewares = Array<RequestHandler | [string, RequestHandler]>;
21
- export declare const getMiddlewares: (options: RsbuildDevMiddlewareOptions) => Promise<{
21
+ export type GetMiddlewaresResult = {
22
22
  close: () => Promise<void>;
23
23
  onUpgrade: UpgradeEvent;
24
24
  middlewares: Middlewares;
25
- }>;
25
+ };
26
+ export declare const getMiddlewares: (options: RsbuildDevMiddlewareOptions) => Promise<GetMiddlewaresResult>;
@@ -2,6 +2,7 @@ import type { CompilerOptions, Runner } from './type';
2
2
  import type { BasicGlobalContext, BasicModuleScope, BasicRunnerFile, ModuleObject, RunnerRequirer } from './type';
3
3
  export interface IBasicRunnerOptions {
4
4
  name: string;
5
+ isBundleOutput: (modulePath: string) => boolean;
5
6
  runInNewContext?: boolean;
6
7
  readFileSync: (path: string) => string;
7
8
  dist: string;
@@ -18,6 +19,11 @@ export declare abstract class BasicRunner implements Runner {
18
19
  protected abstract createGlobalContext(): BasicGlobalContext;
19
20
  protected abstract createBaseModuleScope(): BasicModuleScope;
20
21
  protected abstract createModuleScope(requireFn: RunnerRequirer, m: ModuleObject, file: BasicRunnerFile): BasicModuleScope;
22
+ /**
23
+ * Get the file information for a given module path.
24
+ *
25
+ * @returns An object containing the file path, content, and subPath, or null if the module is not an rspack output.
26
+ */
21
27
  protected getFile(modulePath: string[] | string, currentDirectory: string): BasicRunnerFile | null;
22
28
  protected preExecute(_code: string, _file: BasicRunnerFile): void;
23
29
  protected postExecute(_m: Record<string, any>, _file: BasicRunnerFile): void;
@@ -1,8 +1,10 @@
1
- import type { CompilerOptions, Runner, RunnerFactory } from './type';
1
+ import type { Runner, RunnerFactory, RunnerFactoryOptions } from './type';
2
2
  export declare class BasicRunnerFactory implements RunnerFactory {
3
3
  protected name: string;
4
4
  constructor(name: string);
5
- create(compilerOptions: CompilerOptions, dist: string, readFileSync: (path: string) => string): Runner;
6
- protected createRunner(compilerOptions: CompilerOptions, dist: string, readFileSync: (path: string) => string): Runner;
5
+ create(options: RunnerFactoryOptions): Runner;
6
+ protected createRunner(options: RunnerFactoryOptions): Runner;
7
7
  }
8
- export declare const run: <T>(bundlePath: string, outputPath: string, compilerOptions: CompilerOptions, readFileSync: (path: string) => string) => Promise<T>;
8
+ export declare const run: <T>({ bundlePath, ...runnerFactoryOptions }: RunnerFactoryOptions & {
9
+ bundlePath: string;
10
+ }) => Promise<T>;
@@ -31,6 +31,12 @@ export interface Runner {
31
31
  run(file: string): Promise<unknown>;
32
32
  getRequire(): RunnerRequirer;
33
33
  }
34
+ export type RunnerFactoryOptions = {
35
+ dist: string;
36
+ compilerOptions: CompilerOptions;
37
+ readFileSync: (path: string) => string;
38
+ isBundleOutput: (modulePath: string) => boolean;
39
+ };
34
40
  export interface RunnerFactory {
35
- create(compilerOptions: CompilerOptions, dist: string, readFileSync: (fileName: string) => string): Runner;
41
+ create(options: RunnerFactoryOptions): Runner;
36
42
  }
@@ -7,8 +7,9 @@ type WatchFilesOptions = {
7
7
  compileMiddlewareAPI?: CompileMiddlewareAPI;
8
8
  root: string;
9
9
  };
10
- export declare function setupWatchFiles(options: WatchFilesOptions): Promise<{
10
+ export type WatchFilesResult = {
11
11
  close(): Promise<void>;
12
- } | undefined>;
12
+ };
13
+ export declare function setupWatchFiles(options: WatchFilesOptions): Promise<WatchFilesResult | undefined>;
13
14
  export declare function createChokidar(pathOrGlobs: string[], root: string, options: ChokidarOptions): Promise<FSWatcher>;
14
15
  export {};
@@ -336,6 +336,11 @@ export type BuildCacheOptions = {
336
336
  * @default undefined
337
337
  */
338
338
  cacheDigest?: Array<string | undefined>;
339
+ /**
340
+ * An array of files containing build dependencies.
341
+ * Rspack will use the hash of each of these files to invalidate the persistent cache.
342
+ */
343
+ buildDependencies?: string[];
339
344
  };
340
345
  export type PrintFileSizeAsset = {
341
346
  /**
@@ -393,11 +398,14 @@ export type Preconnect = Array<string | PreconnectOption>;
393
398
  export type DnsPrefetch = string[];
394
399
  export type PreloadIncludeType = 'async-chunks' | 'initial' | 'all-assets' | 'all-chunks';
395
400
  export type Filter = Array<string | RegExp> | ((filename: string) => boolean);
396
- export interface PreloadOrPreFetchOption {
401
+ export interface PreloadOrPrefetchOption {
397
402
  type?: PreloadIncludeType;
398
403
  include?: Filter;
399
404
  exclude?: Filter;
405
+ dedupe?: boolean;
400
406
  }
407
+ export type PreloadOption = PreloadOrPrefetchOption;
408
+ export type PrefetchOption = Omit<PreloadOrPrefetchOption, 'dedupe'>;
401
409
  export interface PerformanceConfig {
402
410
  /**
403
411
  * Whether to remove `console.[methodName]` in production build.
@@ -441,14 +449,14 @@ export interface PerformanceConfig {
441
449
  *
442
450
  * Specifies that the user agent must preemptively fetch and cache the target resource for current navigation.
443
451
  */
444
- preload?: true | PreloadOrPreFetchOption;
452
+ preload?: true | PreloadOption;
445
453
  /**
446
454
  * Used to control resource `Prefetch`.
447
455
  *
448
456
  * Specifies that the user agent should preemptively fetch and cache the target resource as it
449
457
  * is likely to be required for a followup navigation.
450
458
  */
451
- prefetch?: true | PreloadOrPreFetchOption;
459
+ prefetch?: true | PrefetchOption;
452
460
  /**
453
461
  * Whether capture timing information for each module,
454
462
  * same as the [profile](https://webpack.js.org/configuration/other-options/#profile) config of webpack.
@@ -1,5 +1,6 @@
1
1
  import type { ChainIdentifier } from '..';
2
2
  import type RspackChain from '../../compiled/rspack-chain/index.js';
3
+ import type { RsbuildDevServer } from '../server/devServer';
3
4
  import type { EnvironmentConfig, HtmlBasicTag, MergedEnvironmentConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
4
5
  import type { RsbuildEntry, RsbuildTarget } from './rsbuild';
5
6
  import type { Rspack } from './rspack';
@@ -33,6 +34,13 @@ export type OnDevCompileDoneFn = (params: {
33
34
  environments: Record<string, EnvironmentContext>;
34
35
  }) => MaybePromise<void>;
35
36
  export type OnBeforeStartDevServerFn = (params: {
37
+ /**
38
+ * The dev server instance, the same as the return value of `createDevServer`.
39
+ */
40
+ server: RsbuildDevServer;
41
+ /**
42
+ * A read-only object that provides some context information about different environments.
43
+ */
36
44
  environments: Record<string, EnvironmentContext>;
37
45
  }) => MaybePromise<void>;
38
46
  export type OnBeforeStartProdServerFn = () => MaybePromise<void>;