@rsbuild/core 1.3.9 → 1.3.11

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.9",
2120
+ version: "1.3.11",
2119
2121
  rootPath,
2120
2122
  distPath: '',
2121
2123
  cachePath,
@@ -3340,13 +3342,19 @@ function updateSourceMappingURL({ source, compilation, publicPath, type, config
3340
3342
  }
3341
3343
  return source;
3342
3344
  }
3343
- function matchTests(name, source, tests) {
3345
+ function matchTests(name, asset, tests) {
3344
3346
  return tests.some((test)=>isFunction(test) ? test({
3345
3347
  name,
3346
- size: source.length
3348
+ size: asset.size()
3347
3349
  }) : test.exec(name));
3348
3350
  }
3349
- 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 = ()=>({
3350
3358
  name: 'rsbuild:inline-chunk',
3351
3359
  setup (api) {
3352
3360
  let inlinedAssets = new Set(), getInlinedScriptTag = (publicPath, tag, compilation, scriptTests, config)=>{
@@ -3354,13 +3362,11 @@ let pluginInlineChunk = ()=>({
3354
3362
  let { assets } = compilation;
3355
3363
  if (!((null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.src) && 'string' == typeof tag.attrs.src)) return tag;
3356
3364
  let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = assets[scriptName];
3357
- if (null == asset) return tag;
3358
- let source = asset.source().toString();
3359
- if (!matchTests(scriptName, source, scriptTests)) return tag;
3365
+ if (null == asset || !matchTests(scriptName, asset, scriptTests)) return tag;
3360
3366
  let ret = {
3361
3367
  tag: "script",
3362
3368
  children: updateSourceMappingURL({
3363
- source,
3369
+ source: asset.source().toString(),
3364
3370
  compilation,
3365
3371
  publicPath,
3366
3372
  type: 'js',
@@ -3376,13 +3382,11 @@ let pluginInlineChunk = ()=>({
3376
3382
  let { assets } = compilation;
3377
3383
  if (!((null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.href) && 'string' == typeof tag.attrs.href)) return tag;
3378
3384
  let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = assets[linkName];
3379
- if (null == asset) return tag;
3380
- let source = asset.source().toString();
3381
- if (!matchTests(linkName, source, styleTests)) return tag;
3385
+ if (null == asset || !matchTests(linkName, asset, styleTests)) return tag;
3382
3386
  let ret = {
3383
3387
  tag: 'style',
3384
3388
  children: updateSourceMappingURL({
3385
- source,
3389
+ source: asset.source().toString(),
3386
3390
  compilation,
3387
3391
  publicPath,
3388
3392
  type: 'css',
@@ -3404,8 +3408,8 @@ let pluginInlineChunk = ()=>({
3404
3408
  headTags,
3405
3409
  bodyTags
3406
3410
  };
3407
- let { inlineStyles, inlineScripts } = config.output, scriptTests = [], styleTests = [], isProdMode = 'production' === environment.config.mode;
3408
- 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 {
3409
3413
  headTags,
3410
3414
  bodyTags
3411
3415
  };
@@ -3417,9 +3421,6 @@ let pluginInlineChunk = ()=>({
3417
3421
  });
3418
3422
  }
3419
3423
  });
3420
- function isAsync(chunk) {
3421
- return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
3422
- }
3423
3424
  function recursiveChunkEntryNames(chunk) {
3424
3425
  let [...chunkGroups] = chunk.groupsIterable;
3425
3426
  return [
@@ -3996,7 +3997,10 @@ let getJsAsyncPath = (jsPath, isServer, jsAsync)=>void 0 !== jsAsync ? jsAsync :
3996
3997
  });
3997
3998
  }
3998
3999
  });
3999
- 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) {
4000
4004
  return key in obj ? Object.defineProperty(obj, key, {
4001
4005
  value: value,
4002
4006
  enumerable: !0,
@@ -4004,20 +4008,34 @@ function HtmlPreloadOrPrefetchPlugin_define_property(obj, key, value) {
4004
4008
  writable: !0
4005
4009
  }) : obj[key] = value, obj;
4006
4010
  }
4007
- let HtmlPreloadOrPrefetchPlugin_defaultOptions = {
4011
+ let HtmlResourceHintsPlugin_defaultOptions = {
4008
4012
  type: 'async-chunks',
4009
4013
  dedupe: !0
4014
+ }, applyFilter = (files, include, exclude)=>{
4015
+ let includeRegExp = [], excludeRegExp = [], includeFn = [], excludeFn = [];
4016
+ if (include) for (let item of castArray(include))'string' == typeof item ? includeRegExp.push(new RegExp(item)) : isFunction(item) ? includeFn.push(item) : includeRegExp.push(item);
4017
+ if (exclude) for (let item of castArray(exclude))'string' == typeof item ? excludeRegExp.push(new RegExp(item)) : isFunction(item) ? excludeFn.push(item) : excludeRegExp.push(item);
4018
+ return files.filter((file)=>{
4019
+ let includeMatched = !1;
4020
+ for (let item of includeRegExp)item.test(file) && (includeMatched = !0);
4021
+ for (let item of includeFn)item(file) && (includeMatched = !0);
4022
+ if (includeRegExp.length + includeFn.length > 0 && !includeMatched) return !1;
4023
+ for (let item of excludeRegExp)if (item.test(file)) return !1;
4024
+ for (let item of excludeFn)if (item(file)) return !1;
4025
+ return !0;
4026
+ });
4010
4027
  };
4011
- class HtmlPreloadOrPrefetchPlugin {
4028
+ class HtmlResourceHintsPlugin {
4012
4029
  apply(compiler) {
4013
4030
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
4014
- getHTMLPlugin().getHooks(compilation).beforeAssetTagGeneration.tap(`HTML${upperFirst(this.type)}Plugin`, (htmlPluginData)=>(this.resourceHints = function(options, type, compilation, htmlPluginData, HTMLCount) {
4015
- let extractedChunks = function({ compilation, includeType }) {
4031
+ let pluginHooks = getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
4032
+ pluginHooks.beforeAssetTagGeneration.tap(pluginName, (data)=>(this.resourceHints = function(options, type, compilation, data, HTMLCount) {
4033
+ let extractedChunks = function(compilation, includeType) {
4016
4034
  let chunks = [
4017
4035
  ...compilation.chunks
4018
4036
  ];
4019
- if (void 0 === includeType || 'async-chunks' === includeType) return chunks.filter(isAsync);
4020
- if ('initial' === includeType) return chunks.filter((chunk)=>!isAsync(chunk));
4037
+ if (void 0 === includeType || 'async-chunks' === includeType) return chunks.filter(isAsyncChunk);
4038
+ if ('initial' === includeType) return chunks.filter((chunk)=>!isAsyncChunk(chunk));
4021
4039
  if ('all-chunks' === includeType) return chunks;
4022
4040
  if ('all-assets' === includeType) {
4023
4041
  var _compilation_assetsInfo;
@@ -4034,10 +4052,7 @@ class HtmlPreloadOrPrefetchPlugin {
4034
4052
  ];
4035
4053
  }
4036
4054
  return chunks;
4037
- }({
4038
- compilation,
4039
- includeType: options.type
4040
- }), sortedFilteredFiles = [
4055
+ }(compilation, options.type), sortedFilteredFiles = applyFilter([
4041
4056
  ...new Set(('all-assets' === options.type || 1 === HTMLCount ? extractedChunks : extractedChunks.filter((chunk)=>(function({ chunk, htmlPluginData }) {
4042
4057
  let { options } = htmlPluginData.plugin;
4043
4058
  return recursiveChunkEntryNames(chunk).some((chunkName)=>{
@@ -4047,15 +4062,13 @@ class HtmlPreloadOrPrefetchPlugin {
4047
4062
  })({
4048
4063
  chunk: chunk,
4049
4064
  compilation,
4050
- htmlPluginData,
4065
+ htmlPluginData: data,
4051
4066
  pluginOptions: options
4052
4067
  }))).reduce((accumulated, chunk)=>accumulated.concat([
4053
4068
  ...chunk.files,
4054
4069
  ...chunk.auxiliaryFiles || []
4055
- ]), []))
4056
- ].filter((file)=>[
4057
- /.map$/
4058
- ].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;
4070
+ ]), []).filter((file)=>!file.endsWith('.map')))
4071
+ ], options.include, options.exclude).sort(), links = [], { publicPath, crossOriginLoading } = compilation.outputOptions;
4059
4072
  for (let file of sortedFilteredFiles){
4060
4073
  let href = ensureAssetPrefix(file, publicPath), attributes = {
4061
4074
  href,
@@ -4079,19 +4092,19 @@ class HtmlPreloadOrPrefetchPlugin {
4079
4092
  });
4080
4093
  }
4081
4094
  return links;
4082
- }(this.options, this.type, compilation, htmlPluginData, this.HTMLCount), htmlPluginData)), getHTMLPlugin().getHooks(compilation).alterAssetTags.tap(`HTML${upperFirst(this.type)}Plugin`, (htmlPluginData)=>{
4095
+ }(this.options, this.type, compilation, data, this.HTMLCount), data)), pluginHooks.alterAssetTags.tap(pluginName, (data)=>{
4083
4096
  var resourceHints, scripts;
4084
- return this.resourceHints && (htmlPluginData.assetTags.styles = [
4085
- ...this.options.dedupe ? (resourceHints = this.resourceHints, scripts = htmlPluginData.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))) : this.resourceHints,
4086
- ...htmlPluginData.assetTags.styles
4087
- ]), htmlPluginData;
4097
+ return this.resourceHints && (data.assetTags.styles = [
4098
+ ...this.options.dedupe ? (resourceHints = this.resourceHints, scripts = data.assetTags.scripts, resourceHints.filter((resourceHint)=>!scripts.find((script)=>script.attributes.src === resourceHint.attributes.href))) : this.resourceHints,
4099
+ ...data.assetTags.styles
4100
+ ]), data;
4088
4101
  });
4089
4102
  });
4090
4103
  }
4091
4104
  constructor(options, type, HTMLCount){
4092
- 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 = {
4093
- ...HtmlPreloadOrPrefetchPlugin_defaultOptions,
4094
- ...'boolean' == typeof options ? {} : options
4105
+ 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 = {
4106
+ ...HtmlResourceHintsPlugin_defaultOptions,
4107
+ ...options
4095
4108
  }, this.type = type, this.HTMLCount = HTMLCount;
4096
4109
  }
4097
4110
  }
@@ -4101,7 +4114,13 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4101
4114
  rel,
4102
4115
  ...option
4103
4116
  }
4104
- })), pluginResourceHints = ()=>({
4117
+ })), getInlineExcludes = (config)=>{
4118
+ let { scriptTests, styleTests } = getInlineTests(config);
4119
+ return [
4120
+ ...scriptTests,
4121
+ ...styleTests
4122
+ ].filter((item)=>(0, __WEBPACK_EXTERNAL_MODULE_node_util_types_ce11fc49__.isRegExp)(item));
4123
+ }, pluginResourceHints = ()=>({
4105
4124
  name: 'rsbuild:resource-hints',
4106
4125
  setup (api) {
4107
4126
  api.modifyHTMLTags(({ headTags, bodyTags }, { environment })=>{
@@ -4125,16 +4144,29 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
4125
4144
  }), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
4126
4145
  let { config, htmlPaths } = environment;
4127
4146
  if (0 === Object.keys(htmlPaths).length) return;
4128
- let { performance: { preload, prefetch } } = config, HTMLCount = chain.entryPoints.values().length;
4129
- prefetch && chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlPreloadOrPrefetchPlugin, [
4130
- prefetch,
4131
- 'prefetch',
4132
- HTMLCount
4133
- ]), preload && chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlPreloadOrPrefetchPlugin, [
4134
- preload,
4135
- 'preload',
4136
- HTMLCount
4137
- ]);
4147
+ let { performance: { preload, prefetch } } = config, HTMLCount = chain.entryPoints.values().length, excludes = getInlineExcludes(config);
4148
+ if (prefetch) {
4149
+ let options = !0 === prefetch ? {} : prefetch;
4150
+ excludes.length && (options.exclude = options.exclude ? [
4151
+ ...castArray(options.exclude),
4152
+ ...excludes
4153
+ ] : excludes), chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HtmlResourceHintsPlugin, [
4154
+ options,
4155
+ 'prefetch',
4156
+ HTMLCount
4157
+ ]);
4158
+ }
4159
+ if (preload) {
4160
+ let options = !0 === preload ? {} : preload;
4161
+ excludes.length && (options.exclude = options.exclude ? [
4162
+ ...castArray(options.exclude),
4163
+ ...excludes
4164
+ ] : excludes), chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HtmlResourceHintsPlugin, [
4165
+ options,
4166
+ 'preload',
4167
+ HTMLCount
4168
+ ]);
4169
+ }
4138
4170
  });
4139
4171
  }
4140
4172
  }), rsdoctor_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), pluginRsdoctor = ()=>({
@@ -7291,11 +7323,11 @@ async function runCLI() {
7291
7323
  }
7292
7324
  process.title = 'rsbuild-node';
7293
7325
  let { npm_execpath } = process.env;
7294
- (!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.9\n`);
7326
+ (!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.11\n`);
7295
7327
  try {
7296
7328
  !function() {
7297
7329
  let cli = cac_dist('rsbuild');
7298
- cli.help(), cli.version("1.3.9"), applyCommonOptions(cli);
7330
+ cli.help(), cli.version("1.3.11"), applyCommonOptions(cli);
7299
7331
  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');
7300
7332
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7301
7333
  try {
@@ -7346,6 +7378,6 @@ async function runCLI() {
7346
7378
  __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);
7347
7379
  }
7348
7380
  }
7349
- let src_version = "1.3.9";
7381
+ let src_version = "1.3.11";
7350
7382
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
7351
7383
  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.9",
3
+ "version": "1.3.11",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -46,14 +46,14 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.3.5",
49
+ "@rspack/core": "1.3.6",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.17",
52
52
  "core-js": "~3.41.0",
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';