@rsbuild/core 2.0.8 → 2.0.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.
Files changed (86) hide show
  1. package/compiled/connect-next/package.json +1 -1
  2. package/compiled/css-loader/index.js +2 -2
  3. package/compiled/html-rspack-plugin/index.js +14 -14
  4. package/compiled/html-rspack-plugin/package.json +1 -1
  5. package/compiled/postcss-loader/index.js +6 -6
  6. package/compiled/rslog/index.d.ts +3 -3
  7. package/compiled/rslog/package.json +1 -1
  8. package/compiled/rspack-chain/package.json +1 -1
  9. package/dist/1~rslib-runtime.js +8 -5
  10. package/dist/756.js +25 -21
  11. package/dist/launch-editor-middleware.js +58 -23
  12. package/dist/manifest-plugin.js +6 -6
  13. package/dist/memfs.js +101 -99
  14. package/dist/tinyglobby.js +11 -9
  15. package/dist-types/build.d.ts +1 -1
  16. package/dist-types/cli/init.d.ts +1 -1
  17. package/dist-types/configChain.d.ts +59 -118
  18. package/dist-types/constants.d.ts +35 -31
  19. package/dist-types/createContext.d.ts +1 -2
  20. package/dist-types/createRsbuild.d.ts +1 -2
  21. package/dist-types/defaultConfig.d.ts +2 -4
  22. package/dist-types/helpers/exitHook.d.ts +1 -1
  23. package/dist-types/helpers/format.d.ts +2 -1
  24. package/dist-types/helpers/fs.d.ts +2 -4
  25. package/dist-types/helpers/index.d.ts +1 -2
  26. package/dist-types/helpers/path.d.ts +4 -8
  27. package/dist-types/helpers/stats.d.ts +3 -5
  28. package/dist-types/helpers/url.d.ts +1 -0
  29. package/dist-types/helpers/vendors.d.ts +2 -3
  30. package/dist-types/helpers/version.d.ts +2 -3
  31. package/dist-types/hooks.d.ts +6 -8
  32. package/dist-types/index.d.ts +10 -5
  33. package/dist-types/initConfigs.d.ts +2 -3
  34. package/dist-types/initPlugins.d.ts +1 -1
  35. package/dist-types/inspectConfig.d.ts +1 -1
  36. package/dist-types/loadConfig.d.ts +24 -32
  37. package/dist-types/loadEnv.d.ts +48 -57
  38. package/dist-types/loader/transformRawLoader.d.ts +1 -0
  39. package/dist-types/logger.d.ts +1 -2
  40. package/dist-types/mergeConfig.d.ts +1 -2
  41. package/dist-types/pluginHelper.d.ts +1 -2
  42. package/dist-types/pluginManager.d.ts +4 -7
  43. package/dist-types/plugins/basic.d.ts +1 -2
  44. package/dist-types/plugins/css.d.ts +4 -0
  45. package/dist-types/plugins/fileSize.d.ts +6 -5
  46. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  47. package/dist-types/plugins/server.d.ts +1 -0
  48. package/dist-types/plugins/swc.d.ts +1 -2
  49. package/dist-types/restart.d.ts +4 -5
  50. package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +2 -3
  51. package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +2 -3
  52. package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +3 -4
  53. package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +1 -2
  54. package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +2 -3
  55. package/dist-types/rspackConfig.d.ts +1 -1
  56. package/dist-types/server/ansiHTML.d.ts +1 -2
  57. package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +1 -2
  58. package/dist-types/server/assets-middleware/index.d.ts +3 -5
  59. package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +1 -2
  60. package/dist-types/server/browserLogs.d.ts +1 -2
  61. package/dist-types/server/buildManager.d.ts +4 -6
  62. package/dist-types/server/cliShortcuts.d.ts +3 -1
  63. package/dist-types/server/devMiddlewares.d.ts +2 -3
  64. package/dist-types/server/devServer.d.ts +18 -23
  65. package/dist-types/server/gracefulShutdown.d.ts +2 -4
  66. package/dist-types/server/gzipMiddleware.d.ts +1 -1
  67. package/dist-types/server/helper.d.ts +36 -45
  68. package/dist-types/server/historyApiFallback.d.ts +8 -1
  69. package/dist-types/server/httpServer.d.ts +1 -1
  70. package/dist-types/server/middlewares.d.ts +4 -8
  71. package/dist-types/server/open.d.ts +1 -1
  72. package/dist-types/server/runner/basic.d.ts +4 -5
  73. package/dist-types/server/runner/index.d.ts +3 -1
  74. package/dist-types/server/socketServer.d.ts +24 -18
  75. package/dist-types/server/watchFiles.d.ts +1 -1
  76. package/dist-types/types/config.d.ts +1192 -1465
  77. package/dist-types/types/context.d.ts +63 -92
  78. package/dist-types/types/hooks.d.ts +106 -150
  79. package/dist-types/types/plugin.d.ts +359 -444
  80. package/dist-types/types/rsbuild.d.ts +156 -191
  81. package/dist-types/types/thirdParty.d.ts +101 -132
  82. package/dist-types/types/utils.d.ts +2 -5
  83. package/package.json +13 -13
  84. package/dist-types/client/hmr.d.ts +0 -3
  85. package/dist-types/client/log.d.ts +0 -13
  86. package/dist-types/client/overlay.d.ts +0 -1
@@ -16,18 +16,17 @@ import type { RsbuildPlugins } from './plugin';
16
16
  import type { RsbuildEntry, RsbuildMode, RsbuildTarget } from './rsbuild';
17
17
  import type { Rspack, RspackRule } from './rspack';
18
18
  import type { Connect, CSSExtractOptions, CSSLoaderModulesOptions, CSSLoaderOptions, HtmlRspackPlugin, LoosePostCSSPlugin, PostCSSLoaderOptions, StyleLoaderOptions } from './thirdParty';
19
- import type { ConfigChain, ConfigChainAsyncWithContext, ConfigChainMergeContext, ConfigChainWithContext, LiteralUnion, MaybePromise, OneOrMany, Optional, TwoLevelReadonly } from './utils';
19
+ import type { ConfigChain, ConfigChainAsyncWithContext, ConfigChainWithContext, LiteralUnion, MaybePromise, OneOrMany, Optional, TwoLevelReadonly } from './utils';
20
20
  export type ToolsSwcConfig = ConfigChain<SwcLoaderOptions>;
21
21
  export type ToolsBundlerChainConfig = OneOrMany<(chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>>;
22
22
  export type ToolsPostCSSContext = {
23
23
  addPlugins: (plugins: LoosePostCSSPlugin | LoosePostCSSPlugin[], options?: {
24
24
  /**
25
- * Controls where the plugin is placed relative to the existing PostCSS plugins.
26
- * - `pre`: Insert the plugin before all existing plugins.
27
- * - `post`: Insert the plugin after all existing plugins.
28
- * @default `post`
29
- */
30
- order?: 'pre' | 'post';
25
+ * Controls where the plugin is placed relative to the existing PostCSS plugins.
26
+ * - `pre`: Insert the plugin before all existing plugins.
27
+ * - `post`: Insert the plugin after all existing plugins.
28
+ * @default `post`
29
+ */ order?: 'pre' | 'post';
31
30
  }) => void;
32
31
  };
33
32
  export type ToolsPostCSSLoaderConfig = ConfigChainWithContext<PostCSSLoaderOptions, ToolsPostCSSContext>;
@@ -37,6 +36,7 @@ export type ToolsHtmlPluginConfig = ConfigChainWithContext<HtmlRspackPlugin.Opti
37
36
  entryName: string;
38
37
  entryValue: (string | string[] | Rspack.EntryDescription)[];
39
38
  }>;
39
+ // equivalent to import('rspack-merge').merge
40
40
  export type RspackMerge = (firstConfiguration: Rspack.Configuration | Rspack.Configuration[], ...configurations: Rspack.Configuration[]) => Rspack.Configuration;
41
41
  export type ModifyRspackConfigUtils = ModifyChainUtils & {
42
42
  addRules: (rules: OneOrMany<RspackRule>) => void;
@@ -73,63 +73,49 @@ export type ModifyRspackConfigUtils = ModifyChainUtils & {
73
73
  * }
74
74
  * }
75
75
  * ```
76
- */
77
- export type NarrowedRspackConfig = Omit<Rspack.Configuration, 'plugins' | 'module' | 'resolve' | 'output'> & {
76
+ */ export type NarrowedRspackConfig = Omit<Rspack.Configuration, 'plugins' | 'module' | 'resolve' | 'output'> & {
78
77
  /**
79
- * Plugins to use during compilation.
80
- */
81
- plugins: Rspack.Plugin[];
78
+ * Plugins to use during compilation.
79
+ */ plugins: Rspack.Plugin[];
82
80
  /**
83
- * Options for module configuration.
84
- */
85
- module: NonNullable<Rspack.Configuration['module']>;
81
+ * Options for module configuration.
82
+ */ module: NonNullable<Rspack.Configuration['module']>;
86
83
  /**
87
- * Options for resolving modules.
88
- */
89
- resolve: NonNullable<Rspack.Configuration['resolve']>;
84
+ * Options for resolving modules.
85
+ */ resolve: NonNullable<Rspack.Configuration['resolve']>;
90
86
  /**
91
- * Configuration for the output of the compilation.
92
- */
93
- output: NonNullable<Rspack.Configuration['output']>;
87
+ * Configuration for the output of the compilation.
88
+ */ output: NonNullable<Rspack.Configuration['output']>;
94
89
  };
95
90
  export type ToolsRspackConfig = OneOrMany<Rspack.Configuration | ((config: NarrowedRspackConfig, ctx: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>)>;
96
91
  export interface ToolsConfig {
97
92
  /**
98
- * Configure bundler config base on [rspack-chain](https://github.com/rstackjs/rspack-chain)
99
- */
100
- bundlerChain?: ToolsBundlerChainConfig;
93
+ * Configure bundler config base on [rspack-chain](https://github.com/rstackjs/rspack-chain)
94
+ */ bundlerChain?: ToolsBundlerChainConfig;
101
95
  /**
102
- * Modify the options of [css-loader](https://github.com/webpack/css-loader).
103
- */
104
- cssLoader?: ToolsCSSLoaderConfig;
96
+ * Modify the options of [css-loader](https://github.com/webpack/css-loader).
97
+ */ cssLoader?: ToolsCSSLoaderConfig;
105
98
  /**
106
- * Modify the options of [postcss-loader](https://github.com/webpack/postcss-loader).
107
- */
108
- postcss?: ToolsPostCSSLoaderConfig;
99
+ * Modify the options of [postcss-loader](https://github.com/webpack/postcss-loader).
100
+ */ postcss?: ToolsPostCSSLoaderConfig;
109
101
  /**
110
- * Modify the options of [style-loader](https://github.com/webpack/style-loader).
111
- */
112
- styleLoader?: ToolsStyleLoaderConfig;
102
+ * Modify the options of [style-loader](https://github.com/webpack/style-loader).
103
+ */ styleLoader?: ToolsStyleLoaderConfig;
113
104
  /**
114
- * Configure the html-rspack-plugin.
115
- */
116
- htmlPlugin?: boolean | ToolsHtmlPluginConfig;
105
+ * Configure the html-rspack-plugin.
106
+ */ htmlPlugin?: boolean | ToolsHtmlPluginConfig;
117
107
  /**
118
- * Configure the `builtin:swc-loader` of Rspack.
119
- */
120
- swc?: ToolsSwcConfig;
108
+ * Configure the `builtin:swc-loader` of Rspack.
109
+ */ swc?: ToolsSwcConfig;
121
110
  /**
122
- * Configure the `builtin:lightningcss-loader` of Rspack.
123
- */
124
- lightningcssLoader?: boolean | ConfigChain<Rspack.LightningcssLoaderOptions>;
111
+ * Configure the `builtin:lightningcss-loader` of Rspack.
112
+ */ lightningcssLoader?: boolean | ConfigChain<Rspack.LightningcssLoaderOptions>;
125
113
  /**
126
- * Modify the options of [CssExtractRspackPlugin](https://rspack.rs/plugins/rspack/css-extract-rspack-plugin).
127
- */
128
- cssExtract?: CSSExtractOptions;
114
+ * Modify the options of [CssExtractRspackPlugin](https://rspack.rs/plugins/rspack/css-extract-rspack-plugin).
115
+ */ cssExtract?: CSSExtractOptions;
129
116
  /**
130
- * Configure Rspack.
131
- */
132
- rspack?: ToolsRspackConfig;
117
+ * Configure Rspack.
118
+ */ rspack?: ToolsRspackConfig;
133
119
  }
134
120
  export type NormalizedToolsConfig = ToolsConfig & {
135
121
  cssExtract: Required<CSSExtractOptions>;
@@ -138,76 +124,68 @@ export type Alias = Record<string, string | false | (string | false)[]>;
138
124
  export type AliasStrategy = 'prefer-tsconfig' | 'prefer-alias';
139
125
  export type Decorators = {
140
126
  /**
141
- * Specify the version of decorators to use.
142
- * @default '2023-11'
143
- */
144
- version?: 'legacy' | '2022-03' | '2023-11';
127
+ * Specify the version of decorators to use.
128
+ * @default '2023-11'
129
+ */ version?: 'legacy'// stage 1
130
+ | '2022-03'// stage 3
131
+ | '2023-11';
145
132
  };
146
133
  export interface SourceConfig {
147
134
  /**
148
- * Include additional files that should be treated as static assets.
149
- * @default undefined
150
- */
151
- assetsInclude?: Rspack.RuleSetCondition;
152
- /**
153
- * Specify additional JavaScript files that need to be compiled by SWC.
154
- * Through the `source.include` config, you can specify directories or modules
155
- * that need to be compiled by Rsbuild. The usage of `source.include` is
156
- * consistent with [rules[].include](https://rspack.rs/config/module-rules#rulesinclude)
157
- * in Rspack, which supports passing in strings or regular expressions to match
158
- * the module path.
159
- * @default
160
- * [
161
- * { and: [rootPath, { not: /[\\/]node_modules[\\/]/ }], },
162
- * /\.(?:ts|tsx|jsx|mts|cts)$/,
163
- * ];
164
- */
165
- include?: RuleSetCondition[];
166
- /**
167
- * Set the entry modules for building.
168
- *
169
- * The value of `source.entry` is an object, the key is the entry name, and the
170
- * value is the path of the entry module or a description object.
171
- *
172
- * If the value is a path, it can be an absolute path or a relative path, the
173
- * relative path will be resolved based on `root`.
174
- *
175
- * @default
176
- * {
177
- * // Rsbuild also supports other suffixes by default, such as ts,
178
- * // tsx, jsx, mts, cts, mjs, cjs
179
- * index: './src/index.js',
180
- * }
181
- */
182
- entry?: RsbuildEntry;
183
- /**
184
- * Exclude JavaScript or TypeScript files that do not need to be compiled by SWC.
185
- */
186
- exclude?: RuleSetCondition[];
187
- /**
188
- * Add a script before the entry file of each page.
189
- * This script will be executed before the page code.
190
- * It can be used to execute global logics, such as polyfill injection.
191
- */
192
- preEntry?: string | string[];
193
- /**
194
- * Replaces variables in your code with other values or expressions at compile time.
195
- * This is useful for enabling different behavior between development and production builds.
196
- */
197
- define?: DefinePluginOptions;
198
- /**
199
- * Configuring decorators syntax.
200
- */
201
- decorators?: Decorators;
202
- /**
203
- * Used to import the code and style of the component library on demand.
204
- */
205
- transformImport?: TransformImportFn | (TransformImport | TransformImportFn)[];
206
- /**
207
- * Configure a custom tsconfig.json file path to use, can be a relative or absolute path.
208
- * @default 'tsconfig.json'
209
- */
210
- tsconfigPath?: string;
135
+ * Include additional files that should be treated as static assets.
136
+ * @default undefined
137
+ */ assetsInclude?: Rspack.RuleSetCondition;
138
+ /**
139
+ * Specify additional JavaScript files that need to be compiled by SWC.
140
+ * Through the `source.include` config, you can specify directories or modules
141
+ * that need to be compiled by Rsbuild. The usage of `source.include` is
142
+ * consistent with [rules[].include](https://rspack.rs/config/module-rules#rulesinclude)
143
+ * in Rspack, which supports passing in strings or regular expressions to match
144
+ * the module path.
145
+ * @default
146
+ * [
147
+ * { and: [rootPath, { not: /[\\/]node_modules[\\/]/ }], },
148
+ * /\.(?:ts|tsx|jsx|mts|cts)$/,
149
+ * ];
150
+ */ include?: RuleSetCondition[];
151
+ /**
152
+ * Set the entry modules for building.
153
+ *
154
+ * The value of `source.entry` is an object, the key is the entry name, and the
155
+ * value is the path of the entry module or a description object.
156
+ *
157
+ * If the value is a path, it can be an absolute path or a relative path, the
158
+ * relative path will be resolved based on `root`.
159
+ *
160
+ * @default
161
+ * {
162
+ * // Rsbuild also supports other suffixes by default, such as ts,
163
+ * // tsx, jsx, mts, cts, mjs, cjs
164
+ * index: './src/index.js',
165
+ * }
166
+ */ entry?: RsbuildEntry;
167
+ /**
168
+ * Exclude JavaScript or TypeScript files that do not need to be compiled by SWC.
169
+ */ exclude?: RuleSetCondition[];
170
+ /**
171
+ * Add a script before the entry file of each page.
172
+ * This script will be executed before the page code.
173
+ * It can be used to execute global logics, such as polyfill injection.
174
+ */ preEntry?: string | string[];
175
+ /**
176
+ * Replaces variables in your code with other values or expressions at compile time.
177
+ * This is useful for enabling different behavior between development and production builds.
178
+ */ define?: DefinePluginOptions;
179
+ /**
180
+ * Configuring decorators syntax.
181
+ */ decorators?: Decorators;
182
+ /**
183
+ * Used to import the code and style of the component library on demand.
184
+ */ transformImport?: TransformImportFn | (TransformImport | TransformImportFn)[];
185
+ /**
186
+ * Configure a custom tsconfig.json file path to use, can be a relative or absolute path.
187
+ * @default 'tsconfig.json'
188
+ */ tsconfigPath?: string;
211
189
  }
212
190
  export type TransformImport = {
213
191
  libraryName: string;
@@ -232,15 +210,14 @@ export type ProxyBypass = (req: IncomingMessage, res: ServerResponse, proxyOptio
232
210
  export type { ProxyFilter };
233
211
  export type ProxyOptions = HttpProxyOptions & {
234
212
  /**
235
- * Use the `bypass` function to skip the proxy.
236
- * Inside the function, you have access to the request, response, and proxy options.
237
- * - Return `null` or `undefined` to continue processing the request with proxy.
238
- * - Return `true` to skip the proxy and continue processing the request.
239
- * - Return `false` to produce a 404 error for the request.
240
- * - Return a specific path to replace the original request path.
241
- * - Return a Promise to handle the request asynchronously.
242
- */
243
- bypass?: ProxyBypass;
213
+ * Use the `bypass` function to skip the proxy.
214
+ * Inside the function, you have access to the request, response, and proxy options.
215
+ * - Return `null` or `undefined` to continue processing the request with proxy.
216
+ * - Return `true` to skip the proxy and continue processing the request.
217
+ * - Return `false` to produce a 404 error for the request.
218
+ * - Return a specific path to replace the original request path.
219
+ * - Return a Promise to handle the request asynchronously.
220
+ */ bypass?: ProxyBypass;
244
221
  };
245
222
  export type ProxyConfig = Record<string, string | ProxyOptions> | ProxyOptions[];
246
223
  export type HistoryApiFallbackContext = {
@@ -251,33 +228,29 @@ export type HistoryApiFallbackContext = {
251
228
  export type HistoryApiFallbackTo = string | ((context: HistoryApiFallbackContext) => string);
252
229
  export type HistoryApiFallbackOptions = {
253
230
  /**
254
- * Specifies the default HTML file to return when the History API fallback is enabled.
255
- * For example, if you set `historyApiFallback.index` to `main.html`, the server will
256
- * automatically serve `main.html` as the fallback page when users access any unmatched
257
- * routes.
258
- * @default 'index.html'
259
- */
260
- index?: string;
261
- /**
262
- * Override the default `Accepts:` headers that are queried when matching HTML content
263
- * requests.
264
- * @default ['text/html', '*\/*']
265
- */
266
- htmlAcceptHeaders?: string[];
267
- /**
268
- * By default, requests containing a dot (`.`) in the path are treated as direct file
269
- * requests and are not redirected. Setting `disableDotRule` to `true` will disable this
270
- * behavior and allow such requests to be redirected as well.
271
- * @default false
272
- */
273
- disableDotRule?: boolean;
274
- /**
275
- * `rewrites` lets you customize how request paths are mapped to HTML files when
276
- * a History API fallback occurs. These rules only apply when no static asset matches
277
- * the request, meaning it has entered the fallback stage. Each rule is evaluated in
278
- * order until a match is found and executed.
279
- */
280
- rewrites?: {
231
+ * Specifies the default HTML file to return when the History API fallback is enabled.
232
+ * For example, if you set `historyApiFallback.index` to `main.html`, the server will
233
+ * automatically serve `main.html` as the fallback page when users access any unmatched
234
+ * routes.
235
+ * @default 'index.html'
236
+ */ index?: string;
237
+ /**
238
+ * Override the default `Accepts:` headers that are queried when matching HTML content
239
+ * requests.
240
+ * @default ['text/html', '*\/*']
241
+ */ htmlAcceptHeaders?: string[];
242
+ /**
243
+ * By default, requests containing a dot (`.`) in the path are treated as direct file
244
+ * requests and are not redirected. Setting `disableDotRule` to `true` will disable this
245
+ * behavior and allow such requests to be redirected as well.
246
+ * @default false
247
+ */ disableDotRule?: boolean;
248
+ /**
249
+ * `rewrites` lets you customize how request paths are mapped to HTML files when
250
+ * a History API fallback occurs. These rules only apply when no static asset matches
251
+ * the request, meaning it has entered the fallback stage. Each rule is evaluated in
252
+ * order until a match is found and executed.
253
+ */ rewrites?: {
281
254
  from: RegExp;
282
255
  to: HistoryApiFallbackTo;
283
256
  }[];
@@ -293,164 +266,141 @@ export type PrintUrls = boolean | ((params: {
293
266
  })[] | void);
294
267
  export type PublicDirOptions = {
295
268
  /**
296
- * The name of the public directory, can be set as a relative path or an absolute path.
297
- * @default 'public'
298
- */
299
- name?: string;
300
- /**
301
- * Whether to copy files from the public directory to the dist directory on production build.
302
- * - `true`: copy files
303
- * - `false`: do not copy files
304
- * - `'auto'`: if `output.target` is not `'node'`, copy files, otherwise do not copy
305
- * @default 'auto'
306
- */
307
- copyOnBuild?: boolean | 'auto';
308
- /**
309
- * whether to watch the public directory and reload the page when the files change
310
- * @default false
311
- */
312
- watch?: boolean;
313
- /**
314
- * Glob patterns for files or directories to ignore when copying the public directory
315
- * during production builds.
316
- * @default []
317
- */
318
- ignore?: string[];
269
+ * The name of the public directory, can be set as a relative path or an absolute path.
270
+ * @default 'public'
271
+ */ name?: string;
272
+ /**
273
+ * Whether to copy files from the public directory to the dist directory on production build.
274
+ * - `true`: copy files
275
+ * - `false`: do not copy files
276
+ * - `'auto'`: if `output.target` is not `'node'`, copy files, otherwise do not copy
277
+ * @default 'auto'
278
+ */ copyOnBuild?: boolean | 'auto';
279
+ /**
280
+ * whether to watch the public directory and reload the page when the files change
281
+ * @default false
282
+ */ watch?: boolean;
283
+ /**
284
+ * Glob patterns for files or directories to ignore when copying the public directory
285
+ * during production builds.
286
+ * @default []
287
+ */ ignore?: string[];
319
288
  };
320
289
  export type PublicDir = false | PublicDirOptions | PublicDirOptions[];
321
290
  /**
322
291
  * The options for `server.compress`.
323
- */
324
- export type CompressOptions = {
325
- /**
326
- * A function that determines whether a response should be compressed.
327
- * @param req - The incoming HTTP request
328
- * @param res - The outgoing HTTP response
329
- * @returns `true` to compress the response, `false` to skip compression
330
- */
331
- filter?: (req: IncomingMessage, res: ServerResponse) => boolean;
332
- /**
333
- * The level of zlib compression to apply to responses.
334
- * A higher level will result in better compression, but will take longer to complete.
335
- * A lower level will result in less compression, but will be much faster.
336
- * This is an integer in the range of 0 (no compression) to 9 (maximum compression).
337
- * @default
338
- * - 1 (fastest) for dev server (also known as `zlib.constants.Z_BEST_SPEED`)
339
- * - 6 for preview server (also known as `zlib.constants.Z_DEFAULT_COMPRESSION`)
340
- */
341
- level?: number;
292
+ */ export type CompressOptions = {
293
+ /**
294
+ * A function that determines whether a response should be compressed.
295
+ * @param req - The incoming HTTP request
296
+ * @param res - The outgoing HTTP response
297
+ * @returns `true` to compress the response, `false` to skip compression
298
+ */ filter?: (req: IncomingMessage, res: ServerResponse) => boolean;
299
+ /**
300
+ * The level of zlib compression to apply to responses.
301
+ * A higher level will result in better compression, but will take longer to complete.
302
+ * A lower level will result in less compression, but will be much faster.
303
+ * This is an integer in the range of 0 (no compression) to 9 (maximum compression).
304
+ * @default
305
+ * - 1 (fastest) for dev server (also known as `zlib.constants.Z_BEST_SPEED`)
306
+ * - 6 for preview server (also known as `zlib.constants.Z_DEFAULT_COMPRESSION`)
307
+ */ level?: number;
342
308
  };
343
309
  export interface ServerConfig {
344
310
  /**
345
- * Configure the base path of the server.
346
- * @default '/'
347
- */
348
- base?: string;
349
- /**
350
- * Whether to enable gzip compression for served static assets.
351
- * Pass an object to customize the compression behavior.
352
- * @default true
353
- */
354
- compress?: boolean | CompressOptions;
355
- /**
356
- * Serving static files from the directory
357
- * @default { name: 'public', copyOnBuild: 'auto', watch: false }
358
- */
359
- publicDir?: PublicDir;
360
- /**
361
- * Specify a port number for Rsbuild server to listen.
362
- * @default 3000
363
- */
364
- port?: number;
365
- /**
366
- * Configure HTTPS options to enable HTTPS server.
367
- * When enabled, HTTP server will be disabled.
368
- * @default undefined
369
- */
370
- https?: HttpsServerOptions | SecureServerSessionOptions;
371
- /**
372
- * Specify the host that the Rsbuild server listens to.
373
- * - `string`: specify a hostname or IP address to listen on.
374
- * - `true`: equals to `0.0.0.0`, listen on all interfaces.
375
- * - `false`: equals to `localhost`
376
- * @default 'localhost'
377
- */
378
- host?: string | boolean;
379
- /**
380
- * Adds headers to all responses.
381
- */
382
- headers?: Record<string, string | string[]>;
383
- /**
384
- * Whether to enable HTML fallback.
385
- * @default 'index'
386
- */
387
- htmlFallback?: HtmlFallback;
388
- /**
389
- * Used to support routing based on the history API.
390
- * When a user visits a path that does not exist, it will automatically
391
- * return a specified HTML file to avoid a 404 error.
392
- * @default false
393
- */
394
- historyApiFallback?: boolean | HistoryApiFallbackOptions;
395
- /**
396
- * Set the page URL to open when the server starts.
397
- * @default false
398
- */
399
- open?: boolean | string | string[] | {
311
+ * Configure the base path of the server.
312
+ * @default '/'
313
+ */ base?: string;
314
+ /**
315
+ * Whether to enable gzip compression for served static assets.
316
+ * Pass an object to customize the compression behavior.
317
+ * @default true
318
+ */ compress?: boolean | CompressOptions;
319
+ /**
320
+ * Serving static files from the directory
321
+ * @default { name: 'public', copyOnBuild: 'auto', watch: false }
322
+ */ publicDir?: PublicDir;
323
+ /**
324
+ * Specify a port number for Rsbuild server to listen.
325
+ * @default 3000
326
+ */ port?: number;
327
+ /**
328
+ * Configure HTTPS options to enable HTTPS server.
329
+ * When enabled, HTTP server will be disabled.
330
+ * @default undefined
331
+ */ https?: HttpsServerOptions | SecureServerSessionOptions;
332
+ /**
333
+ * Specify the host that the Rsbuild server listens to.
334
+ * - `string`: specify a hostname or IP address to listen on.
335
+ * - `true`: equals to `0.0.0.0`, listen on all interfaces.
336
+ * - `false`: equals to `localhost`
337
+ * @default 'localhost'
338
+ */ host?: string | boolean;
339
+ /**
340
+ * Adds headers to all responses.
341
+ */ headers?: Record<string, string | string[]>;
342
+ /**
343
+ * Whether to enable HTML fallback.
344
+ * @default 'index'
345
+ */ htmlFallback?: HtmlFallback;
346
+ /**
347
+ * Used to support routing based on the history API.
348
+ * When a user visits a path that does not exist, it will automatically
349
+ * return a specified HTML file to avoid a 404 error.
350
+ * @default false
351
+ */ historyApiFallback?: boolean | HistoryApiFallbackOptions;
352
+ /**
353
+ * Set the page URL to open when the server starts.
354
+ * @default false
355
+ */ open?: boolean | string | string[] | {
400
356
  target?: string | string[];
401
357
  before?: () => Promise<void> | void;
402
358
  };
403
359
  /**
404
- * Configure CORS for the dev server or preview server.
405
- * - object: enable CORS with the specified options.
406
- * - true: enable CORS with default options (allow all origins, not recommended).
407
- * - false: disable CORS.
408
- * @default
409
- * ```js
410
- * { origin: defaultAllowedOrigins }
411
- * ```
412
- * where `defaultAllowedOrigins` includes:
413
- * - `localhost`
414
- * - `127.0.0.1`
415
- * - `[::1]`
416
- *
417
- * @link https://github.com/expressjs/cors
418
- */
419
- cors?: boolean | Cors.CorsOptions;
420
- /**
421
- * Configure proxy rules for the dev server or preview server to proxy requests to
422
- * the specified service.
423
- */
424
- proxy?: ProxyConfig;
425
- /**
426
- * Whether to throw an error when the port is occupied.
427
- * @default false
428
- */
429
- strictPort?: boolean;
430
- /**
431
- * Controls whether and how server URLs are printed when the server starts.
432
- * @default true
433
- */
434
- printUrls?: PrintUrls;
435
- /**
436
- * Whether to create Rsbuild's server in middleware mode, which is useful for
437
- * integrating with other servers.
438
- * @default false
439
- */
440
- middlewareMode?: boolean;
441
- /**
442
- * Run setup logic when the Rsbuild dev server or preview server starts,
443
- * such as registering custom middleware or running pre-start tasks.
444
- *
445
- * When `server.setup` is called, Rsbuild built-in middlewares are not registered yet,
446
- * so middlewares you add run earlier than built-ins.
447
- *
448
- * `server.setup` can return a callback function. After built-in middlewares are registered,
449
- * Rsbuild will execute that callback. Middlewares registered in the callback run later than built-ins.
450
- *
451
- * @default undefined
452
- */
453
- setup?: ServerSetupFn | ServerSetupFn[];
360
+ * Configure CORS for the dev server or preview server.
361
+ * - object: enable CORS with the specified options.
362
+ * - true: enable CORS with default options (allow all origins, not recommended).
363
+ * - false: disable CORS.
364
+ * @default
365
+ * ```js
366
+ * { origin: defaultAllowedOrigins }
367
+ * ```
368
+ * where `defaultAllowedOrigins` includes:
369
+ * - `localhost`
370
+ * - `127.0.0.1`
371
+ * - `[::1]`
372
+ *
373
+ * @link https://github.com/expressjs/cors
374
+ */ cors?: boolean | Cors.CorsOptions;
375
+ /**
376
+ * Configure proxy rules for the dev server or preview server to proxy requests to
377
+ * the specified service.
378
+ */ proxy?: ProxyConfig;
379
+ /**
380
+ * Whether to throw an error when the port is occupied.
381
+ * @default false
382
+ */ strictPort?: boolean;
383
+ /**
384
+ * Controls whether and how server URLs are printed when the server starts.
385
+ * @default true
386
+ */ printUrls?: PrintUrls;
387
+ /**
388
+ * Whether to create Rsbuild's server in middleware mode, which is useful for
389
+ * integrating with other servers.
390
+ * @default false
391
+ */ middlewareMode?: boolean;
392
+ /**
393
+ * Run setup logic when the Rsbuild dev server or preview server starts,
394
+ * such as registering custom middleware or running pre-start tasks.
395
+ *
396
+ * When `server.setup` is called, Rsbuild built-in middlewares are not registered yet,
397
+ * so middlewares you add run earlier than built-ins.
398
+ *
399
+ * `server.setup` can return a callback function. After built-in middlewares are registered,
400
+ * Rsbuild will execute that callback. Middlewares registered in the callback run later than built-ins.
401
+ *
402
+ * @default undefined
403
+ */ setup?: ServerSetupFn | ServerSetupFn[];
454
404
  }
455
405
  export type NormalizedServerConfig = {
456
406
  host: string;
@@ -458,98 +408,82 @@ export type NormalizedServerConfig = {
458
408
  } & Omit<Optional<Required<ServerConfig>, 'headers' | 'https' | 'historyApiFallback' | 'proxy' | 'setup'>, 'host' | 'publicDir'>;
459
409
  export type ServerSetupContext = {
460
410
  /**
461
- * Environment contexts of all environments.
462
- */
463
- environments: Record<string, EnvironmentContext>;
411
+ * Environment contexts of all environments.
412
+ */ environments: Record<string, EnvironmentContext>;
464
413
  } & ({
465
414
  /**
466
- * Action type of current server.
467
- */
468
- action: 'dev';
415
+ * Action type of current server.
416
+ */ action: 'dev';
469
417
  /**
470
- * Dev server instance, only available in dev mode.
471
- */
472
- server: RsbuildDevServer;
418
+ * Dev server instance, only available in dev mode.
419
+ */ server: RsbuildDevServer;
473
420
  } | {
474
421
  /**
475
- * Action type of current server.
476
- */
477
- action: 'preview';
422
+ * Action type of current server.
423
+ */ action: 'preview';
478
424
  /**
479
- * Preview server instance, only available in preview mode.
480
- */
481
- server: RsbuildPreviewServer;
425
+ * Preview server instance, only available in preview mode.
426
+ */ server: RsbuildPreviewServer;
482
427
  });
483
428
  /**
484
429
  * Server setup function.
485
430
  * Return a callback to run after built-in middlewares are registered.
486
- */
487
- export type ServerSetupFn = (context: ServerSetupContext) => MaybePromise<(() => MaybePromise<void>) | void>;
431
+ */ export type ServerSetupFn = (context: ServerSetupContext) => MaybePromise<(() => MaybePromise<void>) | void>;
488
432
  export type SriAlgorithm = 'sha256' | 'sha384' | 'sha512';
489
433
  export type SriOptions = {
490
434
  /**
491
- * Specifies the algorithm used to compute the integrity hash.
492
- * @default 'sha384'
493
- */
494
- algorithm?: SriAlgorithm | SriAlgorithm[];
435
+ * Specifies the algorithm used to compute the integrity hash.
436
+ * @default 'sha384'
437
+ */ algorithm?: SriAlgorithm | SriAlgorithm[];
495
438
  /**
496
- * Whether to enable SRI.
497
- * `'auto'` means it's enabled in production mode and disabled in development mode.
498
- * @default false
499
- */
500
- enable?: boolean | 'auto';
439
+ * Whether to enable SRI.
440
+ * `'auto'` means it's enabled in production mode and disabled in development mode.
441
+ * @default false
442
+ */ enable?: boolean | 'auto';
501
443
  };
502
444
  export interface SecurityConfig {
503
445
  /**
504
- * Adding a `nonce` attribute to the scripts resources introduced for HTML. This allows
505
- * the browser to determine whether the script can be executed when it parses inline
506
- * scripts with matching nonce values.
507
- */
508
- nonce?: string;
509
- /**
510
- * Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML
511
- * allows the browser to verify the integrity of the introduced resource, thus preventing
512
- * tampering with the downloaded resource.
513
- */
514
- sri?: SriOptions;
446
+ * Adding a `nonce` attribute to the scripts resources introduced for HTML. This allows
447
+ * the browser to determine whether the script can be executed when it parses inline
448
+ * scripts with matching nonce values.
449
+ */ nonce?: string;
450
+ /**
451
+ * Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML
452
+ * allows the browser to verify the integrity of the introduced resource, thus preventing
453
+ * tampering with the downloaded resource.
454
+ */ sri?: SriOptions;
515
455
  }
516
456
  export type NormalizedSecurityConfig = Required<SecurityConfig>;
517
457
  export type ConsoleType = 'log' | 'info' | 'warn' | 'error' | 'table' | 'group';
518
458
  export type BuildCacheOptions = {
519
459
  /**
520
- * The output directory of the cache files.
521
- * @default 'node_modules/.cache'
522
- */
523
- cacheDirectory?: string;
524
- /**
525
- * Add additional cache digests, the previous build cache will be invalidated
526
- * when any value in the array changes.
527
- * @default undefined
528
- */
529
- cacheDigest?: (string | undefined)[];
530
- /**
531
- * An array of files containing build dependencies.
532
- * Rspack will use the hash of each of these files to invalidate the persistent cache.
533
- */
534
- buildDependencies?: string[];
460
+ * The output directory of the cache files.
461
+ * @default 'node_modules/.cache'
462
+ */ cacheDirectory?: string;
463
+ /**
464
+ * Add additional cache digests, the previous build cache will be invalidated
465
+ * when any value in the array changes.
466
+ * @default undefined
467
+ */ cacheDigest?: (string | undefined)[];
468
+ /**
469
+ * An array of files containing build dependencies.
470
+ * Rspack will use the hash of each of these files to invalidate the persistent cache.
471
+ */ buildDependencies?: string[];
535
472
  };
536
473
  export type PrintFileSizeAsset = {
537
474
  /**
538
- * The name of the asset.
539
- * @example 'index.html', 'static/js/index.[hash].js'
540
- */
541
- name: string;
475
+ * The name of the asset.
476
+ * @example 'index.html', 'static/js/index.[hash].js'
477
+ */ name: string;
542
478
  /**
543
- * The size of the asset in bytes.
544
- */
545
- size: number;
479
+ * The size of the asset in bytes.
480
+ */ size: number;
546
481
  };
547
482
  export type PrintFileSizeOptions = {
548
483
  /**
549
- * Whether to print the total size of all static assets, or a function to generate custom total output.
550
- * @default true
551
- */
552
- total?: boolean | ((params: {
484
+ * Whether to print the total size of all static assets, or a function to generate custom total output.
485
+ * @default true
486
+ */ total?: boolean | ((params: {
553
487
  environmentName: string;
554
488
  distPath: string;
555
489
  assets: PrintFileSizeAsset[];
@@ -557,47 +491,40 @@ export type PrintFileSizeOptions = {
557
491
  totalGzipSize: number;
558
492
  }) => string);
559
493
  /**
560
- * Whether to print the size of each static asset.
561
- * @default true
562
- */
563
- detail?: boolean;
564
- /**
565
- * Whether to print the gzip-compressed size of each static asset.
566
- * Disable this option can save some gzip computation time for large projects.
567
- * @default true
568
- */
569
- compressed?: boolean;
570
- /**
571
- * A filter function to determine which static assets to print.
572
- * If returned `false`, the static asset will be excluded and not included in the
573
- * total size or detailed size.
574
- * @default undefined
575
- */
576
- include?: (asset: PrintFileSizeAsset) => boolean;
577
- /**
578
- * A filter function to exclude static assets from the total size or detailed size.
579
- * If both `include` and `exclude` are set, `exclude` will take precedence.
580
- * @default (asset) => /\.(?:map|LICENSE\.txt)$/.test(asset.name)
581
- */
582
- exclude?: (asset: PrintFileSizeAsset) => boolean;
583
- /**
584
- * Controls whether file size differences are displayed relative to the previous build.
585
- * When this option is enabled, Rsbuild records a snapshot of all output file sizes after
586
- * each build. On subsequent builds, Rsbuild compares the current sizes against the previous
587
- * snapshot and shows the change inline in parentheses.
588
- * @default false
589
- */
590
- diff?: boolean;
494
+ * Whether to print the size of each static asset.
495
+ * @default true
496
+ */ detail?: boolean;
497
+ /**
498
+ * Whether to print the gzip-compressed size of each static asset.
499
+ * Disable this option can save some gzip computation time for large projects.
500
+ * @default true
501
+ */ compressed?: boolean;
502
+ /**
503
+ * A filter function to determine which static assets to print.
504
+ * If returned `false`, the static asset will be excluded and not included in the
505
+ * total size or detailed size.
506
+ * @default undefined
507
+ */ include?: (asset: PrintFileSizeAsset) => boolean;
508
+ /**
509
+ * A filter function to exclude static assets from the total size or detailed size.
510
+ * If both `include` and `exclude` are set, `exclude` will take precedence.
511
+ * @default (asset) => /\.(?:map|LICENSE\.txt)$/.test(asset.name)
512
+ */ exclude?: (asset: PrintFileSizeAsset) => boolean;
513
+ /**
514
+ * Controls whether file size differences are displayed relative to the previous build.
515
+ * When this option is enabled, Rsbuild records a snapshot of all output file sizes after
516
+ * each build. On subsequent builds, Rsbuild compares the current sizes against the previous
517
+ * snapshot and shows the change inline in parentheses.
518
+ * @default false
519
+ */ diff?: boolean;
591
520
  };
592
521
  export interface PreconnectOption {
593
522
  /**
594
- * The URL of the resource to preconnect to.
595
- */
596
- href: string;
523
+ * The URL of the resource to preconnect to.
524
+ */ href: string;
597
525
  /**
598
- * Whether to add `crossorigin` attribute to the `<link>` element.
599
- */
600
- crossorigin?: boolean;
526
+ * Whether to add `crossorigin` attribute to the `<link>` element.
527
+ */ crossorigin?: boolean;
601
528
  }
602
529
  export type Preconnect = (string | PreconnectOption)[];
603
530
  export type DnsPrefetch = string[];
@@ -606,102 +533,90 @@ export type ResourceHintsFilterFn = (filename: string) => boolean;
606
533
  export type ResourceHintsFilter = OneOrMany<string | RegExp | ResourceHintsFilterFn>;
607
534
  export interface ResourceHintsOptions {
608
535
  /**
609
- * Specifies which types of resources will be included.
610
- * - `async-chunks`: Includes all async resources on the current page, such as async JS
611
- * chunks, and its associated CSS, images, fonts, and other static resources.
612
- * - `initial`: Includes all non-async resources on the current page.
613
- * - `all-chunks`: Includes all async and non-async resources on the current page.
614
- * - `all-assets`: Includes all resources from all pages.
615
- * @default 'async-chunks'
616
- */
617
- type?: ResourceHintsIncludeType;
618
- /**
619
- * A extra filter to determine which resources to include.
620
- */
621
- include?: ResourceHintsFilter;
622
- /**
623
- * A extra filter to determine which resources to exclude.
624
- */
625
- exclude?: ResourceHintsFilter;
626
- /**
627
- * Whether to dedupe script resources that already exist in the current HTML content.
628
- * By default, if a resource has been added to the current HTML via a script tag, it will
629
- * not be preloaded additionally.
630
- * @default true
631
- */
632
- dedupe?: boolean;
536
+ * Specifies which types of resources will be included.
537
+ * - `async-chunks`: Includes all async resources on the current page, such as async JS
538
+ * chunks, and its associated CSS, images, fonts, and other static resources.
539
+ * - `initial`: Includes all non-async resources on the current page.
540
+ * - `all-chunks`: Includes all async and non-async resources on the current page.
541
+ * - `all-assets`: Includes all resources from all pages.
542
+ * @default 'async-chunks'
543
+ */ type?: ResourceHintsIncludeType;
544
+ /**
545
+ * A extra filter to determine which resources to include.
546
+ */ include?: ResourceHintsFilter;
547
+ /**
548
+ * A extra filter to determine which resources to exclude.
549
+ */ exclude?: ResourceHintsFilter;
550
+ /**
551
+ * Whether to dedupe script resources that already exist in the current HTML content.
552
+ * By default, if a resource has been added to the current HTML via a script tag, it will
553
+ * not be preloaded additionally.
554
+ * @default true
555
+ */ dedupe?: boolean;
633
556
  }
634
557
  export type PreloadOptions = ResourceHintsOptions;
635
558
  export type PrefetchOptions = Omit<ResourceHintsOptions, 'dedupe'>;
636
559
  export interface PerformanceConfig {
637
560
  /**
638
- * Whether to remove `console.[methodName]` in production build.
639
- * @default false
640
- */
641
- removeConsole?: boolean | ConsoleType[];
642
- /**
643
- * To enable or configure persistent build cache.
644
- * @experimental This feature is experimental and may be changed in the future.
645
- * @default false
646
- */
647
- buildCache?: BuildCacheOptions | boolean;
648
- /**
649
- * Whether to print the file sizes after production build.
650
- * @default true
651
- */
652
- printFileSize?: PrintFileSizeOptions | boolean;
653
- /**
654
- * Configure the chunk splitting strategy.
655
- * @deprecated Use `splitChunks` instead.
656
- */
657
- chunkSplit?: ChunkSplit;
658
- /**
659
- * Used to control resource `Preconnect`.
660
- *
661
- * Specifies that the user agent should preemptively connect to the target resource's origin.
662
- */
663
- preconnect?: Preconnect;
664
- /**
665
- * Used to control resource `DnsPrefetch`.
666
- *
667
- * Specifies that the user agent should preemptively perform DNS resolution for the target
668
- * resource's origin.
669
- */
670
- dnsPrefetch?: DnsPrefetch;
671
- /**
672
- * Inject the `<link rel="preload">` tags for the static assets generated by Rsbuild.
673
- *
674
- * `performance.preload` can be set to an object to specify the options.
675
- *
676
- * When `performance.preload` is set to `true`, Rsbuild will use the following default
677
- * options to preload resources. This means preloading all async resources on the current
678
- * page, including async JS and its associated CSS, image, font, and other resources.
679
- *
680
- * ```js
681
- * const defaultOptions = {
682
- * type: 'async-chunks',
683
- * };
684
- * ```
685
- * @default undefined
686
- */
687
- preload?: true | PreloadOptions;
688
- /**
689
- * Inject the `<link rel="prefetch">` tags for the static assets generated by Rsbuild.
690
- *
691
- * `performance.prefetch` can be set to an object to specify the options.
692
- *
693
- * When `performance.prefetch` is set to `true`, Rsbuild will use the following default
694
- * options to prefetch resources. This means prefetching all async resources on the current
695
- * page, including async JS and its associated CSS, image, font, and other resources.
696
- *
697
- * ```js
698
- * const defaultOptions = {
699
- * type: 'async-chunks',
700
- * };
701
- * ```
702
- * @default undefined
703
- */
704
- prefetch?: true | PrefetchOptions;
561
+ * Whether to remove `console.[methodName]` in production build.
562
+ * @default false
563
+ */ removeConsole?: boolean | ConsoleType[];
564
+ /**
565
+ * To enable or configure persistent build cache.
566
+ * @experimental This feature is experimental and may be changed in the future.
567
+ * @default false
568
+ */ buildCache?: BuildCacheOptions | boolean;
569
+ /**
570
+ * Whether to print the file sizes after production build.
571
+ * @default true
572
+ */ printFileSize?: PrintFileSizeOptions | boolean;
573
+ /**
574
+ * Configure the chunk splitting strategy.
575
+ * @deprecated Use `splitChunks` instead.
576
+ */ chunkSplit?: ChunkSplit;
577
+ /**
578
+ * Used to control resource `Preconnect`.
579
+ *
580
+ * Specifies that the user agent should preemptively connect to the target resource's origin.
581
+ */ preconnect?: Preconnect;
582
+ /**
583
+ * Used to control resource `DnsPrefetch`.
584
+ *
585
+ * Specifies that the user agent should preemptively perform DNS resolution for the target
586
+ * resource's origin.
587
+ */ dnsPrefetch?: DnsPrefetch;
588
+ /**
589
+ * Inject the `<link rel="preload">` tags for the static assets generated by Rsbuild.
590
+ *
591
+ * `performance.preload` can be set to an object to specify the options.
592
+ *
593
+ * When `performance.preload` is set to `true`, Rsbuild will use the following default
594
+ * options to preload resources. This means preloading all async resources on the current
595
+ * page, including async JS and its associated CSS, image, font, and other resources.
596
+ *
597
+ * ```js
598
+ * const defaultOptions = {
599
+ * type: 'async-chunks',
600
+ * };
601
+ * ```
602
+ * @default undefined
603
+ */ preload?: true | PreloadOptions;
604
+ /**
605
+ * Inject the `<link rel="prefetch">` tags for the static assets generated by Rsbuild.
606
+ *
607
+ * `performance.prefetch` can be set to an object to specify the options.
608
+ *
609
+ * When `performance.prefetch` is set to `true`, Rsbuild will use the following default
610
+ * options to prefetch resources. This means prefetching all async resources on the current
611
+ * page, including async JS and its associated CSS, image, font, and other resources.
612
+ *
613
+ * ```js
614
+ * const defaultOptions = {
615
+ * type: 'async-chunks',
616
+ * };
617
+ * ```
618
+ * @default undefined
619
+ */ prefetch?: true | PrefetchOptions;
705
620
  }
706
621
  export interface NormalizedPerformanceConfig extends PerformanceConfig {
707
622
  printFileSize: PrintFileSizeOptions | boolean;
@@ -714,8 +629,7 @@ export type SplitChunks = Rspack.OptimizationSplitChunksOptions | false;
714
629
  * - `per-package`: splits dependencies in `node_modules` by npm package.
715
630
  * - `single-vendor`: splits all `node_modules` dependencies into one vendor chunk.
716
631
  * - `none`: disables Rsbuild preset rules.
717
- */
718
- export type SplitChunksPreset = 'default' | 'single-vendor' | 'per-package' | 'none';
632
+ */ export type SplitChunksPreset = 'default' | 'single-vendor' | 'per-package' | 'none';
719
633
  export type SplitChunksConfig = Rspack.OptimizationSplitChunksOptions & {
720
634
  preset?: SplitChunksPreset;
721
635
  };
@@ -741,163 +655,134 @@ export interface SplitCustom extends BaseSplitRules {
741
655
  export type ChunkSplit = BaseChunkSplit | SplitBySize | SplitCustom;
742
656
  export type DistPathConfig = {
743
657
  /**
744
- * The root directory of all files.
745
- * @default 'dist'
746
- **/
747
- root?: string;
748
- /**
749
- * The output directory of JavaScript files.
750
- * @default 'static/js'
751
- */
752
- js?: string;
753
- /**
754
- * The output directory of async JavaScript files.
755
- * @default 'static/js/async'
756
- */
757
- jsAsync?: string;
758
- /**
759
- * The output directory of CSS files.
760
- * @default 'static/css'
761
- */
762
- css?: string;
763
- /**
764
- * The output directory of async CSS files.
765
- * @default 'static/css/async'
766
- */
767
- cssAsync?: string;
768
- /**
769
- * The output directory of SVG images.
770
- * @default 'static/svg'
771
- */
772
- svg?: string;
773
- /**
774
- * The output directory of font files.
775
- * @default 'static/font'
776
- */
777
- font?: string;
778
- /**
779
- * The output directory of HTML files.
780
- * @default './'
781
- */
782
- html?: string;
783
- /**
784
- * The output directory of Wasm files.
785
- * @default 'static/wasm'
786
- */
787
- wasm?: string;
788
- /**
789
- * The output directory of non-SVG images.
790
- * @default 'static/image'
791
- */
792
- image?: string;
793
- /**
794
- * The output directory of media resources, such as videos.
795
- * @default 'static/media'
796
- */
797
- media?: string;
798
- /**
799
- * The output directory of assets, except for above (image, svg, font, html, wasm...)
800
- * @default 'static/assets'
801
- */
802
- assets?: string;
803
- /**
804
- * The output directory of favicon.
805
- * @default './'
806
- */
807
- favicon?: string;
658
+ * The root directory of all files.
659
+ * @default 'dist'
660
+ **/ root?: string;
661
+ /**
662
+ * The output directory of JavaScript files.
663
+ * @default 'static/js'
664
+ */ js?: string;
665
+ /**
666
+ * The output directory of async JavaScript files.
667
+ * @default 'static/js/async'
668
+ */ jsAsync?: string;
669
+ /**
670
+ * The output directory of CSS files.
671
+ * @default 'static/css'
672
+ */ css?: string;
673
+ /**
674
+ * The output directory of async CSS files.
675
+ * @default 'static/css/async'
676
+ */ cssAsync?: string;
677
+ /**
678
+ * The output directory of SVG images.
679
+ * @default 'static/svg'
680
+ */ svg?: string;
681
+ /**
682
+ * The output directory of font files.
683
+ * @default 'static/font'
684
+ */ font?: string;
685
+ /**
686
+ * The output directory of HTML files.
687
+ * @default './'
688
+ */ html?: string;
689
+ /**
690
+ * The output directory of Wasm files.
691
+ * @default 'static/wasm'
692
+ */ wasm?: string;
693
+ /**
694
+ * The output directory of non-SVG images.
695
+ * @default 'static/image'
696
+ */ image?: string;
697
+ /**
698
+ * The output directory of media resources, such as videos.
699
+ * @default 'static/media'
700
+ */ media?: string;
701
+ /**
702
+ * The output directory of assets, except for above (image, svg, font, html, wasm...)
703
+ * @default 'static/assets'
704
+ */ assets?: string;
705
+ /**
706
+ * The output directory of favicon.
707
+ * @default './'
708
+ */ favicon?: string;
808
709
  };
809
710
  export type FilenameConfig = {
810
711
  /**
811
- * The name of HTML files.
812
- * @default `[name].html`
813
- */
814
- html?: string;
815
- /**
816
- * The name of the JavaScript files.
817
- * @default
818
- * - dev: '[name].js'
819
- * - prod: '[name].[contenthash:10].js'
820
- */
821
- js?: Rspack.Filename;
822
- /**
823
- * The name of the CSS files.
824
- * @default
825
- * - dev: '[name].css'
826
- * - prod: '[name].[contenthash:10].css'
827
- */
828
- css?: Rspack.CssFilename;
829
- /**
830
- * The name of the SVG images.
831
- * @default '[name].[contenthash:10].svg'
832
- */
833
- svg?: Rspack.AssetModuleFilename;
834
- /**
835
- * The name of the font files.
836
- * @default '[name].[contenthash:10][ext]'
837
- */
838
- font?: Rspack.AssetModuleFilename;
839
- /**
840
- * The name of non-SVG images.
841
- * @default '[name].[contenthash:10][ext]'
842
- */
843
- image?: Rspack.AssetModuleFilename;
844
- /**
845
- * The name of media assets, such as video.
846
- * @default '[name].[contenthash:10][ext]'
847
- */
848
- media?: Rspack.AssetModuleFilename;
849
- /**
850
- * The name of Wasm files.
851
- * @default '[hash].module.wasm'
852
- */
853
- wasm?: Rspack.WebassemblyModuleFilename;
854
- /**
855
- * The name of other assets, except for above (image, svg, font, html, wasm...)
856
- * @default '[name].[contenthash:10][ext]'
857
- */
858
- assets?: Rspack.AssetModuleFilename;
712
+ * The name of HTML files.
713
+ * @default `[name].html`
714
+ */ html?: string;
715
+ /**
716
+ * The name of the JavaScript files.
717
+ * @default
718
+ * - dev: '[name].js'
719
+ * - prod: '[name].[contenthash:10].js'
720
+ */ js?: Rspack.Filename;
721
+ /**
722
+ * The name of the CSS files.
723
+ * @default
724
+ * - dev: '[name].css'
725
+ * - prod: '[name].[contenthash:10].css'
726
+ */ css?: Rspack.CssFilename;
727
+ /**
728
+ * The name of the SVG images.
729
+ * @default '[name].[contenthash:10].svg'
730
+ */ svg?: Rspack.AssetModuleFilename;
731
+ /**
732
+ * The name of the font files.
733
+ * @default '[name].[contenthash:10][ext]'
734
+ */ font?: Rspack.AssetModuleFilename;
735
+ /**
736
+ * The name of non-SVG images.
737
+ * @default '[name].[contenthash:10][ext]'
738
+ */ image?: Rspack.AssetModuleFilename;
739
+ /**
740
+ * The name of media assets, such as video.
741
+ * @default '[name].[contenthash:10][ext]'
742
+ */ media?: Rspack.AssetModuleFilename;
743
+ /**
744
+ * The name of Wasm files.
745
+ * @default '[hash].module.wasm'
746
+ */ wasm?: Rspack.WebassemblyModuleFilename;
747
+ /**
748
+ * The name of other assets, except for above (image, svg, font, html, wasm...)
749
+ * @default '[name].[contenthash:10][ext]'
750
+ */ assets?: Rspack.AssetModuleFilename;
859
751
  };
860
752
  export type FilenameHash = boolean | string | {
861
753
  /**
862
- * Controls whether to add filename hash.
863
- * - `true`: JavaScript and CSS filenames include hash in production mode.
864
- * - `false`: Disable filename hash.
865
- * - `'always'`: JavaScript and CSS filenames include hash in all modes.
866
- * @default true
867
- */
868
- enable?: boolean | 'always';
869
- /**
870
- * The filename hash format.
871
- * @default 'contenthash:10'
872
- */
873
- format?: string;
754
+ * Controls whether to add filename hash.
755
+ * - `true`: JavaScript and CSS filenames include hash in production mode.
756
+ * - `false`: Disable filename hash.
757
+ * - `'always'`: JavaScript and CSS filenames include hash in all modes.
758
+ * @default true
759
+ */ enable?: boolean | 'always';
760
+ /**
761
+ * The filename hash format.
762
+ * @default 'contenthash:10'
763
+ */ format?: string;
874
764
  };
875
765
  export type DataUriLimit = {
876
766
  /**
877
- * The data URI limit of the SVG image.
878
- * @default 4096
879
- */
880
- svg?: number;
881
- /**
882
- * The data URI limit of the font file.
883
- * @default 4096
884
- */
885
- font?: number;
886
- /**
887
- * The data URI limit of non-SVG images.
888
- * @default 4096
889
- */
890
- image?: number;
891
- /**
892
- * The data URI limit of media resources such as videos.
893
- * @default 4096
894
- */
895
- media?: number;
896
- /**
897
- * The data URI limit of other static assets.
898
- * @default 4096
899
- */
900
- assets?: number;
767
+ * The data URI limit of the SVG image.
768
+ * @default 4096
769
+ */ svg?: number;
770
+ /**
771
+ * The data URI limit of the font file.
772
+ * @default 4096
773
+ */ font?: number;
774
+ /**
775
+ * The data URI limit of non-SVG images.
776
+ * @default 4096
777
+ */ image?: number;
778
+ /**
779
+ * The data URI limit of media resources such as videos.
780
+ * @default 4096
781
+ */ media?: number;
782
+ /**
783
+ * The data URI limit of other static assets.
784
+ * @default 4096
785
+ */ assets?: number;
901
786
  };
902
787
  export type Charset = 'ascii' | 'utf8';
903
788
  export type LegalComments = 'none' | 'inline' | 'linked';
@@ -905,107 +790,90 @@ export type NormalizedDataUriLimit = Required<DataUriLimit>;
905
790
  export type Polyfill = 'usage' | 'entry' | 'off';
906
791
  export type SourceMapExtractTarget = {
907
792
  /**
908
- * Include matched files whose existing source maps should be extracted.
909
- */
910
- include?: RuleSetCondition[];
793
+ * Include matched files whose existing source maps should be extracted.
794
+ */ include?: RuleSetCondition[];
911
795
  /**
912
- * Exclude matched files whose existing source maps should not be extracted.
913
- */
914
- exclude?: RuleSetCondition[];
796
+ * Exclude matched files whose existing source maps should not be extracted.
797
+ */ exclude?: RuleSetCondition[];
915
798
  };
916
799
  export type SourceMapExtractOptions = SourceMapExtractTarget & {
917
800
  /**
918
- * Custom rule condition for matching files whose existing source maps should
919
- * be extracted.
920
- * @default /\.(?:js|mjs|cjs|jsx)$/
921
- */
922
- test?: RuleSetCondition;
801
+ * Custom rule condition for matching files whose existing source maps should
802
+ * be extracted.
803
+ * @default /\.(?:js|mjs|cjs|jsx)$/
804
+ */ test?: RuleSetCondition;
923
805
  /**
924
- * Whether to extract existing source maps from matching JavaScript files.
925
- * @deprecated Use the flat `test`, `include`, and `exclude` fields instead.
926
- */
927
- js?: boolean | SourceMapExtractTarget;
806
+ * Whether to extract existing source maps from matching JavaScript files.
807
+ * @deprecated Use the flat `test`, `include`, and `exclude` fields instead.
808
+ */ js?: boolean | SourceMapExtractTarget;
928
809
  };
929
810
  export type SourceMapExtract = boolean | SourceMapExtractOptions;
930
811
  export type SourceMap = {
931
812
  /**
932
- * The source map type for JavaScript files.
933
- * @default isDev ? 'cheap-module-source-map' : false
934
- */
935
- js?: Rspack.Configuration['devtool'];
936
- /**
937
- * Whether to generate source map for CSS files.
938
- * @default false
939
- */
940
- css?: boolean;
941
- /**
942
- * Whether to extract existing source maps from matching input files.
943
- * This is useful when a third-party package already ships both output files
944
- * and source map files.
945
- * @default false
946
- */
947
- extract?: SourceMapExtract;
813
+ * The source map type for JavaScript files.
814
+ * @default isDev ? 'cheap-module-source-map' : false
815
+ */ js?: Rspack.Configuration['devtool'];
816
+ /**
817
+ * Whether to generate source map for CSS files.
818
+ * @default false
819
+ */ css?: boolean;
820
+ /**
821
+ * Whether to extract existing source maps from matching input files.
822
+ * This is useful when a third-party package already ships both output files
823
+ * and source map files.
824
+ * @default false
825
+ */ extract?: SourceMapExtract;
948
826
  };
949
827
  export type CSSModulesLocalsConvention = 'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
950
828
  export type CSSModules = {
951
829
  /**
952
- * Allows CSS Modules to be automatically enabled based on their filenames.
953
- * @default true
954
- */
955
- auto?: CSSLoaderModulesOptions['auto'];
956
- /**
957
- * Allows exporting names from global class names, so you can use them via import.
958
- * @default false
959
- */
960
- exportGlobals?: boolean;
961
- /**
962
- * Style of exported class names.
963
- * @default 'camelCase'
964
- */
965
- exportLocalsConvention?: CSSModulesLocalsConvention;
966
- /**
967
- * Set the local ident name of CSS Modules.
968
- * @default isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'
969
- */
970
- localIdentName?: string;
971
- /**
972
- * Controls the level of compilation applied to the input styles.
973
- * @default 'local'
974
- */
975
- mode?: CSSLoaderModulesOptions['mode'];
976
- /**
977
- * Whether to enable ES modules named export for locals.
978
- * @default false
979
- */
980
- namedExport?: boolean;
830
+ * Allows CSS Modules to be automatically enabled based on their filenames.
831
+ * @default true
832
+ */ auto?: CSSLoaderModulesOptions['auto'];
833
+ /**
834
+ * Allows exporting names from global class names, so you can use them via import.
835
+ * @default false
836
+ */ exportGlobals?: boolean;
837
+ /**
838
+ * Style of exported class names.
839
+ * @default 'camelCase'
840
+ */ exportLocalsConvention?: CSSModulesLocalsConvention;
841
+ /**
842
+ * Set the local ident name of CSS Modules.
843
+ * @default isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'
844
+ */ localIdentName?: string;
845
+ /**
846
+ * Controls the level of compilation applied to the input styles.
847
+ * @default 'local'
848
+ */ mode?: CSSLoaderModulesOptions['mode'];
849
+ /**
850
+ * Whether to enable ES modules named export for locals.
851
+ * @default false
852
+ */ namedExport?: boolean;
981
853
  };
982
854
  export type Minify = boolean | {
983
855
  /**
984
- * Whether to enable minification for JavaScript bundles.
985
- * - `true`: Enabled in production mode.
986
- * - `false`: Disabled in all modes.
987
- * - `'always'`: Enabled in all modes.
988
- * @default true
989
- */
990
- js?: boolean | 'always';
991
- /**
992
- * Minimizer options of JavaScript, which will be passed to SWC.
993
- * @default {}
994
- */
995
- jsOptions?: SwcJsMinimizerRspackPluginOptions;
996
- /**
997
- * Whether to enable minification for CSS bundles.
998
- * - `true`: Enabled in production mode.
999
- * - `false`: Disabled in all modes.
1000
- * - `'always'`: Enabled in all modes.
1001
- * @default true
1002
- */
1003
- css?: boolean | 'always';
1004
- /**
1005
- * Minimizer options of CSS, which will be passed to LightningCSS.
1006
- * @default inherit from `tools.lightningcssLoader` config
1007
- */
1008
- cssOptions?: LightningCssMinimizerRspackPluginOptions;
856
+ * Whether to enable minification for JavaScript bundles.
857
+ * - `true`: Enabled in production mode.
858
+ * - `false`: Disabled in all modes.
859
+ * - `'always'`: Enabled in all modes.
860
+ * @default true
861
+ */ js?: boolean | 'always';
862
+ /**
863
+ * Minimizer options of JavaScript, which will be passed to SWC.
864
+ * @default {}
865
+ */ jsOptions?: SwcJsMinimizerRspackPluginOptions;
866
+ /**
867
+ * Whether to enable minification for CSS bundles.
868
+ * - `true`: Enabled in production mode.
869
+ * - `false`: Disabled in all modes.
870
+ * - `'always'`: Enabled in all modes.
871
+ * @default true
872
+ */ css?: boolean | 'always';
873
+ /**
874
+ * Minimizer options of CSS, which will be passed to LightningCSS.
875
+ * @default inherit from `tools.lightningcssLoader` config
876
+ */ cssOptions?: LightningCssMinimizerRspackPluginOptions;
1009
877
  };
1010
878
  export type InlineChunkTestFunction = (params: {
1011
879
  size: number;
@@ -1018,286 +886,239 @@ export type InlineChunkConfig = boolean | InlineChunkTest | {
1018
886
  };
1019
887
  export type ManifestByEntry = {
1020
888
  /**
1021
- * Files that are required during the initial load of the entry.
1022
- */
1023
- initial?: {
1024
- /** Initial JavaScript files for this entry. */
1025
- js?: string[];
1026
- /** Initial CSS files for this entry. */
1027
- css?: string[];
889
+ * Files that are required during the initial load of the entry.
890
+ */ initial?: {
891
+ /** Initial JavaScript files for this entry. */ js?: string[];
892
+ /** Initial CSS files for this entry. */ css?: string[];
1028
893
  };
1029
894
  /**
1030
- * Files that may be loaded asynchronously.
1031
- * Usually code-split chunks or lazily loaded chunks.
1032
- */
1033
- async?: {
1034
- /** Async JavaScript files for this entry. */
1035
- js?: string[];
1036
- /** Async CSS files for this entry. */
1037
- css?: string[];
895
+ * Files that may be loaded asynchronously.
896
+ * Usually code-split chunks or lazily loaded chunks.
897
+ */ async?: {
898
+ /** Async JavaScript files for this entry. */ js?: string[];
899
+ /** Async CSS files for this entry. */ css?: string[];
1038
900
  };
1039
- /** HTML files generated for this entry, if any. */
1040
- html?: string[];
901
+ /** HTML files generated for this entry, if any. */ html?: string[];
1041
902
  /**
1042
- * Additional assets associated with this entry.
1043
- * For example images、fonts、source maps and other non JS or CSS files.
1044
- */
1045
- assets?: string[];
903
+ * Additional assets associated with this entry.
904
+ * For example images、fonts、source maps and other non JS or CSS files.
905
+ */ assets?: string[];
1046
906
  };
1047
907
  export type ManifestData = {
1048
908
  /**
1049
- * A flat list of all emitted asset files.
1050
- */
1051
- allFiles: string[];
909
+ * A flat list of all emitted asset files.
910
+ */ allFiles: string[];
1052
911
  /**
1053
- * Maps each entry name to its associated output files.
1054
- */
1055
- entries: Record<string, ManifestByEntry>;
912
+ * Maps each entry name to its associated output files.
913
+ */ entries: Record<string, ManifestByEntry>;
1056
914
  /**
1057
- * Subresource Integrity (SRI) hashes for emitted assets.
1058
- * The key is the asset file path, and the value is its integrity hash.
1059
- * This field is available only when the `security.sri` option is enabled.
1060
- */
1061
- integrity: Record<string, string>;
915
+ * Subresource Integrity (SRI) hashes for emitted assets.
916
+ * The key is the asset file path, and the value is its integrity hash.
917
+ * This field is available only when the `security.sri` option is enabled.
918
+ */ integrity: Record<string, string>;
1062
919
  };
1063
920
  export type ManifestObjectConfig = {
1064
921
  /**
1065
- * The filename or path of the manifest file.
1066
- * The manifest file will be emitted to the output directory.
1067
- * @default 'manifest.json'
1068
- */
1069
- filename?: string;
922
+ * The filename or path of the manifest file.
923
+ * The manifest file will be emitted to the output directory.
924
+ * @default 'manifest.json'
925
+ */ filename?: string;
1070
926
  /**
1071
- * A custom function to generate the content of the manifest file.
1072
- */
1073
- generate?: (params: {
927
+ * A custom function to generate the content of the manifest file.
928
+ */ generate?: (params: {
1074
929
  files: FileDescriptor[];
1075
930
  manifestData: ManifestData;
1076
931
  }) => Record<string, unknown>;
1077
932
  /**
1078
- * Allows you to filter the files included in the manifest.
1079
- * The function receives a `file` parameter and returns `true` to keep the file,
1080
- * or `false` to exclude it.
1081
- * @default (file: FileDescriptor) => !file.name.endsWith('.LICENSE.txt')
1082
- */
1083
- filter?: (file: FileDescriptor) => boolean;
1084
- /**
1085
- * Controls whether the generated manifest includes the static asset prefix in file paths.
1086
- * The prefix is taken from `dev.assetPrefix` and `output.assetPrefix`.
1087
- * @default true
1088
- */
1089
- prefix?: boolean;
933
+ * Allows you to filter the files included in the manifest.
934
+ * The function receives a `file` parameter and returns `true` to keep the file,
935
+ * or `false` to exclude it.
936
+ * @default (file: FileDescriptor) => !file.name.endsWith('.LICENSE.txt')
937
+ */ filter?: (file: FileDescriptor) => boolean;
938
+ /**
939
+ * Controls whether the generated manifest includes the static asset prefix in file paths.
940
+ * The prefix is taken from `dev.assetPrefix` and `output.assetPrefix`.
941
+ * @default true
942
+ */ prefix?: boolean;
1090
943
  };
1091
944
  export type ManifestConfig = string | boolean | ManifestObjectConfig;
1092
945
  export type CleanDistPathObject = {
1093
946
  /**
1094
- * Whether to clean up all files under the output directory before the build starts.
1095
- * @default 'auto'
1096
- */
1097
- enable?: boolean | 'auto';
947
+ * Whether to clean up all files under the output directory before the build starts.
948
+ * @default 'auto'
949
+ */ enable?: boolean | 'auto';
1098
950
  /**
1099
- * Specify the files to keep in the output directory.
1100
- * If the file's absolute path matches the regular expression in `keep`, the file
1101
- * will not be removed.
1102
- * @default undefined
1103
- */
1104
- keep?: RegExp[];
951
+ * Specify the files to keep in the output directory.
952
+ * If the file's absolute path matches the regular expression in `keep`, the file
953
+ * will not be removed.
954
+ * @default undefined
955
+ */ keep?: RegExp[];
1105
956
  };
1106
957
  export type CleanDistPath = boolean | 'auto' | CleanDistPathObject;
1107
958
  export type AutoExternalExclude = OneOrMany<string | RegExp>;
1108
959
  export type AutoExternal = boolean | {
1109
960
  /**
1110
- * Whether to automatically externalize dependencies of type `dependencies`.
1111
- * @default true
1112
- */
1113
- dependencies?: boolean;
1114
- /**
1115
- * Whether to automatically externalize dependencies of type `optionalDependencies`.
1116
- * @default true
1117
- */
1118
- optionalDependencies?: boolean;
1119
- /**
1120
- * Whether to automatically externalize dependencies of type `peerDependencies`.
1121
- * @default true
1122
- */
1123
- peerDependencies?: boolean;
1124
- /**
1125
- * Whether to automatically externalize dependencies of type `devDependencies`.
1126
- * @default false
1127
- */
1128
- devDependencies?: boolean;
1129
- /**
1130
- * Specify the package.json file path(s) used to collect dependencies.
1131
- * Relative paths are resolved from the Rsbuild root directory.
1132
- * @default '<root>/package.json'
1133
- */
1134
- packageJson?: string | string[];
1135
- /**
1136
- * Prevent matched packages from being automatically externalized.
1137
- * Strings match package names exactly, and regular expressions test package names.
1138
- * @default undefined
1139
- */
1140
- exclude?: AutoExternalExclude;
961
+ * Whether to automatically externalize dependencies of type `dependencies`.
962
+ * @default true
963
+ */ dependencies?: boolean;
964
+ /**
965
+ * Whether to automatically externalize dependencies of type `optionalDependencies`.
966
+ * @default true
967
+ */ optionalDependencies?: boolean;
968
+ /**
969
+ * Whether to automatically externalize dependencies of type `peerDependencies`.
970
+ * @default true
971
+ */ peerDependencies?: boolean;
972
+ /**
973
+ * Whether to automatically externalize dependencies of type `devDependencies`.
974
+ * @default false
975
+ */ devDependencies?: boolean;
976
+ /**
977
+ * Specify the package.json file path(s) used to collect dependencies.
978
+ * Relative paths are resolved from the Rsbuild root directory.
979
+ * @default '<root>/package.json'
980
+ */ packageJson?: string | string[];
981
+ /**
982
+ * Prevent matched packages from being automatically externalized.
983
+ * Strings match package names exactly, and regular expressions test package names.
984
+ * @default undefined
985
+ */ exclude?: AutoExternalExclude;
1141
986
  };
1142
987
  export interface OutputConfig {
1143
988
  /**
1144
- * Setting the build target for Rsbuild.
1145
- * @default 'web'
1146
- */
1147
- target?: RsbuildTarget;
1148
- /**
1149
- * Use this option to specify which modules should not be bundled by Rsbuild, and instead
1150
- * use implementations provided by the external environment.
1151
- * For more information, please see: [Rspack Externals](https://rspack.rs/config/externals)
1152
- * @default undefined
1153
- */
1154
- externals?: Externals;
1155
- /**
1156
- * Automatically externalize dependencies declared in the root package.json.
1157
- * This option will generate `externals` rules for matching dependencies and their subpath imports.
1158
- * @default false
1159
- */
1160
- autoExternal?: AutoExternal;
1161
- /**
1162
- * Set the directory of the output files.
1163
- * Rsbuild will emit files to the specified subdirectory according to the file type.
1164
- * - `string`: Set the root output directory to a specific path, equivalent to `distPath.root`.
1165
- * - `object`: Set the output directory for each file type.
1166
- */
1167
- distPath?: string | DistPathConfig;
1168
- /**
1169
- * Sets the filename of output files.
1170
- */
1171
- filename?: FilenameConfig;
1172
- /**
1173
- * Specify the character encoding format for output files.
1174
- * Can be `ascii` or `utf8`.
1175
- * @default 'utf8'
1176
- */
1177
- charset?: Charset;
1178
- /**
1179
- * Configure how the polyfill is injected.
1180
- * @default 'off'
1181
- */
1182
- polyfill?: Polyfill;
1183
- /**
1184
- * When using CDN in the production,
1185
- * you can use this option to set the URL prefix of static assets,
1186
- * similar to the `output.publicPath` config of Rspack.
1187
- * `auto` means use a relative path based on file location.
1188
- * @default `server.base`
1189
- */
1190
- assetPrefix?: LiteralUnion<'auto', string>;
1191
- /**
1192
- * Set the size threshold to inline static assets such as images and fonts.
1193
- * By default, static assets will be Base64 encoded and inline into the page if
1194
- * the size is less than 4KiB.
1195
- * @default { svg: 4096, font: 4096, image: 4096, media: 4096, assets: 4096 }
1196
- */
1197
- dataUriLimit?: number | DataUriLimit;
1198
- /**
1199
- * Configure how to handle the legal comment.
1200
- * A "legal comment" is considered to be any statement-level comment in JS or rule-level
1201
- * comment in CSS that contains @license or @preserve or that starts with //! or /\*!.
1202
- * These comments are preserved in output files by default since that follows the intent
1203
- * of the original authors of the code.
1204
- * @default 'linked'
1205
- */
1206
- legalComments?: LegalComments;
1207
- /**
1208
- * Whether to clean up all files under the output directory before the build starts.
1209
- * @default 'auto'
1210
- */
1211
- cleanDistPath?: CleanDistPath;
1212
- /**
1213
- * Allow to custom CSS Modules options.
1214
- */
1215
- cssModules?: CSSModules;
1216
- /**
1217
- * Configure whether to enable code minification in production mode, or to configure
1218
- * minimizer options.
1219
- * @default true
1220
- */
1221
- minify?: Minify;
1222
- /**
1223
- * Configure how to generate the manifest file.
1224
- * - `true`: Generate a manifest file named `manifest.json` in the output directory.
1225
- * - `false`: Do not generate the manifest file.
1226
- * - `string`: Generate a manifest file with the specified filename or path.
1227
- * - `object`: Generate a manifest file with the specified options.
1228
- * @default false
1229
- */
1230
- manifest?: ManifestConfig;
1231
- /**
1232
- * Whether to output JavaScript files in ES modules format.
1233
- * @default true when `output.target` is `node`, otherwise `false`
1234
- */
1235
- module?: boolean;
1236
- /**
1237
- * Whether to generate source map files, and which format of source map to generate.
1238
- *
1239
- * @default
1240
- * ```js
1241
- * const defaultSourceMap = {
1242
- * js: isDev ? 'cheap-module-source-map' : false,
1243
- * css: false,
1244
- * extract: false,
1245
- * };
1246
- * ```
1247
- */
1248
- sourceMap?: boolean | SourceMap;
1249
- /**
1250
- * Whether to add filename hash.
1251
- * - `true`: JavaScript and CSS filenames include hash in production mode, while other assets
1252
- * always include hash in all modes.
1253
- * - `false`: Disable filename hash.
1254
- * - `string`: Enable filename hash and customize the hash format, such as `'contenthash:16'`.
1255
- * - `object`: An object to configure filename hash behavior.
1256
- * @default true
1257
- */
1258
- filenameHash?: FilenameHash;
1259
- /**
1260
- * Whether to inline output scripts files (.js files) into HTML with `<script>` tags.
1261
- * @default false
1262
- */
1263
- inlineScripts?: InlineChunkConfig;
1264
- /**
1265
- * Whether to inline output style files (.css files) into html with `<style>` tags.
1266
- * @default false
1267
- */
1268
- inlineStyles?: InlineChunkConfig;
1269
- /**
1270
- * Whether to inject styles into the DOM via `style-loader`.
1271
- * @default false
1272
- */
1273
- injectStyles?: boolean;
1274
- /**
1275
- * Specifies the range of target browsers that the project is compatible with.
1276
- * This value will be used by [SWC](https://github.com/swc-project/swc) and
1277
- * [Lightning CSS](https://github.com/parcel-bundler/lightningcss) to identify
1278
- * the JavaScript syntax that need to be transformed and the CSS browser prefixes
1279
- * that need to be added.
1280
- * @default undefined
1281
- */
1282
- overrideBrowserslist?: string[];
1283
- /**
1284
- * Copies the specified file or directory to the dist directory.
1285
- * @default undefined
1286
- */
1287
- copy?: CopyRspackPluginOptions | CopyRspackPluginOptions['patterns'];
1288
- /**
1289
- * Whether to emit static assets such as image, font, etc.
1290
- * Return `false` to avoid outputting unnecessary assets for some scenarios such as SSR.
1291
- * @default true
1292
- */
1293
- emitAssets?: boolean;
1294
- /**
1295
- * Whether to emit CSS to the output bundles.
1296
- * If `false`, the CSS will not be extracted to separate files or injected into the
1297
- * JavaScript bundles via `output.injectStyles`.
1298
- * @default `true` when `output.target` is `web`, otherwise `false`
1299
- */
1300
- emitCss?: boolean;
989
+ * Setting the build target for Rsbuild.
990
+ * @default 'web'
991
+ */ target?: RsbuildTarget;
992
+ /**
993
+ * Use this option to specify which modules should not be bundled by Rsbuild, and instead
994
+ * use implementations provided by the external environment.
995
+ * For more information, please see: [Rspack Externals](https://rspack.rs/config/externals)
996
+ * @default undefined
997
+ */ externals?: Externals;
998
+ /**
999
+ * Automatically externalize dependencies declared in the root package.json.
1000
+ * This option will generate `externals` rules for matching dependencies and their subpath imports.
1001
+ * @default false
1002
+ */ autoExternal?: AutoExternal;
1003
+ /**
1004
+ * Set the directory of the output files.
1005
+ * Rsbuild will emit files to the specified subdirectory according to the file type.
1006
+ * - `string`: Set the root output directory to a specific path, equivalent to `distPath.root`.
1007
+ * - `object`: Set the output directory for each file type.
1008
+ */ distPath?: string | DistPathConfig;
1009
+ /**
1010
+ * Sets the filename of output files.
1011
+ */ filename?: FilenameConfig;
1012
+ /**
1013
+ * Specify the character encoding format for output files.
1014
+ * Can be `ascii` or `utf8`.
1015
+ * @default 'utf8'
1016
+ */ charset?: Charset;
1017
+ /**
1018
+ * Configure how the polyfill is injected.
1019
+ * @default 'off'
1020
+ */ polyfill?: Polyfill;
1021
+ /**
1022
+ * When using CDN in the production,
1023
+ * you can use this option to set the URL prefix of static assets,
1024
+ * similar to the `output.publicPath` config of Rspack.
1025
+ * `auto` means use a relative path based on file location.
1026
+ * @default `server.base`
1027
+ */ assetPrefix?: LiteralUnion<'auto', string>;
1028
+ /**
1029
+ * Set the size threshold to inline static assets such as images and fonts.
1030
+ * By default, static assets will be Base64 encoded and inline into the page if
1031
+ * the size is less than 4KiB.
1032
+ * @default { svg: 4096, font: 4096, image: 4096, media: 4096, assets: 4096 }
1033
+ */ dataUriLimit?: number | DataUriLimit;
1034
+ /**
1035
+ * Configure how to handle the legal comment.
1036
+ * A "legal comment" is considered to be any statement-level comment in JS or rule-level
1037
+ * comment in CSS that contains @license or @preserve or that starts with //! or /\*!.
1038
+ * These comments are preserved in output files by default since that follows the intent
1039
+ * of the original authors of the code.
1040
+ * @default 'linked'
1041
+ */ legalComments?: LegalComments;
1042
+ /**
1043
+ * Whether to clean up all files under the output directory before the build starts.
1044
+ * @default 'auto'
1045
+ */ cleanDistPath?: CleanDistPath;
1046
+ /**
1047
+ * Allow to custom CSS Modules options.
1048
+ */ cssModules?: CSSModules;
1049
+ /**
1050
+ * Configure whether to enable code minification in production mode, or to configure
1051
+ * minimizer options.
1052
+ * @default true
1053
+ */ minify?: Minify;
1054
+ /**
1055
+ * Configure how to generate the manifest file.
1056
+ * - `true`: Generate a manifest file named `manifest.json` in the output directory.
1057
+ * - `false`: Do not generate the manifest file.
1058
+ * - `string`: Generate a manifest file with the specified filename or path.
1059
+ * - `object`: Generate a manifest file with the specified options.
1060
+ * @default false
1061
+ */ manifest?: ManifestConfig;
1062
+ /**
1063
+ * Whether to output JavaScript files in ES modules format.
1064
+ * @default true when `output.target` is `node`, otherwise `false`
1065
+ */ module?: boolean;
1066
+ /**
1067
+ * Whether to generate source map files, and which format of source map to generate.
1068
+ *
1069
+ * @default
1070
+ * ```js
1071
+ * const defaultSourceMap = {
1072
+ * js: isDev ? 'cheap-module-source-map' : false,
1073
+ * css: false,
1074
+ * extract: false,
1075
+ * };
1076
+ * ```
1077
+ */ sourceMap?: boolean | SourceMap;
1078
+ /**
1079
+ * Whether to add filename hash.
1080
+ * - `true`: JavaScript and CSS filenames include hash in production mode, while other assets
1081
+ * always include hash in all modes.
1082
+ * - `false`: Disable filename hash.
1083
+ * - `string`: Enable filename hash and customize the hash format, such as `'contenthash:16'`.
1084
+ * - `object`: An object to configure filename hash behavior.
1085
+ * @default true
1086
+ */ filenameHash?: FilenameHash;
1087
+ /**
1088
+ * Whether to inline output scripts files (.js files) into HTML with `<script>` tags.
1089
+ * @default false
1090
+ */ inlineScripts?: InlineChunkConfig;
1091
+ /**
1092
+ * Whether to inline output style files (.css files) into html with `<style>` tags.
1093
+ * @default false
1094
+ */ inlineStyles?: InlineChunkConfig;
1095
+ /**
1096
+ * Whether to inject styles into the DOM via `style-loader`.
1097
+ * @default false
1098
+ */ injectStyles?: boolean;
1099
+ /**
1100
+ * Specifies the range of target browsers that the project is compatible with.
1101
+ * This value will be used by [SWC](https://github.com/swc-project/swc) and
1102
+ * [Lightning CSS](https://github.com/parcel-bundler/lightningcss) to identify
1103
+ * the JavaScript syntax that need to be transformed and the CSS browser prefixes
1104
+ * that need to be added.
1105
+ * @default undefined
1106
+ */ overrideBrowserslist?: string[];
1107
+ /**
1108
+ * Copies the specified file or directory to the dist directory.
1109
+ * @default undefined
1110
+ */ copy?: CopyRspackPluginOptions | CopyRspackPluginOptions['patterns'];
1111
+ /**
1112
+ * Whether to emit static assets such as image, font, etc.
1113
+ * Return `false` to avoid outputting unnecessary assets for some scenarios such as SSR.
1114
+ * @default true
1115
+ */ emitAssets?: boolean;
1116
+ /**
1117
+ * Whether to emit CSS to the output bundles.
1118
+ * If `false`, the CSS will not be extracted to separate files or injected into the
1119
+ * JavaScript bundles via `output.injectStyles`.
1120
+ * @default `true` when `output.target` is `web`, otherwise `false`
1121
+ */ emitCss?: boolean;
1301
1122
  }
1302
1123
  export interface NormalizedOutputConfig extends OutputConfig {
1303
1124
  target: RsbuildTarget;
@@ -1341,8 +1162,7 @@ export type OutputStructure = 'flat' | 'nested';
1341
1162
  * name: 'viewport',
1342
1163
  * content: 'width=500, initial-scale=1',
1343
1164
  * }
1344
- */
1345
- export type MetaAttrs = Record<string, string | boolean>;
1165
+ */ export type MetaAttrs = Record<string, string | boolean>;
1346
1166
  /**
1347
1167
  * Meta options in name-content form.
1348
1168
  * Key is the meta name, such as `viewport`, `description`, or `robots`.
@@ -1357,88 +1177,79 @@ export type MetaAttrs = Record<string, string | boolean>;
1357
1177
  * description: 'My awesome website',
1358
1178
  * robots: false,
1359
1179
  * }
1360
- */
1361
- export type MetaOptions = Record<string, string | false | MetaAttrs>;
1180
+ */ export type MetaOptions = Record<string, string | false | MetaAttrs>;
1362
1181
  export type HtmlBasicTag = {
1363
1182
  /**
1364
- * The HTML tag name to be generated. Should be a valid HTML element name.
1365
- * @example
1366
- * - `'script'` for JavaScript files
1367
- * - `'link'` for stylesheets or external resources
1368
- * - `'meta'` for metadata
1369
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
1370
- */
1371
- tag: string;
1372
- /**
1373
- * HTML attributes to be applied to the tag.
1374
- * - `string` values will be rendered as `attribute="value"`
1375
- * - `true` renders as boolean attribute (e.g., `<input disabled>`)
1376
- * - `false` or `null` or `undefined` values will omit the attribute
1377
- *
1378
- * @example
1379
- * // String attributes
1380
- * attrs: {
1381
- * src: 'https://example.com/script.js',
1382
- * type: 'text/javascript',
1383
- * }
1384
- * // Result: <script src="https://example.com/script.js" type="text/javascript">
1385
-
1386
- * // Boolean attributes
1387
- * attrs: {
1388
- * async: true, // <script async>
1389
- * defer: false, // attribute omitted
1390
- * }
1391
- * // Result: <script async>
1392
- */
1393
- attrs?: Record<string, string | boolean | null | undefined>;
1394
- /**
1395
- * The innerHTML content of the tag. The content is inserted as-is without
1396
- * HTML escaping, so ensure it's safe to prevent XSS vulnerabilities.
1397
- */
1398
- children?: string;
1399
- /**
1400
- * The metadata object for tags, used to store additional information about tags.
1401
- * `metadata` does not affect the generated HTML content.
1402
- * @default undefined
1403
- */
1404
- metadata?: Record<string, any>;
1183
+ * The HTML tag name to be generated. Should be a valid HTML element name.
1184
+ * @example
1185
+ * - `'script'` for JavaScript files
1186
+ * - `'link'` for stylesheets or external resources
1187
+ * - `'meta'` for metadata
1188
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
1189
+ */ tag: string;
1190
+ /**
1191
+ * HTML attributes to be applied to the tag.
1192
+ * - `string` values will be rendered as `attribute="value"`
1193
+ * - `true` renders as boolean attribute (e.g., `<input disabled>`)
1194
+ * - `false` or `null` or `undefined` values will omit the attribute
1195
+ *
1196
+ * @example
1197
+ * // String attributes
1198
+ * attrs: {
1199
+ * src: 'https://example.com/script.js',
1200
+ * type: 'text/javascript',
1201
+ * }
1202
+ * // Result: <script src="https://example.com/script.js" type="text/javascript">
1203
+
1204
+ * // Boolean attributes
1205
+ * attrs: {
1206
+ * async: true, // <script async>
1207
+ * defer: false, // attribute omitted
1208
+ * }
1209
+ * // Result: <script async>
1210
+ */ attrs?: Record<string, string | boolean | null | undefined>;
1211
+ /**
1212
+ * The innerHTML content of the tag. The content is inserted as-is without
1213
+ * HTML escaping, so ensure it's safe to prevent XSS vulnerabilities.
1214
+ */ children?: string;
1215
+ /**
1216
+ * The metadata object for tags, used to store additional information about tags.
1217
+ * `metadata` does not affect the generated HTML content.
1218
+ * @default undefined
1219
+ */ metadata?: Record<string, any>;
1405
1220
  };
1406
1221
  export type HtmlTag = HtmlBasicTag & {
1407
1222
  /**
1408
- * Controls whether to add a hash query parameter to asset URLs for cache invalidation.
1409
- * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1410
- * - `false`: No hash query
1411
- * - `true`: Generate hash based on HTML content
1412
- * - `string`: Uses a custom hash string
1413
- * - `function`: Custom hash generation via a function
1414
- * @default false
1415
- */
1416
- hash?: boolean | string | ((url: string, hash: string) => string);
1417
- /**
1418
- * Controls whether to prepend the asset prefix to resource URLs.
1419
- * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1420
- * - `true`: Prepends asset prefix to the URL
1421
- * - `false`: Uses the URL as-is
1422
- * - `string`: Uses a custom prefix
1423
- * - `function`: Custom path transformation via a function
1424
- * @default true
1425
- */
1426
- publicPath?: boolean | string | ((url: string, publicPath: string) => string);
1427
- /**
1428
- * Defines the injection position relative to existing tags.
1429
- * - `true`: Insert after existing tags
1430
- * - `false`: Insert before existing tags
1431
- * @default true
1432
- */
1433
- append?: boolean;
1434
- /**
1435
- * Specifies whether to inject the tag into the HTML `<head>` element.
1436
- * - `true`: Inject into `<head>`
1437
- * - `false`: Inject into `<body>`
1438
- * @default Auto-detect: `true` for head-allowed elements, `false` otherwise
1439
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head#see_also
1440
- */
1441
- head?: boolean;
1223
+ * Controls whether to add a hash query parameter to asset URLs for cache invalidation.
1224
+ * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1225
+ * - `false`: No hash query
1226
+ * - `true`: Generate hash based on HTML content
1227
+ * - `string`: Uses a custom hash string
1228
+ * - `function`: Custom hash generation via a function
1229
+ * @default false
1230
+ */ hash?: boolean | string | ((url: string, hash: string) => string);
1231
+ /**
1232
+ * Controls whether to prepend the asset prefix to resource URLs.
1233
+ * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1234
+ * - `true`: Prepends asset prefix to the URL
1235
+ * - `false`: Uses the URL as-is
1236
+ * - `string`: Uses a custom prefix
1237
+ * - `function`: Custom path transformation via a function
1238
+ * @default true
1239
+ */ publicPath?: boolean | string | ((url: string, publicPath: string) => string);
1240
+ /**
1241
+ * Defines the injection position relative to existing tags.
1242
+ * - `true`: Insert after existing tags
1243
+ * - `false`: Insert before existing tags
1244
+ * @default true
1245
+ */ append?: boolean;
1246
+ /**
1247
+ * Specifies whether to inject the tag into the HTML `<head>` element.
1248
+ * - `true`: Inject into `<head>`
1249
+ * - `false`: Inject into `<body>`
1250
+ * @default Auto-detect: `true` for head-allowed elements, `false` otherwise
1251
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head#see_also
1252
+ */ head?: boolean;
1442
1253
  };
1443
1254
  export type HtmlTagContext = {
1444
1255
  hash: string;
@@ -1448,156 +1259,137 @@ export type HtmlTagContext = {
1448
1259
  };
1449
1260
  export type HtmlTagHandler = (tags: HtmlTag[], context: HtmlTagContext) => HtmlTag[] | void;
1450
1261
  export type HtmlTagDescriptor = HtmlTag | HtmlTagHandler;
1451
- type ChainedHtmlOption<O> = ConfigChainMergeContext<O, {
1262
+ type ChainedHtmlOption<O> = OneOrMany<O | ((context: {
1263
+ value: O;
1452
1264
  entryName: string;
1453
- }>;
1265
+ }) => MaybePromise<O | void>)>;
1454
1266
  export type AppIconItem = {
1455
1267
  /**
1456
- * The path to the icon, can be a URL, an absolute file path,
1457
- * or a relative path to the project root.
1458
- */
1459
- src: string;
1460
- /**
1461
- * The size of the icon.
1462
- */
1463
- size: number;
1464
- /**
1465
- * Specifies the intended target for which the icon should be generated.
1466
- * - `apple-touch-icon` for iOS system.
1467
- * - `web-app-manifest` for web application manifest.
1468
- */
1469
- target?: 'apple-touch-icon' | 'web-app-manifest';
1470
- /**
1471
- * A case-sensitive keyword string that specifies one or more contexts in
1472
- * which the icon can be used by the browser or operating system.
1473
- * This field is only effective when the `target` is `'web-app-manifest'`.
1474
- *
1475
- * The possible properties include:
1476
- * - `'monochrome'`: Indicates that the icon is intended to be used as a
1477
- * monochrome icon with a solid fill.
1478
- * - `'maskable'`: Indicates that the icon is designed with icon masks and
1479
- * safe zone in mind.
1480
- * - `'any'`: Indicates that the icon can be used in any context. This is
1481
- * the default value.
1482
- * @see https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/icons#purpose
1483
- */
1484
- purpose?: LiteralUnion<'any' | 'maskable' | 'monochrome', string>;
1268
+ * The path to the icon, can be a URL, an absolute file path,
1269
+ * or a relative path to the project root.
1270
+ */ src: string;
1271
+ /**
1272
+ * The size of the icon.
1273
+ */ size: number;
1274
+ /**
1275
+ * Specifies the intended target for which the icon should be generated.
1276
+ * - `apple-touch-icon` for iOS system.
1277
+ * - `web-app-manifest` for web application manifest.
1278
+ */ target?: 'apple-touch-icon' | 'web-app-manifest';
1279
+ /**
1280
+ * A case-sensitive keyword string that specifies one or more contexts in
1281
+ * which the icon can be used by the browser or operating system.
1282
+ * This field is only effective when the `target` is `'web-app-manifest'`.
1283
+ *
1284
+ * The possible properties include:
1285
+ * - `'monochrome'`: Indicates that the icon is intended to be used as a
1286
+ * monochrome icon with a solid fill.
1287
+ * - `'maskable'`: Indicates that the icon is designed with icon masks and
1288
+ * safe zone in mind.
1289
+ * - `'any'`: Indicates that the icon can be used in any context. This is
1290
+ * the default value.
1291
+ * @see https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/icons#purpose
1292
+ */ purpose?: LiteralUnion<'any' | 'maskable' | 'monochrome', string>;
1485
1293
  };
1486
1294
  export type AppIcon = {
1487
1295
  /**
1488
- * The name of the application.
1489
- * @see https://developer.mozilla.org/en-US/docs/Web/Manifest/name
1490
- */
1491
- name?: string;
1296
+ * The name of the application.
1297
+ * @see https://developer.mozilla.org/en-US/docs/Web/Manifest/name
1298
+ */ name?: string;
1492
1299
  /**
1493
- * The list of icons.
1494
- */
1495
- icons: AppIconItem[];
1300
+ * The list of icons.
1301
+ */ icons: AppIconItem[];
1496
1302
  /**
1497
- * The filename of the manifest file.
1498
- * @default 'manifest.webmanifest'
1499
- */
1500
- filename?: string;
1303
+ * The filename of the manifest file.
1304
+ * @default 'manifest.webmanifest'
1305
+ */ filename?: string;
1501
1306
  };
1502
1307
  type HtmlImplementation = 'js' | 'native';
1503
1308
  export interface HtmlConfig {
1504
1309
  /**
1505
- * Configure the `<meta>` tag of the HTML.
1506
- *
1507
- * @default
1508
- * ```js
1509
- * const defaultMeta = {
1510
- * charset: { charset: 'utf-8' },
1511
- * viewport: 'width=device-width, initial-scale=1.0',
1512
- * };
1513
- * ```
1514
- */
1515
- meta?: ChainedHtmlOption<MetaOptions>;
1516
- /**
1517
- * Set the title tag of the HTML page.
1518
- * @default 'Rsbuild App'
1519
- */
1520
- title?: ChainedHtmlOption<string>;
1521
- /**
1522
- * Set the inject position of the `<script>` tag.
1523
- * @default 'head'
1524
- */
1525
- inject?: ChainedHtmlOption<ScriptInject>;
1526
- /**
1527
- * Inject custom html tags into the output html files.
1528
- * @default undefined
1529
- */
1530
- tags?: OneOrMany<HtmlTagDescriptor>;
1531
- /**
1532
- * Set the favicon icon for all pages.
1533
- * @default undefined
1534
- */
1535
- favicon?: ChainedHtmlOption<string>;
1536
- /**
1537
- * Set the web application icons to display when added to the home screen of a mobile device.
1538
- *
1539
- * @default undefined
1540
- * @example
1541
- * appIcon: {
1542
- * name: 'My Website',
1543
- * icons: [
1544
- * { src: './icon-192.png', size: 192 },
1545
- * { src: './icon-512.png', size: 512 },
1546
- * ]
1547
- * }
1548
- */
1549
- appIcon?: AppIcon;
1550
- /**
1551
- * Set the id of root element.
1552
- * @default 'root'
1553
- */
1554
- mountId?: string;
1555
- /**
1556
- * Set the [crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) attribute
1557
- * of the `<script>` tag.
1558
- * @default false
1559
- */
1560
- crossorigin?: boolean | CrossOrigin;
1561
- /**
1562
- * Define the directory structure of the HTML output files.
1563
- * @default 'flat'
1564
- */
1565
- outputStructure?: OutputStructure;
1566
- /**
1567
- * Define the path to the HTML template,
1568
- * corresponding to the `template` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1569
- * @default A built-in HTML template
1570
- */
1571
- template?: ChainedHtmlOption<string>;
1572
- /**
1573
- * Define the parameters in the HTML template,
1574
- * corresponding to the `templateParameters` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1575
- */
1576
- templateParameters?: ConfigChainAsyncWithContext<Record<string, unknown>, {
1310
+ * Configure the `<meta>` tag of the HTML.
1311
+ *
1312
+ * @default
1313
+ * ```js
1314
+ * const defaultMeta = {
1315
+ * charset: { charset: 'utf-8' },
1316
+ * viewport: 'width=device-width, initial-scale=1.0',
1317
+ * };
1318
+ * ```
1319
+ */ meta?: ChainedHtmlOption<MetaOptions>;
1320
+ /**
1321
+ * Set the title tag of the HTML page.
1322
+ * @default 'Rsbuild App'
1323
+ */ title?: ChainedHtmlOption<string>;
1324
+ /**
1325
+ * Set the inject position of the `<script>` tag.
1326
+ * @default 'head'
1327
+ */ inject?: ChainedHtmlOption<ScriptInject>;
1328
+ /**
1329
+ * Inject custom html tags into the output html files.
1330
+ * @default undefined
1331
+ */ tags?: OneOrMany<HtmlTagDescriptor>;
1332
+ /**
1333
+ * Set the favicon icon for all pages.
1334
+ * @default undefined
1335
+ */ favicon?: ChainedHtmlOption<string>;
1336
+ /**
1337
+ * Set the web application icons to display when added to the home screen of a mobile device.
1338
+ *
1339
+ * @default undefined
1340
+ * @example
1341
+ * appIcon: {
1342
+ * name: 'My Website',
1343
+ * icons: [
1344
+ * { src: './icon-192.png', size: 192 },
1345
+ * { src: './icon-512.png', size: 512 },
1346
+ * ]
1347
+ * }
1348
+ */ appIcon?: AppIcon;
1349
+ /**
1350
+ * Set the id of root element.
1351
+ * @default 'root'
1352
+ */ mountId?: string;
1353
+ /**
1354
+ * Set the [crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) attribute
1355
+ * of the `<script>` tag.
1356
+ * @default false
1357
+ */ crossorigin?: boolean | CrossOrigin;
1358
+ /**
1359
+ * Define the directory structure of the HTML output files.
1360
+ * @default 'flat'
1361
+ */ outputStructure?: OutputStructure;
1362
+ /**
1363
+ * Define the path to the HTML template,
1364
+ * corresponding to the `template` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1365
+ * @default A built-in HTML template
1366
+ */ template?: ChainedHtmlOption<string>;
1367
+ /**
1368
+ * Define the parameters in the HTML template,
1369
+ * corresponding to the `templateParameters` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1370
+ */ templateParameters?: ConfigChainAsyncWithContext<Record<string, unknown>, {
1577
1371
  entryName: string;
1578
1372
  }>;
1579
1373
  /**
1580
- * Specifies how `<script>` tags generated by Rsbuild are loaded.
1581
- * - `'defer'`: Adds the `defer` attribute so scripts load in parallel and run after
1582
- * the document has been parsed.
1583
- * - `'module'`: Adds `type="module"` to enable ES modules semantics.
1584
- * - `'blocking'`: No `defer` or `async`, scripts execute immediately in order.
1585
- * @default 'defer'. If `output.module` is enabled, the value is always `'module'`.
1586
- */
1587
- scriptLoading?: ScriptLoading;
1588
- /**
1589
- * Specifies which implementation to use for generating HTML files.
1590
- *
1591
- * - `'js'` (default) - Use the JavaScript-based `html-rspack-plugin`.
1592
- * - `'native'` - Use Rspack's built-in `HtmlRspackPlugin` implemented in Rust.
1593
- *
1594
- * This option is experimental and may affect the available options in `tools.htmlPlugin`,
1595
- * since the two implementations are not fully compatible.
1596
- *
1597
- * @default 'js'
1598
- * @experimental
1599
- */
1600
- implementation?: HtmlImplementation;
1374
+ * Specifies how `<script>` tags generated by Rsbuild are loaded.
1375
+ * - `'defer'`: Adds the `defer` attribute so scripts load in parallel and run after
1376
+ * the document has been parsed.
1377
+ * - `'module'`: Adds `type="module"` to enable ES modules semantics.
1378
+ * - `'blocking'`: No `defer` or `async`, scripts execute immediately in order.
1379
+ * @default 'defer'. If `output.module` is enabled, the value is always `'module'`.
1380
+ */ scriptLoading?: ScriptLoading;
1381
+ /**
1382
+ * Specifies which implementation to use for generating HTML files.
1383
+ *
1384
+ * - `'js'` (default) - Use the JavaScript-based `html-rspack-plugin`.
1385
+ * - `'native'` - Use Rspack's built-in `HtmlRspackPlugin` implemented in Rust.
1386
+ *
1387
+ * This option is experimental and may affect the available options in `tools.htmlPlugin`,
1388
+ * since the two implementations are not fully compatible.
1389
+ *
1390
+ * @default 'js'
1391
+ * @experimental
1392
+ */ implementation?: HtmlImplementation;
1601
1393
  }
1602
1394
  export type NormalizedHtmlConfig = HtmlConfig & {
1603
1395
  meta: ChainedHtmlOption<MetaOptions>;
@@ -1616,29 +1408,24 @@ export type RequestHandler = Connect.NextHandleFunction;
1616
1408
  export type EnvironmentAPI = Record<string, {
1617
1409
  /**
1618
1410
  * Get stats info about current environment.
1619
- */
1620
- getStats: () => Promise<Rspack.Stats>;
1411
+ */ getStats: () => Promise<Rspack.Stats>;
1621
1412
  /**
1622
1413
  * Load and execute stats bundle in Server.
1623
1414
  *
1624
1415
  * @param entryName - relate to rsbuild source.entry
1625
1416
  * @returns the return of entry module.
1626
- */
1627
- loadBundle: <T = unknown>(entryName: string) => Promise<T>;
1417
+ */ loadBundle: <T = unknown>(entryName: string) => Promise<T>;
1628
1418
  /**
1629
1419
  * Get the compiled HTML template.
1630
- */
1631
- getTransformedHtml: (entryName: string) => Promise<string>;
1420
+ */ getTransformedHtml: (entryName: string) => Promise<string>;
1632
1421
  /**
1633
1422
  * Send HMR message to the current environment only.
1634
- */
1635
- hot: {
1423
+ */ hot: {
1636
1424
  send: HotSend;
1637
1425
  };
1638
1426
  /**
1639
1427
  * Provides some context information about the current environment
1640
- */
1641
- context: EnvironmentContext;
1428
+ */ context: EnvironmentContext;
1642
1429
  }>;
1643
1430
  export type SetupMiddlewaresContext = Pick<RsbuildDevServer, 'sockWrite' | 'environments'>;
1644
1431
  export type SetupMiddlewaresFn = (middlewares: {
@@ -1647,106 +1434,89 @@ export type SetupMiddlewaresFn = (middlewares: {
1647
1434
  }, server: SetupMiddlewaresContext) => void;
1648
1435
  export type OverlayOptions = {
1649
1436
  /**
1650
- * Whether to show build errors in the overlay. You can pass a filter
1651
- * function to control which formatted build errors are rendered.
1652
- * Return false from the filter function to hide a specific error.
1653
- * @default true
1654
- */
1655
- errors?: boolean | ((error: Error) => boolean);
1656
- /**
1657
- * Whether to show runtime errors in the overlay. You can pass a filter
1658
- * function to control which runtime errors are rendered.
1659
- * Return false from the filter function to hide a specific error.
1660
- * @default false
1661
- */
1662
- runtime?: boolean | ((error: Error) => boolean);
1437
+ * Whether to show build errors in the overlay. You can pass a filter
1438
+ * function to control which formatted build errors are rendered.
1439
+ * Return false from the filter function to hide a specific error.
1440
+ * @default true
1441
+ */ errors?: boolean | ((error: Error) => boolean);
1442
+ /**
1443
+ * Whether to show runtime errors in the overlay. You can pass a filter
1444
+ * function to control which runtime errors are rendered.
1445
+ * Return false from the filter function to hide a specific error.
1446
+ * @default false
1447
+ */ runtime?: boolean | ((error: Error) => boolean);
1663
1448
  };
1664
1449
  export type ClientConfig = {
1665
1450
  /**
1666
- * The path for the WebSocket request.
1667
- * @default '/rsbuild-hmr'
1668
- */
1669
- path?: string;
1670
- /**
1671
- * The port number for the WebSocket request.
1672
- * @default location.port
1673
- */
1674
- port?: string | number;
1675
- /**
1676
- * The host for the WebSocket request.
1677
- * @default location.hostname
1678
- */
1679
- host?: string;
1680
- /**
1681
- * The protocol name for the WebSocket request.
1682
- * @default location.protocol === 'https:' ? 'wss' : 'ws'
1683
- */
1684
- protocol?: 'ws' | 'wss';
1685
- /**
1686
- * The maximum number of reconnection attempts after a WebSocket request is disconnected.
1687
- * @default 100
1688
- */
1689
- reconnect?: number;
1690
- /**
1691
- * Whether to display an error overlay in the browser.
1692
- * @default true
1693
- */
1694
- overlay?: boolean | OverlayOptions;
1695
- /**
1696
- * Controls the log level for client-side logging in the browser console.
1697
- * @default 'info'
1698
- */
1699
- logLevel?: 'info' | 'warn' | 'error' | 'silent';
1451
+ * The path for the WebSocket request.
1452
+ * @default '/rsbuild-hmr'
1453
+ */ path?: string;
1454
+ /**
1455
+ * The port number for the WebSocket request.
1456
+ * @default location.port
1457
+ */ port?: string | number;
1458
+ /**
1459
+ * The host for the WebSocket request.
1460
+ * @default location.hostname
1461
+ */ host?: string;
1462
+ /**
1463
+ * The protocol name for the WebSocket request.
1464
+ * @default location.protocol === 'https:' ? 'wss' : 'ws'
1465
+ */ protocol?: 'ws' | 'wss';
1466
+ /**
1467
+ * The maximum number of reconnection attempts after a WebSocket request is disconnected.
1468
+ * @default 100
1469
+ */ reconnect?: number;
1470
+ /**
1471
+ * Whether to display an error overlay in the browser.
1472
+ * @default true
1473
+ */ overlay?: boolean | OverlayOptions;
1474
+ /**
1475
+ * Controls the log level for client-side logging in the browser console.
1476
+ * @default 'info'
1477
+ */ logLevel?: 'info' | 'warn' | 'error' | 'silent';
1700
1478
  };
1701
1479
  export type NormalizedClientConfig = Optional<Required<ClientConfig>, 'protocol'>;
1702
1480
  export type { ChokidarOptions };
1703
1481
  export type WatchFiles = {
1704
1482
  /**
1705
- * Paths of the files or directories to watch, supports glob syntax.
1706
- */
1707
- paths: string | string[];
1483
+ * Paths of the files or directories to watch, supports glob syntax.
1484
+ */ paths: string | string[];
1708
1485
  /**
1709
- * Watch options passed to [chokidar](https://github.com/paulmillr/chokidar).
1710
- */
1711
- options?: ChokidarOptions;
1486
+ * Watch options passed to [chokidar](https://github.com/paulmillr/chokidar).
1487
+ */ options?: ChokidarOptions;
1712
1488
  /**
1713
- * Specifies whether to reload the page or restart the dev server when files change.
1714
- * @default 'reload-page'
1715
- */
1716
- type?: 'reload-page' | 'reload-server';
1489
+ * Specifies whether to reload the page or restart the dev server when files change.
1490
+ * @default 'reload-page'
1491
+ */ type?: 'reload-page' | 'reload-server';
1717
1492
  };
1718
1493
  export type CliShortcut = {
1719
1494
  /**
1720
- * The key to trigger the shortcut.
1721
- */
1722
- key: string;
1495
+ * The key to trigger the shortcut.
1496
+ */ key: string;
1723
1497
  /**
1724
- * The description of the shortcut.
1725
- */
1726
- description: string;
1498
+ * The description of the shortcut.
1499
+ */ description: string;
1727
1500
  /**
1728
- * The action to execute when the shortcut is triggered.
1729
- */
1730
- action: () => void | Promise<void>;
1501
+ * The action to execute when the shortcut is triggered.
1502
+ */ action: () => void | Promise<void>;
1731
1503
  };
1732
1504
  export type WriteToDisk = boolean | ((filename: string) => boolean);
1733
1505
  export type BrowserLogsStackTrace = 'summary' | 'full' | 'none';
1734
1506
  export type LiveReload = boolean | {
1735
1507
  /**
1736
- * Whether to trigger a full page reload when the HTML template changes.
1737
- * @default true
1738
- */
1739
- html?: boolean;
1508
+ * Whether to trigger a full page reload when the HTML template changes.
1509
+ * @default true
1510
+ */ html?: boolean;
1740
1511
  };
1741
1512
  export interface DevConfig {
1742
1513
  /**
1743
- * Controls whether to forward browser runtime errors to the terminal. When `true`, the dev
1744
- * client listens for `window.error` events and unhandled Promise rejections in the browser,
1745
- * then sends them to the dev server where they are printed in the terminal (prefixed with
1746
- * `[browser]`).
1747
- * @default { stackTrace: 'summary' }
1748
- */
1749
- browserLogs?: boolean | {
1514
+ * Controls whether to forward browser runtime errors to the terminal. When `true`, the dev
1515
+ * client listens for `window.error` events and unhandled Promise rejections in the browser,
1516
+ * then sends them to the dev server where they are printed in the terminal (prefixed with
1517
+ * `[browser]`).
1518
+ * @default { stackTrace: 'summary' }
1519
+ */ browserLogs?: boolean | {
1750
1520
  /**
1751
1521
  * Controls how the error stack trace is displayed in the terminal when forwarding
1752
1522
  * browser errors.
@@ -1754,77 +1524,64 @@ export interface DevConfig {
1754
1524
  * - `'full'` – Print the full stack trace with all frames.
1755
1525
  * - `'none'` – Hide stack traces.
1756
1526
  * @default 'summary'
1757
- */
1758
- stackTrace?: BrowserLogsStackTrace;
1527
+ */ stackTrace?: BrowserLogsStackTrace;
1759
1528
  };
1760
1529
  /**
1761
- * Whether to enable Hot Module Replacement.
1762
- * @default true
1763
- */
1764
- hmr?: boolean;
1765
- /**
1766
- * Whether to reload the page when file changes are detected.
1767
- * @default true
1768
- */
1769
- liveReload?: LiveReload;
1770
- /**
1771
- * Set the URL prefix of static assets in development mode,
1772
- * similar to the [output.publicPath](https://rspack.rs/config/output#outputpublicpath)
1773
- * config of Rspack.
1774
- * @default `server.base`
1775
- */
1776
- assetPrefix?: LiteralUnion<'auto', string> | boolean;
1777
- /**
1778
- * Whether to render progress bars to display the build progress.
1779
- * @default false
1780
- */
1781
- progressBar?: boolean | ProgressBarConfig;
1782
- /**
1783
- * Config for Rsbuild client code.
1784
- */
1785
- client?: ClientConfig;
1786
- /**
1787
- * Whether to enable CLI shortcuts.
1788
- * @default true when using Rsbuild CLI, otherwise false
1789
- */
1790
- cliShortcuts?: boolean | {
1530
+ * Whether to enable Hot Module Replacement.
1531
+ * @default true
1532
+ */ hmr?: boolean;
1533
+ /**
1534
+ * Whether to reload the page when file changes are detected.
1535
+ * @default true
1536
+ */ liveReload?: LiveReload;
1537
+ /**
1538
+ * Set the URL prefix of static assets in development mode,
1539
+ * similar to the [output.publicPath](https://rspack.rs/config/output#outputpublicpath)
1540
+ * config of Rspack.
1541
+ * @default `server.base`
1542
+ */ assetPrefix?: LiteralUnion<'auto', string> | boolean;
1543
+ /**
1544
+ * Whether to render progress bars to display the build progress.
1545
+ * @default false
1546
+ */ progressBar?: boolean | ProgressBarConfig;
1547
+ /**
1548
+ * Config for Rsbuild client code.
1549
+ */ client?: ClientConfig;
1550
+ /**
1551
+ * Whether to enable CLI shortcuts.
1552
+ * @default true when using Rsbuild CLI, otherwise false
1553
+ */ cliShortcuts?: boolean | {
1791
1554
  /**
1792
1555
  * Customize the CLI shortcuts.
1793
1556
  * @param shortcuts - The default CLI shortcuts.
1794
1557
  * @returns - The customized CLI shortcuts.
1795
- */
1796
- custom?: (shortcuts: CliShortcut[]) => CliShortcut[];
1558
+ */ custom?: (shortcuts: CliShortcut[]) => CliShortcut[];
1797
1559
  /**
1798
1560
  * Whether to print the help hint when the server is started.
1799
1561
  * - `true`: Print the default help hint.
1800
1562
  * - `false`: Disable the help hint.
1801
1563
  * - `string`: Print a custom help hint.
1802
1564
  * @default true
1803
- */
1804
- help?: boolean | string;
1565
+ */ help?: boolean | string;
1805
1566
  };
1806
1567
  /**
1807
- * Used to add custom middleware to the dev server.
1808
- * @deprecated Use `server.setup` instead
1809
- * @default undefined
1810
- */
1811
- setupMiddlewares?: SetupMiddlewaresFn | SetupMiddlewaresFn[];
1812
- /**
1813
- * Controls whether the build output from development mode is written to disk.
1814
- * @default false
1815
- */
1816
- writeToDisk?: WriteToDisk;
1817
- /**
1818
- * Watch specified files and directories for changes. When a file change is detected,
1819
- * it can trigger a page reload or restart the dev server.
1820
- * @default undefined
1821
- */
1822
- watchFiles?: WatchFiles | WatchFiles[];
1823
- /**
1824
- * Enable lazy compilation (compilation on demand).
1825
- * @default { imports: true, entries: false }
1826
- */
1827
- lazyCompilation?: boolean | Rspack.LazyCompilationOptions;
1568
+ * Used to add custom middleware to the dev server.
1569
+ * @deprecated Use `server.setup` instead
1570
+ * @default undefined
1571
+ */ setupMiddlewares?: SetupMiddlewaresFn | SetupMiddlewaresFn[];
1572
+ /**
1573
+ * Controls whether the build output from development mode is written to disk.
1574
+ * @default false
1575
+ */ writeToDisk?: WriteToDisk;
1576
+ /**
1577
+ * Watch specified files and directories for changes. When a file change is detected,
1578
+ * it can trigger a page reload or restart the dev server.
1579
+ * @default undefined
1580
+ */ watchFiles?: WatchFiles | WatchFiles[];
1581
+ /**
1582
+ * Enable lazy compilation (compilation on demand).
1583
+ * @default { imports: true, entries: false }
1584
+ */ lazyCompilation?: boolean | Rspack.LazyCompilationOptions;
1828
1585
  }
1829
1586
  export type NormalizedDevConfig = Omit<DevConfig, 'watchFiles'> & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk' | 'cliShortcuts' | 'browserLogs'>> & {
1830
1587
  watchFiles: WatchFiles[];
@@ -1832,48 +1589,42 @@ export type NormalizedDevConfig = Omit<DevConfig, 'watchFiles'> & Required<Pick<
1832
1589
  };
1833
1590
  export interface ResolveConfig {
1834
1591
  /**
1835
- * Force Rsbuild to resolve the specified packages from project root,
1836
- * which is useful for deduplicating packages and reducing the bundle size.
1837
- */
1838
- dedupe?: string[];
1839
- /**
1840
- * Set the alias for the module path, which is used to simplify the import path or
1841
- * redirect the module reference.
1842
- * Similar to the [resolve.alias](https://rspack.rs/config/resolve) config of Rspack.
1843
- * @default { '@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')) }
1844
- */
1845
- alias?: ConfigChain<Alias>;
1846
- /**
1847
- * Set the strategy for path alias resolution, to control the priority relationship
1848
- * between the `paths` option in `tsconfig.json` and the `resolve.alias` option of Rsbuild.
1849
- * - `prefer-tsconfig`: The `paths` option in `tsconfig.json` will take precedence over the
1850
- * `resolve.alias` option of Rsbuild.
1851
- * - `prefer-alias`: The `resolve.alias` option of Rsbuild will take precedence over the
1852
- * `paths` option in `tsconfig.json`.
1853
- * @default 'prefer-tsconfig'
1854
- */
1855
- aliasStrategy?: AliasStrategy;
1856
- /**
1857
- * Automatically resolve file extensions when importing modules.
1858
- * This means you can import files without explicitly writing their extensions.
1859
- * @default ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json']
1860
- */
1861
- extensions?: string[];
1862
- /**
1863
- * Specifies the condition names used to match entry points in the exports field
1864
- * of a package.
1865
- * @default Inherits from Rspack. See https://rspack.rs/config/resolve#resolveconditionnames
1866
- */
1867
- conditionNames?: string[];
1868
- /**
1869
- * Controls the priority of fields in a package.json used to locate a package's
1870
- * entry file. It is the ordered list of package.json fields Rspack will try
1871
- * when resolving an npm package's entry point.
1872
- * @default
1873
- * - If `output.target` is `'web'`, `'web-worker'`, or not specified, the default value is `["browser", "module", "main"]`.
1874
- * - If `output.target` is `'node'`, the default value is `["module", "main"]`.
1875
- */
1876
- mainFields?: string[];
1592
+ * Force Rsbuild to resolve the specified packages from project root,
1593
+ * which is useful for deduplicating packages and reducing the bundle size.
1594
+ */ dedupe?: string[];
1595
+ /**
1596
+ * Set the alias for the module path, which is used to simplify the import path or
1597
+ * redirect the module reference.
1598
+ * Similar to the [resolve.alias](https://rspack.rs/config/resolve) config of Rspack.
1599
+ * @default { '@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')) }
1600
+ */ alias?: ConfigChain<Alias>;
1601
+ /**
1602
+ * Set the strategy for path alias resolution, to control the priority relationship
1603
+ * between the `paths` option in `tsconfig.json` and the `resolve.alias` option of Rsbuild.
1604
+ * - `prefer-tsconfig`: The `paths` option in `tsconfig.json` will take precedence over the
1605
+ * `resolve.alias` option of Rsbuild.
1606
+ * - `prefer-alias`: The `resolve.alias` option of Rsbuild will take precedence over the
1607
+ * `paths` option in `tsconfig.json`.
1608
+ * @default 'prefer-tsconfig'
1609
+ */ aliasStrategy?: AliasStrategy;
1610
+ /**
1611
+ * Automatically resolve file extensions when importing modules.
1612
+ * This means you can import files without explicitly writing their extensions.
1613
+ * @default ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json']
1614
+ */ extensions?: string[];
1615
+ /**
1616
+ * Specifies the condition names used to match entry points in the exports field
1617
+ * of a package.
1618
+ * @default Inherits from Rspack. See https://rspack.rs/config/resolve#resolveconditionnames
1619
+ */ conditionNames?: string[];
1620
+ /**
1621
+ * Controls the priority of fields in a package.json used to locate a package's
1622
+ * entry file. It is the ordered list of package.json fields Rspack will try
1623
+ * when resolving an npm package's entry point.
1624
+ * @default
1625
+ * - If `output.target` is `'web'`, `'web-worker'`, or not specified, the default value is `["browser", "module", "main"]`.
1626
+ * - If `output.target` is `'node'`, the default value is `["module", "main"]`.
1627
+ */ mainFields?: string[];
1877
1628
  }
1878
1629
  export type NormalizedResolveConfig = ResolveConfig & Pick<Required<ResolveConfig>, 'alias' | 'aliasStrategy' | 'extensions'>;
1879
1630
  export type ModuleFederationConfig = {
@@ -1882,115 +1633,92 @@ export type ModuleFederationConfig = {
1882
1633
  export type NormalizedModuleFederationConfig = ModuleFederationConfig;
1883
1634
  export type RsbuildConfigMeta = {
1884
1635
  /**
1885
- * Path to the rsbuild config file.
1886
- */
1887
- configFilePath: string;
1636
+ * Path to the rsbuild config file.
1637
+ */ configFilePath: string;
1888
1638
  };
1889
1639
  /**
1890
1640
  * Only some dev options can be defined in the environment config
1891
- */
1892
- export type AllowedEnvironmentDevKeys = 'hmr' | 'client' | 'liveReload' | 'browserLogs' | 'assetPrefix' | 'progressBar' | 'lazyCompilation' | 'writeToDisk';
1641
+ */ export type AllowedEnvironmentDevKeys = 'hmr' | 'client' | 'liveReload' | 'browserLogs' | 'assetPrefix' | 'progressBar' | 'lazyCompilation' | 'writeToDisk';
1893
1642
  /**
1894
1643
  * The Rsbuild config to run in the specified environment.
1895
- */
1896
- export interface EnvironmentConfig {
1644
+ */ export interface EnvironmentConfig {
1897
1645
  /**
1898
- * Options for local development.
1899
- */
1900
- dev?: Pick<DevConfig, AllowedEnvironmentDevKeys>;
1646
+ * Options for local development.
1647
+ */ dev?: Pick<DevConfig, AllowedEnvironmentDevKeys>;
1901
1648
  /**
1902
- * Options for HTML generation.
1903
- */
1904
- html?: HtmlConfig;
1649
+ * Options for HTML generation.
1650
+ */ html?: HtmlConfig;
1905
1651
  /**
1906
- * Options for the low-level tools.
1907
- */
1908
- tools?: ToolsConfig;
1652
+ * Options for the low-level tools.
1653
+ */ tools?: ToolsConfig;
1909
1654
  /**
1910
- * Options for module resolution.
1911
- */
1912
- resolve?: ResolveConfig;
1655
+ * Options for module resolution.
1656
+ */ resolve?: ResolveConfig;
1913
1657
  /**
1914
- * Options for input source code.
1915
- */
1916
- source?: SourceConfig;
1658
+ * Options for input source code.
1659
+ */ source?: SourceConfig;
1917
1660
  /**
1918
- * Options for build outputs.
1919
- */
1920
- output?: OutputConfig;
1661
+ * Options for build outputs.
1662
+ */ output?: OutputConfig;
1921
1663
  /**
1922
- * Options for Web security.
1923
- */
1924
- security?: SecurityConfig;
1664
+ * Options for Web security.
1665
+ */ security?: SecurityConfig;
1925
1666
  /**
1926
- * Options for build performance and runtime performance.
1927
- */
1928
- performance?: PerformanceConfig;
1667
+ * Options for build performance and runtime performance.
1668
+ */ performance?: PerformanceConfig;
1929
1669
  /**
1930
- * Options for chunk splitting.
1931
- */
1932
- splitChunks?: SplitChunksConfig | false;
1670
+ * Options for chunk splitting.
1671
+ */ splitChunks?: SplitChunksConfig | false;
1933
1672
  /**
1934
- * Options for module federation.
1935
- */
1936
- moduleFederation?: ModuleFederationConfig;
1673
+ * Options for module federation.
1674
+ */ moduleFederation?: ModuleFederationConfig;
1937
1675
  /**
1938
- * Configure Rsbuild plugins.
1939
- */
1940
- plugins?: RsbuildPlugins;
1676
+ * Configure Rsbuild plugins.
1677
+ */ plugins?: RsbuildPlugins;
1941
1678
  }
1942
1679
  export type LogLevel = 'info' | 'warn' | 'error' | 'silent';
1943
1680
  /**
1944
1681
  * The Rsbuild config.
1945
- */
1946
- export interface RsbuildConfig extends EnvironmentConfig {
1947
- /**
1948
- * Specify the build mode for Rsbuild, as each mode has different default behavior and optimizations.
1949
- * @default Depends on `process.env.NODE_ENV`:
1950
- * - `'production'` if NODE_ENV is 'production'
1951
- * - `'development'` if NODE_ENV is 'development'
1952
- * - otherwise `'none'`
1953
- */
1954
- mode?: RsbuildMode;
1955
- /**
1956
- * Specify the project root directory. Can be an absolute path, or a path relative to `process.cwd()`.
1957
- * @default `process.cwd()`
1958
- */
1959
- root?: string;
1960
- /**
1961
- * Specify the log level of Rsbuild.
1962
- * - 'info': Output all logs.
1963
- * - 'warn': Output `warn` and `error` level logs.
1964
- * - 'error': Output `error` level logs.
1965
- * - 'silent': Do not output any logs.
1966
- * @default 'info'
1967
- */
1968
- logLevel?: LogLevel;
1969
- /**
1970
- * Use a custom logger instance for the current Rsbuild instance.
1971
- * You can create one via `createLogger()`.
1972
- */
1973
- customLogger?: Logger;
1974
- /**
1975
- * Options for local development.
1976
- */
1977
- dev?: DevConfig;
1978
- /**
1979
- * Options for the Rsbuild server.
1980
- * Mainly applies to local development and preview.
1981
- * Some options (e.g. `publicDir`, `base`) also affect production builds.
1982
- */
1983
- server?: ServerConfig;
1984
- /**
1985
- * Configure Rsbuild config by environment.
1986
- * The key represents the environment name.
1987
- * The value is the Rsbuild config for the specified environment.
1988
- */
1989
- environments?: Record<string, EnvironmentConfig>;
1990
- /**
1991
- * @private
1992
- */
1993
- _privateMeta?: RsbuildConfigMeta;
1682
+ */ export interface RsbuildConfig extends EnvironmentConfig {
1683
+ /**
1684
+ * Specify the build mode for Rsbuild, as each mode has different default behavior and optimizations.
1685
+ * @default Depends on `process.env.NODE_ENV`:
1686
+ * - `'production'` if NODE_ENV is 'production'
1687
+ * - `'development'` if NODE_ENV is 'development'
1688
+ * - otherwise `'none'`
1689
+ */ mode?: RsbuildMode;
1690
+ /**
1691
+ * Specify the project root directory. Can be an absolute path, or a path relative to `process.cwd()`.
1692
+ * @default `process.cwd()`
1693
+ */ root?: string;
1694
+ /**
1695
+ * Specify the log level of Rsbuild.
1696
+ * - 'info': Output all logs.
1697
+ * - 'warn': Output `warn` and `error` level logs.
1698
+ * - 'error': Output `error` level logs.
1699
+ * - 'silent': Do not output any logs.
1700
+ * @default 'info'
1701
+ */ logLevel?: LogLevel;
1702
+ /**
1703
+ * Use a custom logger instance for the current Rsbuild instance.
1704
+ * You can create one via `createLogger()`.
1705
+ */ customLogger?: Logger;
1706
+ /**
1707
+ * Options for local development.
1708
+ */ dev?: DevConfig;
1709
+ /**
1710
+ * Options for the Rsbuild server.
1711
+ * Mainly applies to local development and preview.
1712
+ * Some options (e.g. `publicDir`, `base`) also affect production builds.
1713
+ */ server?: ServerConfig;
1714
+ /**
1715
+ * Configure Rsbuild config by environment.
1716
+ * The key represents the environment name.
1717
+ * The value is the Rsbuild config for the specified environment.
1718
+ */ environments?: Record<string, EnvironmentConfig>;
1719
+ /**
1720
+ * @private
1721
+ */ _privateMeta?: RsbuildConfigMeta;
1994
1722
  }
1995
1723
  export type MergedEnvironmentConfig = {
1996
1724
  mode: RsbuildMode;
@@ -2011,8 +1739,7 @@ export type MergedEnvironmentConfig = {
2011
1739
  };
2012
1740
  /**
2013
1741
  * The normalized Rsbuild environment config.
2014
- */
2015
- export type NormalizedEnvironmentConfig = TwoLevelReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
1742
+ */ export type NormalizedEnvironmentConfig = TwoLevelReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
2016
1743
  dev: NormalizedDevConfig;
2017
1744
  server: NormalizedServerConfig;
2018
1745
  _privateMeta?: RsbuildConfigMeta;