@rsbuild/core 1.3.8 → 1.3.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
@@ -97,7 +97,7 @@ var EsmMode, __webpack_modules__ = {
97
97
  }, {});
98
98
  }, module.exports = deepmerge;
99
99
  },
100
- "../../node_modules/.pnpm/dotenv-expand@12.0.1/node_modules/dotenv-expand/lib/main.js": function(module) {
100
+ "../../node_modules/.pnpm/dotenv-expand@12.0.2/node_modules/dotenv-expand/lib/main.js": function(module) {
101
101
  function _resolveEscapeSequences(value) {
102
102
  return value.replace(/\\\$/g, '$');
103
103
  }
@@ -942,7 +942,7 @@ __webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(p
942
942
  setHTMLPlugin: ()=>setHTMLPlugin,
943
943
  stringifyConfig: ()=>stringifyConfig
944
944
  });
945
- var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js"), lib_main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@12.0.1/node_modules/dotenv-expand/lib/main.js"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs);
945
+ var main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js"), lib_main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@12.0.2/node_modules/dotenv-expand/lib/main.js"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs);
946
946
  let constants_filename = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url), constants_dirname = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(constants_filename), ROOT_DIST_DIR = 'dist', LOADER_PATH = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_dirname), STATIC_PATH = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_dirname, '../static'), COMPILED_PATH = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
947
947
  'chrome >= 87',
948
948
  'edge >= 88',
@@ -1057,13 +1057,15 @@ async function emptyDir(dir, keep = [], checkExists = !0) {
1057
1057
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`failed to empty dir: ${dir}`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(err);
1058
1058
  }
1059
1059
  }
1060
- let formatFileName = (fileName)=>/:\d+:\d+/.test(fileName) ? `File: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(fileName)}\n` : `File: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(fileName)}:1:1\n`, hintNodePolyfill = (message)=>{
1060
+ let formatFileName = (fileName)=>/:\d+:\d+/.test(fileName) ? `File: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(fileName)}\n` : `File: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan(`${fileName}:1:1`)}\n`, hintNodePolyfill = (message)=>{
1061
1061
  let getTips = (moduleName)=>{
1062
1062
  let tips = [
1063
- `Tip: "${moduleName}" is a built-in Node.js module. It cannot be imported in client-side code.`,
1064
- `Check if you need to import Node.js module. If needed, you can use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan('@rsbuild/plugin-node-polyfill')}" to polyfill it.`
1063
+ `Error: "${moduleName}" is a built-in Node.js module and cannot be imported in client-side code.\n`,
1064
+ 'Solution: Check if you need to import Node.js module.',
1065
+ ' - If not needed, remove the import.',
1066
+ ` - If needed, use "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('@rsbuild/plugin-node-polyfill')}" to polyfill it. (See ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('https://npmjs.com/package/@rsbuild/plugin-node-polyfill')})`
1065
1067
  ];
1066
- return `${message}\n\n${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(tips.join('\n'))}`;
1068
+ return `${message}\n\n${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.red(tips.join('\n'))}`;
1067
1069
  };
1068
1070
  if (message.includes('need an additional plugin to handle "node:" URIs')) return getTips('node:*');
1069
1071
  if (!message.includes("Can't resolve")) return message;
@@ -2115,7 +2117,7 @@ async function updateEnvironmentContext(context, configs) {
2115
2117
  async function createContext(options, userConfig) {
2116
2118
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
2117
2119
  return {
2118
- version: "1.3.8",
2120
+ version: "1.3.10",
2119
2121
  rootPath,
2120
2122
  distPath: '',
2121
2123
  cachePath,
@@ -2677,7 +2679,8 @@ let pluginHelper_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.
2677
2679
  }
2678
2680
  }), getCSSModulesLocalIdentName = (config, isProd)=>config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), getLightningCSSLoaderOptions = (config, targets, minify)=>{
2679
2681
  let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
2680
- targets
2682
+ targets,
2683
+ errorRecovery: !0
2681
2684
  };
2682
2685
  return minify && (initialOptions.minify = !0), reduceConfigs({
2683
2686
  initial: initialOptions,
@@ -3339,13 +3342,19 @@ function updateSourceMappingURL({ source, compilation, publicPath, type, config
3339
3342
  }
3340
3343
  return source;
3341
3344
  }
3342
- function matchTests(name, source, tests) {
3345
+ function matchTests(name, asset, tests) {
3343
3346
  return tests.some((test)=>isFunction(test) ? test({
3344
3347
  name,
3345
- size: source.length
3348
+ size: asset.size()
3346
3349
  }) : test.exec(name));
3347
3350
  }
3348
- let pluginInlineChunk = ()=>({
3351
+ let getInlineTests = (config)=>{
3352
+ let isProd = 'production' === config.mode, { inlineStyles, inlineScripts } = config.output, scriptTests = [], styleTests = [];
3353
+ return inlineScripts && (!0 === inlineScripts ? isProd && scriptTests.push(JS_REGEX) : (0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(inlineScripts) || isFunction(inlineScripts) ? isProd && scriptTests.push(inlineScripts) : ('auto' === inlineScripts.enable ? isProd : inlineScripts.enable) && scriptTests.push(inlineScripts.test)), inlineStyles && (!0 === inlineStyles ? isProd && styleTests.push(CSS_REGEX) : (0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(inlineStyles) || isFunction(inlineStyles) ? isProd && styleTests.push(inlineStyles) : ('auto' === inlineStyles.enable ? isProd : inlineStyles.enable) && styleTests.push(inlineStyles.test)), {
3354
+ scriptTests,
3355
+ styleTests
3356
+ };
3357
+ }, pluginInlineChunk = ()=>({
3349
3358
  name: 'rsbuild:inline-chunk',
3350
3359
  setup (api) {
3351
3360
  let inlinedAssets = new Set(), getInlinedScriptTag = (publicPath, tag, compilation, scriptTests, config)=>{
@@ -3353,13 +3362,11 @@ let pluginInlineChunk = ()=>({
3353
3362
  let { assets } = compilation;
3354
3363
  if (!((null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.src) && 'string' == typeof tag.attrs.src)) return tag;
3355
3364
  let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = assets[scriptName];
3356
- if (null == asset) return tag;
3357
- let source = asset.source().toString();
3358
- if (!matchTests(scriptName, source, scriptTests)) return tag;
3365
+ if (null == asset || !matchTests(scriptName, asset, scriptTests)) return tag;
3359
3366
  let ret = {
3360
3367
  tag: "script",
3361
3368
  children: updateSourceMappingURL({
3362
- source,
3369
+ source: asset.source().toString(),
3363
3370
  compilation,
3364
3371
  publicPath,
3365
3372
  type: 'js',
@@ -3375,13 +3382,11 @@ let pluginInlineChunk = ()=>({
3375
3382
  let { assets } = compilation;
3376
3383
  if (!((null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.href) && 'string' == typeof tag.attrs.href)) return tag;
3377
3384
  let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = assets[linkName];
3378
- if (null == asset) return tag;
3379
- let source = asset.source().toString();
3380
- if (!matchTests(linkName, source, styleTests)) return tag;
3385
+ if (null == asset || !matchTests(linkName, asset, styleTests)) return tag;
3381
3386
  let ret = {
3382
3387
  tag: 'style',
3383
3388
  children: updateSourceMappingURL({
3384
- source,
3389
+ source: asset.source().toString(),
3385
3390
  compilation,
3386
3391
  publicPath,
3387
3392
  type: 'css',
@@ -3403,8 +3408,8 @@ let pluginInlineChunk = ()=>({
3403
3408
  headTags,
3404
3409
  bodyTags
3405
3410
  };
3406
- let { inlineStyles, inlineScripts } = config.output, scriptTests = [], styleTests = [], isProdMode = 'production' === environment.config.mode;
3407
- if (inlineScripts && (!0 === inlineScripts ? isProdMode && scriptTests.push(JS_REGEX) : (0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(inlineScripts) || isFunction(inlineScripts) ? isProdMode && scriptTests.push(inlineScripts) : ('auto' === inlineScripts.enable ? isProdMode : inlineScripts.enable) && scriptTests.push(inlineScripts.test)), inlineStyles && (!0 === inlineStyles ? isProdMode && styleTests.push(CSS_REGEX) : (0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(inlineStyles) || isFunction(inlineStyles) ? isProdMode && styleTests.push(inlineStyles) : ('auto' === inlineStyles.enable ? isProdMode : inlineStyles.enable) && styleTests.push(inlineStyles.test)), !scriptTests.length && !styleTests.length) return {
3411
+ let { scriptTests, styleTests } = getInlineTests(config);
3412
+ if (!scriptTests.length && !styleTests.length) return {
3408
3413
  headTags,
3409
3414
  bodyTags
3410
3415
  };
@@ -3416,9 +3421,6 @@ let pluginInlineChunk = ()=>({
3416
3421
  });
3417
3422
  }
3418
3423
  });
3419
- function isAsync(chunk) {
3420
- return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
3421
- }
3422
3424
  function recursiveChunkEntryNames(chunk) {
3423
3425
  let [...chunkGroups] = chunk.groupsIterable;
3424
3426
  return [
@@ -3995,7 +3997,10 @@ let getJsAsyncPath = (jsPath, isServer, jsAsync)=>void 0 !== jsAsync ? jsAsync :
3995
3997
  });
3996
3998
  }
3997
3999
  });
3998
- function HtmlPreloadOrPrefetchPlugin_define_property(obj, key, value) {
4000
+ function isAsyncChunk(chunk) {
4001
+ return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
4002
+ }
4003
+ function HtmlResourceHintsPlugin_define_property(obj, key, value) {
3999
4004
  return key in obj ? Object.defineProperty(obj, key, {
4000
4005
  value: value,
4001
4006
  enumerable: !0,
@@ -4003,20 +4008,35 @@ function HtmlPreloadOrPrefetchPlugin_define_property(obj, key, value) {
4003
4008
  writable: !0
4004
4009
  }) : obj[key] = value, obj;
4005
4010
  }
4006
- let HtmlPreloadOrPrefetchPlugin_defaultOptions = {
4011
+ let HtmlResourceHintsPlugin_defaultOptions = {
4007
4012
  type: 'async-chunks',
4008
- dedupe: !0
4013
+ dedupe: !0,
4014
+ exclude: /.map$/
4015
+ }, applyFilter = (files, include, exclude)=>{
4016
+ let includeRegExp = [], excludeRegExp = [], includeFn = [], excludeFn = [];
4017
+ if (include) for (let item of castArray(include))'string' == typeof item ? includeRegExp.push(new RegExp(item)) : isFunction(item) ? includeFn.push(item) : includeRegExp.push(item);
4018
+ if (exclude) for (let item of castArray(exclude))'string' == typeof item ? excludeRegExp.push(new RegExp(item)) : isFunction(item) ? excludeFn.push(item) : excludeRegExp.push(item);
4019
+ return files.filter((file)=>{
4020
+ let includeMatched = !1;
4021
+ for (let item of includeRegExp)item.test(file) && (includeMatched = !0);
4022
+ for (let item of includeFn)item(file) && (includeMatched = !0);
4023
+ if (includeRegExp.length + includeFn.length > 0 && !includeMatched) return !1;
4024
+ for (let item of excludeRegExp)if (item.test(file)) return !1;
4025
+ for (let item of excludeFn)if (item(file)) return !1;
4026
+ return !0;
4027
+ });
4009
4028
  };
4010
- class HtmlPreloadOrPrefetchPlugin {
4029
+ class HtmlResourceHintsPlugin {
4011
4030
  apply(compiler) {
4012
4031
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
4013
- getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(`HTML${upperFirst(this.type)}Plugin`, (htmlPluginData)=>(this.resourceHints = function(options, type, compilation, htmlPluginData, HTMLCount) {
4014
- let extractedChunks = function({ compilation, includeType }) {
4032
+ let pluginHooks = getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
4033
+ pluginHooks.beforeAssetTagGeneration.tap(pluginName, (data)=>(this.resourceHints = function(options, type, compilation, data, HTMLCount) {
4034
+ let extractedChunks = function(compilation, includeType) {
4015
4035
  let chunks = [
4016
4036
  ...compilation.chunks
4017
4037
  ];
4018
- if (void 0 === includeType || 'async-chunks' === includeType) return chunks.filter(isAsync);
4019
- if ('initial' === includeType) return chunks.filter((chunk)=>!isAsync(chunk));
4038
+ if (void 0 === includeType || 'async-chunks' === includeType) return chunks.filter(isAsyncChunk);
4039
+ if ('initial' === includeType) return chunks.filter((chunk)=>!isAsyncChunk(chunk));
4020
4040
  if ('all-chunks' === includeType) return chunks;
4021
4041
  if ('all-assets' === includeType) {
4022
4042
  var _compilation_assetsInfo;
@@ -4033,10 +4053,7 @@ class HtmlPreloadOrPrefetchPlugin {
4033
4053
  ];
4034
4054
  }
4035
4055
  return chunks;
4036
- }({
4037
- compilation,
4038
- includeType: options.type
4039
- }), sortedFilteredFiles = [
4056
+ }(compilation, options.type), sortedFilteredFiles = applyFilter([
4040
4057
  ...new Set(('all-assets' === options.type || 1 === HTMLCount ? extractedChunks : extractedChunks.filter((chunk)=>(function({ chunk, htmlPluginData }) {
4041
4058
  let { options } = htmlPluginData.plugin;
4042
4059
  return recursiveChunkEntryNames(chunk).some((chunkName)=>{
@@ -4046,15 +4063,13 @@ class HtmlPreloadOrPrefetchPlugin {
4046
4063
  })({
4047
4064
  chunk: chunk,
4048
4065
  compilation,
4049
- htmlPluginData,
4066
+ htmlPluginData: data,
4050
4067
  pluginOptions: options
4051
4068
  }))).reduce((accumulated, chunk)=>accumulated.concat([
4052
4069
  ...chunk.files,
4053
4070
  ...chunk.auxiliaryFiles || []
4054
4071
  ]), []))
4055
- ].filter((file)=>[
4056
- /.map$/
4057
- ].every((regex)=>!regex.test(file))).filter((file)=>!options.include || ('function' == typeof options.include ? options.include(file) : options.include.some((regex)=>new RegExp(regex).test(file)))).filter((file)=>!options.exclude || ('function' == typeof options.exclude ? !options.exclude(file) : options.exclude.every((regex)=>!new RegExp(regex).test(file)))).sort(), links = [], { publicPath, crossOriginLoading } = compilation.outputOptions;
4072
+ ], options.include, options.exclude).sort(), links = [], { publicPath, crossOriginLoading } = compilation.outputOptions;
4058
4073
  for (let file of sortedFilteredFiles){
4059
4074
  let href = ensureAssetPrefix(file, publicPath), attributes = {
4060
4075
  href,
@@ -4078,19 +4093,19 @@ class HtmlPreloadOrPrefetchPlugin {
4078
4093
  });
4079
4094
  }
4080
4095
  return links;
4081
- }(this.options, this.type, compilation, htmlPluginData, this.HTMLCount), htmlPluginData)), getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(`HTML${upperFirst(this.type)}Plugin`, (htmlPluginData)=>{
4096
+ }(this.options, this.type, compilation, data, this.HTMLCount), data)), pluginHooks.alterAssetTags.tap(pluginName, (data)=>{
4082
4097
  var resourceHints, scripts;
4083
- return this.resourceHints && (htmlPluginData.assetTags.styles = [
4084
- ...this.options.dedupe ? (resourceHints = this.resourceHints, scripts = htmlPluginData.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))) : this.resourceHints,
4085
- ...htmlPluginData.assetTags.styles
4086
- ]), htmlPluginData;
4098
+ return this.resourceHints && (data.assetTags.styles = [
4099
+ ...this.options.dedupe ? (resourceHints = this.resourceHints, scripts = data.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))) : this.resourceHints,
4100
+ ...data.assetTags.styles
4101
+ ]), data;
4087
4102
  });
4088
4103
  });
4089
4104
  }
4090
4105
  constructor(options, type, HTMLCount){
4091
- HtmlPreloadOrPrefetchPlugin_define_property(this, "options", void 0), HtmlPreloadOrPrefetchPlugin_define_property(this, "name", 'HtmlPreloadOrPrefetchPlugin'), HtmlPreloadOrPrefetchPlugin_define_property(this, "resourceHints", []), HtmlPreloadOrPrefetchPlugin_define_property(this, "type", void 0), HtmlPreloadOrPrefetchPlugin_define_property(this, "HTMLCount", void 0), this.options = {
4092
- ...HtmlPreloadOrPrefetchPlugin_defaultOptions,
4093
- ...'boolean' == typeof options ? {} : options
4106
+ HtmlResourceHintsPlugin_define_property(this, "options", void 0), HtmlResourceHintsPlugin_define_property(this, "name", 'HtmlResourceHintsPlugin'), HtmlResourceHintsPlugin_define_property(this, "resourceHints", []), HtmlResourceHintsPlugin_define_property(this, "type", void 0), HtmlResourceHintsPlugin_define_property(this, "HTMLCount", void 0), this.options = {
4107
+ ...HtmlResourceHintsPlugin_defaultOptions,
4108
+ ...options
4094
4109
  }, this.type = type, this.HTMLCount = HTMLCount;
4095
4110
  }
4096
4111
  }
@@ -4100,7 +4115,13 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4100
4115
  rel,
4101
4116
  ...option
4102
4117
  }
4103
- })), pluginResourceHints = ()=>({
4118
+ })), getInlineExcludes = (config)=>{
4119
+ let { scriptTests, styleTests } = getInlineTests(config);
4120
+ return [
4121
+ ...scriptTests,
4122
+ ...styleTests
4123
+ ].filter((item)=>(0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(item));
4124
+ }, pluginResourceHints = ()=>({
4104
4125
  name: 'rsbuild:resource-hints',
4105
4126
  setup (api) {
4106
4127
  api.modifyHTMLTags(({ headTags, bodyTags }, { environment })=>{
@@ -4124,16 +4145,29 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4124
4145
  }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
4125
4146
  let { config, htmlPaths } = environment;
4126
4147
  if (0 === Object.keys(htmlPaths).length) return;
4127
- let { performance: { preload, prefetch } } = config, HTMLCount = chain.entryPoints.values().length;
4128
- prefetch && chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlPreloadOrPrefetchPlugin, [
4129
- prefetch,
4130
- 'prefetch',
4131
- HTMLCount
4132
- ]), preload && chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlPreloadOrPrefetchPlugin, [
4133
- preload,
4134
- 'preload',
4135
- HTMLCount
4136
- ]);
4148
+ let { performance: { preload, prefetch } } = config, HTMLCount = chain.entryPoints.values().length, excludes = getInlineExcludes(config);
4149
+ if (prefetch) {
4150
+ let options = !0 === prefetch ? {} : prefetch;
4151
+ excludes.length && (options.exclude = options.exclude ? [
4152
+ ...castArray(options.exclude),
4153
+ ...excludes
4154
+ ] : excludes), chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlResourceHintsPlugin, [
4155
+ options,
4156
+ 'prefetch',
4157
+ HTMLCount
4158
+ ]);
4159
+ }
4160
+ if (preload) {
4161
+ let options = !0 === preload ? {} : preload;
4162
+ excludes.length && (options.exclude = options.exclude ? [
4163
+ ...castArray(options.exclude),
4164
+ ...excludes
4165
+ ] : excludes), chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlResourceHintsPlugin, [
4166
+ options,
4167
+ 'preload',
4168
+ HTMLCount
4169
+ ]);
4170
+ }
4137
4171
  });
4138
4172
  }
4139
4173
  }), rsdoctor_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), pluginRsdoctor = ()=>({
@@ -7290,11 +7324,11 @@ async function runCLI() {
7290
7324
  }
7291
7325
  process.title = 'rsbuild-node';
7292
7326
  let { npm_execpath } = process.env;
7293
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.3.8\n`);
7327
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.3.10\n`);
7294
7328
  try {
7295
7329
  !function() {
7296
7330
  let cli = cac_dist('rsbuild');
7297
- cli.help(), cli.version("1.3.8"), applyCommonOptions(cli);
7331
+ cli.help(), cli.version("1.3.10"), applyCommonOptions(cli);
7298
7332
  let devCommand = cli.command('', 'starting the dev server').alias('dev'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
7299
7333
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7300
7334
  try {
@@ -7345,6 +7379,6 @@ async function runCLI() {
7345
7379
  __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);
7346
7380
  }
7347
7381
  }
7348
- let src_version = "1.3.8";
7382
+ let src_version = "1.3.10";
7349
7383
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
7350
7384
  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 };
@@ -125,9 +125,9 @@ export declare const CHAIN_ID: {
125
125
  readonly BUNDLE_ANALYZER: "bundle-analyze";
126
126
  /** ModuleFederationPlugin */
127
127
  readonly MODULE_FEDERATION: "module-federation";
128
- /** htmlPrefetchPlugin */
128
+ /** HtmlResourceHintsPlugin (prefetch) */
129
129
  readonly HTML_PREFETCH: "html-prefetch-plugin";
130
- /** htmlPreloadPlugin */
130
+ /** HtmlResourceHintsPlugin (preload) */
131
131
  readonly HTML_PRELOAD: "html-preload-plugin";
132
132
  /** CssExtractRspackPlugin */
133
133
  readonly MINI_CSS_EXTRACT: "mini-css-extract";
@@ -15,7 +15,7 @@ export { logger } from './logger';
15
15
  export { mergeRsbuildConfig } from './mergeConfig';
16
16
  export { ensureAssetPrefix } from './helpers';
17
17
  export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME } from './constants';
18
- export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, Charset, ClientConfig, CliShortcut, CleanDistPath, CleanDistPathObject, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InternalContext, LegalComments, ManifestData, ManifestConfig, ManifestObjectConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigFn, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterEnvironmentCompileFn, OnBeforeEnvironmentCompileFn, OnCloseBuildFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PreloadIncludeType, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
18
+ export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, Charset, ClientConfig, CliShortcut, CleanDistPath, CleanDistPathObject, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InternalContext, LegalComments, ManifestData, ManifestConfig, ManifestObjectConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigFn, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterEnvironmentCompileFn, OnBeforeEnvironmentCompileFn, OnCloseBuildFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, ResourceHintsIncludeType, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
19
19
  export type { ChainIdentifier } from './configChain';
20
20
  export type { RsbuildDevServer } from './server/devServer';
21
21
  export type { StartServerResult } from './server/helper';
@@ -1,2 +1,6 @@
1
- import type { RsbuildPlugin } from '../types';
1
+ import type { InlineChunkTest, NormalizedEnvironmentConfig, RsbuildPlugin } from '../types';
2
+ export declare const getInlineTests: (config: NormalizedEnvironmentConfig) => {
3
+ scriptTests: InlineChunkTest[];
4
+ styleTests: InlineChunkTest[];
5
+ };
2
6
  export declare const pluginInlineChunk: () => RsbuildPlugin;
@@ -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, ResourceHintsOptions } from '../../types';
20
20
  type LinkType = 'preload' | 'prefetch';
21
- export declare class HtmlPreloadOrPrefetchPlugin implements RspackPluginInstance {
22
- readonly options: PreloadOrPrefetchOption;
21
+ export declare class HtmlResourceHintsPlugin implements RspackPluginInstance {
22
+ readonly options: ResourceHintsOptions;
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: ResourceHintsOptions, 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';
20
- import type { BeforeAssetTagGenerationHtmlPluginData } from './type';
19
+ import type { ResourceHintsOptions } from '../../types';
20
+ import type { HtmlRspackPlugin } from '../../types';
21
21
  interface DoesChunkBelongToHtmlOptions {
22
22
  chunk: Chunk;
23
23
  compilation?: Compilation;
24
- htmlPluginData: BeforeAssetTagGenerationHtmlPluginData;
25
- pluginOptions?: PreloadOrPrefetchOption;
24
+ htmlPluginData: HtmlRspackPlugin.BeforeAssetTagGenerationData;
25
+ pluginOptions?: ResourceHintsOptions;
26
26
  }
27
27
  export declare function recursiveChunkEntryNames(chunk: Chunk): string[];
28
28
  export declare function doesChunkBelongToHtml({ chunk, htmlPluginData, }: DoesChunkBelongToHtmlOptions): boolean;
@@ -16,13 +16,8 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import type { Chunk, Compilation } from '@rspack/core';
19
- import type { PreloadIncludeType } from '../../../types';
20
- interface ExtractChunks {
21
- compilation: Compilation;
22
- includeType?: PreloadIncludeType;
23
- }
24
- export declare function extractChunks({ compilation, includeType }: ExtractChunks): Chunk[] | Array<{
19
+ import type { ResourceHintsIncludeType } from '../../types';
20
+ export declare function extractChunks(compilation: Compilation, includeType?: ResourceHintsIncludeType): Chunk[] | Array<{
25
21
  files: string[];
26
22
  auxiliaryFiles?: string[];
27
23
  }>;
28
- export {};
@@ -15,8 +15,8 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- import type { As } from './type';
19
- export declare function determineAsValue({ href, file, }: {
18
+ export type ResourceType = 'audio' | 'document' | 'embed' | 'fetch' | 'font' | 'image' | 'object' | 'script' | 'style' | 'track' | 'worker' | 'video';
19
+ export declare function getResourceType({ href, file, }: {
20
20
  href: string;
21
21
  file: string;
22
- }): As;
22
+ }): ResourceType;
@@ -435,16 +435,38 @@ export interface PreconnectOption {
435
435
  }
436
436
  export type Preconnect = Array<string | PreconnectOption>;
437
437
  export type DnsPrefetch = string[];
438
- export type PreloadIncludeType = 'async-chunks' | 'initial' | 'all-assets' | 'all-chunks';
439
- export type Filter = Array<string | RegExp> | ((filename: string) => boolean);
440
- export interface PreloadOrPrefetchOption {
441
- type?: PreloadIncludeType;
442
- include?: Filter;
443
- exclude?: Filter;
438
+ export type ResourceHintsIncludeType = 'async-chunks' | 'initial' | 'all-assets' | 'all-chunks';
439
+ export type ResourceHintsFilterFn = (filename: string) => boolean;
440
+ export type ResourceHintsFilter = OneOrMany<string | RegExp | ResourceHintsFilterFn>;
441
+ export interface ResourceHintsOptions {
442
+ /**
443
+ * Specifies which types of resources will be included.
444
+ * - `async-chunks`: Includes all async resources on the current page, such as async JS
445
+ * chunks, and its associated CSS, images, fonts, and other static resources.
446
+ * - `initial`: Includes all non-async resources on the current page.
447
+ * - `all-chunks`: Includes all async and non-async resources on the current page.
448
+ * - `all-assets`: Includes all resources from all pages.
449
+ * @default 'async-chunks'
450
+ */
451
+ type?: ResourceHintsIncludeType;
452
+ /**
453
+ * A extra filter to determine which resources to include.
454
+ */
455
+ include?: ResourceHintsFilter;
456
+ /**
457
+ * A extra filter to determine which resources to exclude.
458
+ */
459
+ exclude?: ResourceHintsFilter;
460
+ /**
461
+ * Whether to dedupe script resources that already exist in the current HTML content.
462
+ * By default, if a resource has been added to the current HTML via a script tag, it will
463
+ * not be preloaded additionally.
464
+ * @default true
465
+ */
444
466
  dedupe?: boolean;
445
467
  }
446
- export type PreloadOption = PreloadOrPrefetchOption;
447
- export type PrefetchOption = Omit<PreloadOrPrefetchOption, 'dedupe'>;
468
+ export type PreloadOptions = ResourceHintsOptions;
469
+ export type PrefetchOptions = Omit<ResourceHintsOptions, 'dedupe'>;
448
470
  export interface PerformanceConfig {
449
471
  /**
450
472
  * Whether to remove `console.[methodName]` in production build.
@@ -485,19 +507,37 @@ export interface PerformanceConfig {
485
507
  */
486
508
  dnsPrefetch?: DnsPrefetch;
487
509
  /**
488
- * Used to control resource `Preload`.
510
+ * Inject the `<link rel="preload">` tags for the static assets generated by Rsbuild.
511
+ *
512
+ * `performance.preload` can be set to an object to specify the options.
489
513
  *
490
- * Specifies that the user agent must preemptively fetch and cache the target resource for
491
- * current navigation.
514
+ * When `performance.preload` is set to `true`, Rsbuild will use the following default options
515
+ * to preload resources. This means preloading all async resources on the current page, including
516
+ * async JS and its associated CSS, image, font, and other resources.
517
+ *
518
+ * ```js
519
+ * const defaultOptions = {
520
+ * type: 'async-chunks',
521
+ * };
522
+ * ```
492
523
  */
493
- preload?: true | PreloadOption;
524
+ preload?: true | PreloadOptions;
494
525
  /**
495
- * Used to control resource `Prefetch`.
526
+ * Inject the `<link rel="prefetch">` tags for the static assets generated by Rsbuild.
527
+ *
528
+ * `performance.prefetch` can be set to an object to specify the options.
496
529
  *
497
- * Specifies that the user agent should preemptively fetch and cache the target resource as it
498
- * is likely to be required for a followup navigation.
530
+ * When `performance.prefetch` is set to `true`, Rsbuild will use the following default options
531
+ * to prefetch resources. This means prefetching all async resources on the current page, including
532
+ * async JS and its associated CSS, image, font, and other resources.
533
+ *
534
+ * ```js
535
+ * const defaultOptions = {
536
+ * type: 'async-chunks',
537
+ * };
538
+ * ```
499
539
  */
500
- prefetch?: true | PrefetchOption;
540
+ prefetch?: true | PrefetchOptions;
501
541
  /**
502
542
  * Whether capture timing information for each module,
503
543
  * same as the [profile](https://rspack.dev/config/other-options#profile) config of Rspack.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -53,7 +53,7 @@
53
53
  "jiti": "^2.4.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@rslib/core": "0.6.3",
56
+ "@rslib/core": "0.6.6",
57
57
  "@types/connect": "3.4.38",
58
58
  "@types/cors": "^2.8.17",
59
59
  "@types/node": "^22.14.1",
@@ -69,8 +69,8 @@
69
69
  "css-loader": "7.1.2",
70
70
  "deepmerge": "^4.3.1",
71
71
  "dotenv": "16.5.0",
72
- "dotenv-expand": "12.0.1",
73
- "html-rspack-plugin": "6.0.4",
72
+ "dotenv-expand": "12.0.2",
73
+ "html-rspack-plugin": "6.0.5",
74
74
  "http-proxy-middleware": "^2.0.7",
75
75
  "launch-editor-middleware": "^2.10.0",
76
76
  "mrmime": "^2.0.1",
@@ -88,7 +88,7 @@
88
88
  "rspack-manifest-plugin": "5.0.3",
89
89
  "sirv": "^3.0.1",
90
90
  "style-loader": "3.3.4",
91
- "tinyglobby": "^0.2.12",
91
+ "tinyglobby": "^0.2.13",
92
92
  "typescript": "^5.8.3",
93
93
  "webpack": "^5.98.0",
94
94
  "webpack-bundle-analyzer": "^4.10.2",
@@ -1,4 +0,0 @@
1
- export * from './extractChunks';
2
- export * from './determineAsValue';
3
- export * from './doesChunkBelongToHtml';
4
- export * from './type';
@@ -1,13 +0,0 @@
1
- import type { HtmlRspackPlugin } from '../../../types';
2
- export type BeforeAssetTagGenerationHtmlPluginData = {
3
- assets: {
4
- publicPath: string;
5
- js: Array<string>;
6
- css: Array<string>;
7
- favicon?: string;
8
- manifest?: string;
9
- };
10
- outputName: string;
11
- plugin: HtmlRspackPlugin;
12
- };
13
- export type As = 'audio' | 'document' | 'embed' | 'fetch' | 'font' | 'image' | 'object' | 'script' | 'style' | 'track' | 'worker' | 'video';