@rsbuild/core 2.0.7 → 2.0.9

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 (91) hide show
  1. package/compiled/css-loader/index.js +2 -2
  2. package/compiled/html-rspack-plugin/index.js +14 -14
  3. package/compiled/postcss/index.js +1 -1
  4. package/compiled/postcss/package.json +1 -1
  5. package/compiled/postcss-loader/index.js +6 -6
  6. package/dist/1~rslib-runtime.js +8 -5
  7. package/dist/{753.js → 756.js} +157 -128
  8. package/dist/client/hmr.js +1 -1
  9. package/dist/client/overlay.js +1 -1
  10. package/dist/http-proxy-middleware.js +2 -5
  11. package/dist/index.js +1 -1
  12. package/dist/launch-editor-middleware.js +1 -1
  13. package/dist/manifest-plugin.js +7 -7
  14. package/dist/memfs.js +5 -5
  15. package/dist/ws.js +45 -31
  16. package/dist-types/build.d.ts +1 -1
  17. package/dist-types/cli/init.d.ts +1 -1
  18. package/dist-types/configChain.d.ts +59 -118
  19. package/dist-types/constants.d.ts +35 -31
  20. package/dist-types/createContext.d.ts +1 -2
  21. package/dist-types/createRsbuild.d.ts +1 -2
  22. package/dist-types/defaultConfig.d.ts +2 -4
  23. package/dist-types/helpers/exitHook.d.ts +1 -1
  24. package/dist-types/helpers/format.d.ts +2 -1
  25. package/dist-types/helpers/fs.d.ts +2 -4
  26. package/dist-types/helpers/index.d.ts +1 -2
  27. package/dist-types/helpers/packageJson.d.ts +1 -1
  28. package/dist-types/helpers/path.d.ts +4 -8
  29. package/dist-types/helpers/stats.d.ts +3 -5
  30. package/dist-types/helpers/url.d.ts +1 -0
  31. package/dist-types/helpers/vendors.d.ts +2 -3
  32. package/dist-types/helpers/version.d.ts +2 -3
  33. package/dist-types/hooks.d.ts +6 -8
  34. package/dist-types/index.d.ts +10 -5
  35. package/dist-types/initConfigs.d.ts +2 -3
  36. package/dist-types/initPlugins.d.ts +1 -1
  37. package/dist-types/inspectConfig.d.ts +1 -1
  38. package/dist-types/loadConfig.d.ts +24 -32
  39. package/dist-types/loadEnv.d.ts +48 -57
  40. package/dist-types/loader/transformRawLoader.d.ts +1 -0
  41. package/dist-types/logger.d.ts +1 -2
  42. package/dist-types/mergeConfig.d.ts +1 -2
  43. package/dist-types/pluginHelper.d.ts +1 -2
  44. package/dist-types/pluginManager.d.ts +4 -7
  45. package/dist-types/plugins/basic.d.ts +1 -2
  46. package/dist-types/plugins/css.d.ts +5 -1
  47. package/dist-types/plugins/externals.d.ts +1 -1
  48. package/dist-types/plugins/fileSize.d.ts +6 -5
  49. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  50. package/dist-types/plugins/server.d.ts +1 -0
  51. package/dist-types/plugins/swc.d.ts +1 -2
  52. package/dist-types/restart.d.ts +4 -5
  53. package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +2 -3
  54. package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +2 -3
  55. package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +3 -4
  56. package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +1 -2
  57. package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +2 -3
  58. package/dist-types/rspackConfig.d.ts +1 -1
  59. package/dist-types/server/ansiHTML.d.ts +1 -2
  60. package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +1 -2
  61. package/dist-types/server/assets-middleware/index.d.ts +3 -5
  62. package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +1 -2
  63. package/dist-types/server/browserLogs.d.ts +1 -2
  64. package/dist-types/server/buildManager.d.ts +4 -6
  65. package/dist-types/server/cliShortcuts.d.ts +3 -1
  66. package/dist-types/server/devMiddlewares.d.ts +2 -3
  67. package/dist-types/server/devServer.d.ts +18 -23
  68. package/dist-types/server/gracefulShutdown.d.ts +2 -4
  69. package/dist-types/server/gzipMiddleware.d.ts +1 -1
  70. package/dist-types/server/helper.d.ts +39 -47
  71. package/dist-types/server/historyApiFallback.d.ts +8 -1
  72. package/dist-types/server/httpServer.d.ts +1 -1
  73. package/dist-types/server/middlewares.d.ts +4 -8
  74. package/dist-types/server/open.d.ts +1 -1
  75. package/dist-types/server/runner/basic.d.ts +4 -5
  76. package/dist-types/server/runner/index.d.ts +3 -1
  77. package/dist-types/server/socketServer.d.ts +24 -18
  78. package/dist-types/server/watchFiles.d.ts +1 -1
  79. package/dist-types/types/config.d.ts +1197 -1457
  80. package/dist-types/types/context.d.ts +63 -92
  81. package/dist-types/types/hooks.d.ts +106 -150
  82. package/dist-types/types/plugin.d.ts +359 -444
  83. package/dist-types/types/rsbuild.d.ts +156 -191
  84. package/dist-types/types/thirdParty.d.ts +101 -132
  85. package/dist-types/types/utils.d.ts +2 -5
  86. package/package.json +10 -10
  87. package/dist-types/client/hmr.d.ts +0 -3
  88. package/dist-types/client/log.d.ts +0 -13
  89. package/dist-types/client/overlay.d.ts +0 -1
  90. /package/dist/{753.js.LICENSE.txt → 756.js.LICENSE.txt} +0 -0
  91. /package/dist/client/{797.js → 60.js} +0 -0
@@ -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, 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,12 +36,13 @@ 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
- addRules: (rules: RspackRule | RspackRule[]) => void;
43
- appendRules: (rules: RspackRule | RspackRule[]) => void;
44
- prependPlugins: (plugins: Rspack.RspackPluginInstance | Rspack.RspackPluginInstance[]) => void;
45
- appendPlugins: (plugins: Rspack.RspackPluginInstance | Rspack.RspackPluginInstance[]) => void;
42
+ addRules: (rules: OneOrMany<RspackRule>) => void;
43
+ appendRules: (rules: OneOrMany<RspackRule>) => void;
44
+ prependPlugins: (plugins: OneOrMany<Rspack.Plugin>) => void;
45
+ appendPlugins: (plugins: OneOrMany<Rspack.Plugin>) => void;
46
46
  removePlugin: (pluginName: string) => void;
47
47
  mergeConfig: RspackMerge;
48
48
  };
@@ -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: NonNullable<Rspack.Configuration['plugins']>;
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,273 +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;
958
+ export type AutoExternalExclude = OneOrMany<string | RegExp>;
1107
959
  export type AutoExternal = boolean | {
1108
960
  /**
1109
- * Whether to automatically externalize dependencies of type `dependencies`.
1110
- * @default true
1111
- */
1112
- dependencies?: boolean;
1113
- /**
1114
- * Whether to automatically externalize dependencies of type `optionalDependencies`.
1115
- * @default true
1116
- */
1117
- optionalDependencies?: boolean;
1118
- /**
1119
- * Whether to automatically externalize dependencies of type `peerDependencies`.
1120
- * @default true
1121
- */
1122
- peerDependencies?: boolean;
1123
- /**
1124
- * Whether to automatically externalize dependencies of type `devDependencies`.
1125
- * @default false
1126
- */
1127
- devDependencies?: boolean;
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;
1128
986
  };
1129
987
  export interface OutputConfig {
1130
988
  /**
1131
- * Setting the build target for Rsbuild.
1132
- * @default 'web'
1133
- */
1134
- target?: RsbuildTarget;
1135
- /**
1136
- * Use this option to specify which modules should not be bundled by Rsbuild, and instead
1137
- * use implementations provided by the external environment.
1138
- * For more information, please see: [Rspack Externals](https://rspack.rs/config/externals)
1139
- * @default undefined
1140
- */
1141
- externals?: Externals;
1142
- /**
1143
- * Automatically externalize dependencies declared in the root package.json.
1144
- * This option will generate `externals` rules for matching dependencies and their subpath imports.
1145
- * @default false
1146
- */
1147
- autoExternal?: AutoExternal;
1148
- /**
1149
- * Set the directory of the output files.
1150
- * Rsbuild will emit files to the specified subdirectory according to the file type.
1151
- * - `string`: Set the root output directory to a specific path, equivalent to `distPath.root`.
1152
- * - `object`: Set the output directory for each file type.
1153
- */
1154
- distPath?: string | DistPathConfig;
1155
- /**
1156
- * Sets the filename of output files.
1157
- */
1158
- filename?: FilenameConfig;
1159
- /**
1160
- * Specify the character encoding format for output files.
1161
- * Can be `ascii` or `utf8`.
1162
- * @default 'utf8'
1163
- */
1164
- charset?: Charset;
1165
- /**
1166
- * Configure how the polyfill is injected.
1167
- * @default 'off'
1168
- */
1169
- polyfill?: Polyfill;
1170
- /**
1171
- * When using CDN in the production,
1172
- * you can use this option to set the URL prefix of static assets,
1173
- * similar to the `output.publicPath` config of Rspack.
1174
- * `auto` means use a relative path based on file location.
1175
- * @default `server.base`
1176
- */
1177
- assetPrefix?: LiteralUnion<'auto', string>;
1178
- /**
1179
- * Set the size threshold to inline static assets such as images and fonts.
1180
- * By default, static assets will be Base64 encoded and inline into the page if
1181
- * the size is less than 4KiB.
1182
- * @default { svg: 4096, font: 4096, image: 4096, media: 4096, assets: 4096 }
1183
- */
1184
- dataUriLimit?: number | DataUriLimit;
1185
- /**
1186
- * Configure how to handle the legal comment.
1187
- * A "legal comment" is considered to be any statement-level comment in JS or rule-level
1188
- * comment in CSS that contains @license or @preserve or that starts with //! or /\*!.
1189
- * These comments are preserved in output files by default since that follows the intent
1190
- * of the original authors of the code.
1191
- * @default 'linked'
1192
- */
1193
- legalComments?: LegalComments;
1194
- /**
1195
- * Whether to clean up all files under the output directory before the build starts.
1196
- * @default 'auto'
1197
- */
1198
- cleanDistPath?: CleanDistPath;
1199
- /**
1200
- * Allow to custom CSS Modules options.
1201
- */
1202
- cssModules?: CSSModules;
1203
- /**
1204
- * Configure whether to enable code minification in production mode, or to configure
1205
- * minimizer options.
1206
- * @default true
1207
- */
1208
- minify?: Minify;
1209
- /**
1210
- * Configure how to generate the manifest file.
1211
- * - `true`: Generate a manifest file named `manifest.json` in the output directory.
1212
- * - `false`: Do not generate the manifest file.
1213
- * - `string`: Generate a manifest file with the specified filename or path.
1214
- * - `object`: Generate a manifest file with the specified options.
1215
- * @default false
1216
- */
1217
- manifest?: ManifestConfig;
1218
- /**
1219
- * Whether to output JavaScript files in ES modules format.
1220
- * @default true when `output.target` is `node`, otherwise `false`
1221
- */
1222
- module?: boolean;
1223
- /**
1224
- * Whether to generate source map files, and which format of source map to generate.
1225
- *
1226
- * @default
1227
- * ```js
1228
- * const defaultSourceMap = {
1229
- * js: isDev ? 'cheap-module-source-map' : false,
1230
- * css: false,
1231
- * extract: false,
1232
- * };
1233
- * ```
1234
- */
1235
- sourceMap?: boolean | SourceMap;
1236
- /**
1237
- * Whether to add filename hash.
1238
- * - `true`: JavaScript and CSS filenames include hash in production mode, while other assets
1239
- * always include hash in all modes.
1240
- * - `false`: Disable filename hash.
1241
- * - `string`: Enable filename hash and customize the hash format, such as `'contenthash:16'`.
1242
- * - `object`: An object to configure filename hash behavior.
1243
- * @default true
1244
- */
1245
- filenameHash?: FilenameHash;
1246
- /**
1247
- * Whether to inline output scripts files (.js files) into HTML with `<script>` tags.
1248
- * @default false
1249
- */
1250
- inlineScripts?: InlineChunkConfig;
1251
- /**
1252
- * Whether to inline output style files (.css files) into html with `<style>` tags.
1253
- * @default false
1254
- */
1255
- inlineStyles?: InlineChunkConfig;
1256
- /**
1257
- * Whether to inject styles into the DOM via `style-loader`.
1258
- * @default false
1259
- */
1260
- injectStyles?: boolean;
1261
- /**
1262
- * Specifies the range of target browsers that the project is compatible with.
1263
- * This value will be used by [SWC](https://github.com/swc-project/swc) and
1264
- * [Lightning CSS](https://github.com/parcel-bundler/lightningcss) to identify
1265
- * the JavaScript syntax that need to be transformed and the CSS browser prefixes
1266
- * that need to be added.
1267
- * @default undefined
1268
- */
1269
- overrideBrowserslist?: string[];
1270
- /**
1271
- * Copies the specified file or directory to the dist directory.
1272
- * @default undefined
1273
- */
1274
- copy?: CopyRspackPluginOptions | CopyRspackPluginOptions['patterns'];
1275
- /**
1276
- * Whether to emit static assets such as image, font, etc.
1277
- * Return `false` to avoid outputting unnecessary assets for some scenarios such as SSR.
1278
- * @default true
1279
- */
1280
- emitAssets?: boolean;
1281
- /**
1282
- * Whether to emit CSS to the output bundles.
1283
- * If `false`, the CSS will not be extracted to separate files or injected into the
1284
- * JavaScript bundles via `output.injectStyles`.
1285
- * @default `true` when `output.target` is `web`, otherwise `false`
1286
- */
1287
- 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;
1288
1122
  }
1289
1123
  export interface NormalizedOutputConfig extends OutputConfig {
1290
1124
  target: RsbuildTarget;
@@ -1328,8 +1162,7 @@ export type OutputStructure = 'flat' | 'nested';
1328
1162
  * name: 'viewport',
1329
1163
  * content: 'width=500, initial-scale=1',
1330
1164
  * }
1331
- */
1332
- export type MetaAttrs = Record<string, string | boolean>;
1165
+ */ export type MetaAttrs = Record<string, string | boolean>;
1333
1166
  /**
1334
1167
  * Meta options in name-content form.
1335
1168
  * Key is the meta name, such as `viewport`, `description`, or `robots`.
@@ -1344,88 +1177,79 @@ export type MetaAttrs = Record<string, string | boolean>;
1344
1177
  * description: 'My awesome website',
1345
1178
  * robots: false,
1346
1179
  * }
1347
- */
1348
- export type MetaOptions = Record<string, string | false | MetaAttrs>;
1180
+ */ export type MetaOptions = Record<string, string | false | MetaAttrs>;
1349
1181
  export type HtmlBasicTag = {
1350
1182
  /**
1351
- * The HTML tag name to be generated. Should be a valid HTML element name.
1352
- * @example
1353
- * - `'script'` for JavaScript files
1354
- * - `'link'` for stylesheets or external resources
1355
- * - `'meta'` for metadata
1356
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
1357
- */
1358
- tag: string;
1359
- /**
1360
- * HTML attributes to be applied to the tag.
1361
- * - `string` values will be rendered as `attribute="value"`
1362
- * - `true` renders as boolean attribute (e.g., `<input disabled>`)
1363
- * - `false` or `null` or `undefined` values will omit the attribute
1364
- *
1365
- * @example
1366
- * // String attributes
1367
- * attrs: {
1368
- * src: 'https://example.com/script.js',
1369
- * type: 'text/javascript',
1370
- * }
1371
- * // Result: <script src="https://example.com/script.js" type="text/javascript">
1372
-
1373
- * // Boolean attributes
1374
- * attrs: {
1375
- * async: true, // <script async>
1376
- * defer: false, // attribute omitted
1377
- * }
1378
- * // Result: <script async>
1379
- */
1380
- attrs?: Record<string, string | boolean | null | undefined>;
1381
- /**
1382
- * The innerHTML content of the tag. The content is inserted as-is without
1383
- * HTML escaping, so ensure it's safe to prevent XSS vulnerabilities.
1384
- */
1385
- children?: string;
1386
- /**
1387
- * The metadata object for tags, used to store additional information about tags.
1388
- * `metadata` does not affect the generated HTML content.
1389
- * @default undefined
1390
- */
1391
- 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>;
1392
1220
  };
1393
1221
  export type HtmlTag = HtmlBasicTag & {
1394
1222
  /**
1395
- * Controls whether to add a hash query parameter to asset URLs for cache invalidation.
1396
- * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1397
- * - `false`: No hash query
1398
- * - `true`: Generate hash based on HTML content
1399
- * - `string`: Uses a custom hash string
1400
- * - `function`: Custom hash generation via a function
1401
- * @default false
1402
- */
1403
- hash?: boolean | string | ((url: string, hash: string) => string);
1404
- /**
1405
- * Controls whether to prepend the asset prefix to resource URLs.
1406
- * Only affects the `src` attribute of the `script` tag and the `href` attribute of the `link` tag.
1407
- * - `true`: Prepends asset prefix to the URL
1408
- * - `false`: Uses the URL as-is
1409
- * - `string`: Uses a custom prefix
1410
- * - `function`: Custom path transformation via a function
1411
- * @default true
1412
- */
1413
- publicPath?: boolean | string | ((url: string, publicPath: string) => string);
1414
- /**
1415
- * Defines the injection position relative to existing tags.
1416
- * - `true`: Insert after existing tags
1417
- * - `false`: Insert before existing tags
1418
- * @default true
1419
- */
1420
- append?: boolean;
1421
- /**
1422
- * Specifies whether to inject the tag into the HTML `<head>` element.
1423
- * - `true`: Inject into `<head>`
1424
- * - `false`: Inject into `<body>`
1425
- * @default Auto-detect: `true` for head-allowed elements, `false` otherwise
1426
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head#see_also
1427
- */
1428
- 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;
1429
1253
  };
1430
1254
  export type HtmlTagContext = {
1431
1255
  hash: string;
@@ -1435,156 +1259,137 @@ export type HtmlTagContext = {
1435
1259
  };
1436
1260
  export type HtmlTagHandler = (tags: HtmlTag[], context: HtmlTagContext) => HtmlTag[] | void;
1437
1261
  export type HtmlTagDescriptor = HtmlTag | HtmlTagHandler;
1438
- type ChainedHtmlOption<O> = ConfigChainMergeContext<O, {
1262
+ type ChainedHtmlOption<O> = OneOrMany<O | ((context: {
1263
+ value: O;
1439
1264
  entryName: string;
1440
- }>;
1265
+ }) => MaybePromise<O | void>)>;
1441
1266
  export type AppIconItem = {
1442
1267
  /**
1443
- * The path to the icon, can be a URL, an absolute file path,
1444
- * or a relative path to the project root.
1445
- */
1446
- src: string;
1447
- /**
1448
- * The size of the icon.
1449
- */
1450
- size: number;
1451
- /**
1452
- * Specifies the intended target for which the icon should be generated.
1453
- * - `apple-touch-icon` for iOS system.
1454
- * - `web-app-manifest` for web application manifest.
1455
- */
1456
- target?: 'apple-touch-icon' | 'web-app-manifest';
1457
- /**
1458
- * A case-sensitive keyword string that specifies one or more contexts in
1459
- * which the icon can be used by the browser or operating system.
1460
- * This field is only effective when the `target` is `'web-app-manifest'`.
1461
- *
1462
- * The possible properties include:
1463
- * - `'monochrome'`: Indicates that the icon is intended to be used as a
1464
- * monochrome icon with a solid fill.
1465
- * - `'maskable'`: Indicates that the icon is designed with icon masks and
1466
- * safe zone in mind.
1467
- * - `'any'`: Indicates that the icon can be used in any context. This is
1468
- * the default value.
1469
- * @see https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/icons#purpose
1470
- */
1471
- 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>;
1472
1293
  };
1473
1294
  export type AppIcon = {
1474
1295
  /**
1475
- * The name of the application.
1476
- * @see https://developer.mozilla.org/en-US/docs/Web/Manifest/name
1477
- */
1478
- name?: string;
1296
+ * The name of the application.
1297
+ * @see https://developer.mozilla.org/en-US/docs/Web/Manifest/name
1298
+ */ name?: string;
1479
1299
  /**
1480
- * The list of icons.
1481
- */
1482
- icons: AppIconItem[];
1300
+ * The list of icons.
1301
+ */ icons: AppIconItem[];
1483
1302
  /**
1484
- * The filename of the manifest file.
1485
- * @default 'manifest.webmanifest'
1486
- */
1487
- filename?: string;
1303
+ * The filename of the manifest file.
1304
+ * @default 'manifest.webmanifest'
1305
+ */ filename?: string;
1488
1306
  };
1489
1307
  type HtmlImplementation = 'js' | 'native';
1490
1308
  export interface HtmlConfig {
1491
1309
  /**
1492
- * Configure the `<meta>` tag of the HTML.
1493
- *
1494
- * @default
1495
- * ```js
1496
- * const defaultMeta = {
1497
- * charset: { charset: 'utf-8' },
1498
- * viewport: 'width=device-width, initial-scale=1.0',
1499
- * };
1500
- * ```
1501
- */
1502
- meta?: ChainedHtmlOption<MetaOptions>;
1503
- /**
1504
- * Set the title tag of the HTML page.
1505
- * @default 'Rsbuild App'
1506
- */
1507
- title?: ChainedHtmlOption<string>;
1508
- /**
1509
- * Set the inject position of the `<script>` tag.
1510
- * @default 'head'
1511
- */
1512
- inject?: ChainedHtmlOption<ScriptInject>;
1513
- /**
1514
- * Inject custom html tags into the output html files.
1515
- * @default undefined
1516
- */
1517
- tags?: OneOrMany<HtmlTagDescriptor>;
1518
- /**
1519
- * Set the favicon icon for all pages.
1520
- * @default undefined
1521
- */
1522
- favicon?: ChainedHtmlOption<string>;
1523
- /**
1524
- * Set the web application icons to display when added to the home screen of a mobile device.
1525
- *
1526
- * @default undefined
1527
- * @example
1528
- * appIcon: {
1529
- * name: 'My Website',
1530
- * icons: [
1531
- * { src: './icon-192.png', size: 192 },
1532
- * { src: './icon-512.png', size: 512 },
1533
- * ]
1534
- * }
1535
- */
1536
- appIcon?: AppIcon;
1537
- /**
1538
- * Set the id of root element.
1539
- * @default 'root'
1540
- */
1541
- mountId?: string;
1542
- /**
1543
- * Set the [crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) attribute
1544
- * of the `<script>` tag.
1545
- * @default false
1546
- */
1547
- crossorigin?: boolean | CrossOrigin;
1548
- /**
1549
- * Define the directory structure of the HTML output files.
1550
- * @default 'flat'
1551
- */
1552
- outputStructure?: OutputStructure;
1553
- /**
1554
- * Define the path to the HTML template,
1555
- * corresponding to the `template` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1556
- * @default A built-in HTML template
1557
- */
1558
- template?: ChainedHtmlOption<string>;
1559
- /**
1560
- * Define the parameters in the HTML template,
1561
- * corresponding to the `templateParameters` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin).
1562
- */
1563
- templateParameters?: ConfigChainWithContext<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>, {
1564
1371
  entryName: string;
1565
1372
  }>;
1566
1373
  /**
1567
- * Specifies how `<script>` tags generated by Rsbuild are loaded.
1568
- * - `'defer'`: Adds the `defer` attribute so scripts load in parallel and run after
1569
- * the document has been parsed.
1570
- * - `'module'`: Adds `type="module"` to enable ES modules semantics.
1571
- * - `'blocking'`: No `defer` or `async`, scripts execute immediately in order.
1572
- * @default 'defer'. If `output.module` is enabled, the value is always `'module'`.
1573
- */
1574
- scriptLoading?: ScriptLoading;
1575
- /**
1576
- * Specifies which implementation to use for generating HTML files.
1577
- *
1578
- * - `'js'` (default) - Use the JavaScript-based `html-rspack-plugin`.
1579
- * - `'native'` - Use Rspack's built-in `HtmlRspackPlugin` implemented in Rust.
1580
- *
1581
- * This option is experimental and may affect the available options in `tools.htmlPlugin`,
1582
- * since the two implementations are not fully compatible.
1583
- *
1584
- * @default 'js'
1585
- * @experimental
1586
- */
1587
- 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;
1588
1393
  }
1589
1394
  export type NormalizedHtmlConfig = HtmlConfig & {
1590
1395
  meta: ChainedHtmlOption<MetaOptions>;
@@ -1603,29 +1408,24 @@ export type RequestHandler = Connect.NextHandleFunction;
1603
1408
  export type EnvironmentAPI = Record<string, {
1604
1409
  /**
1605
1410
  * Get stats info about current environment.
1606
- */
1607
- getStats: () => Promise<Rspack.Stats>;
1411
+ */ getStats: () => Promise<Rspack.Stats>;
1608
1412
  /**
1609
1413
  * Load and execute stats bundle in Server.
1610
1414
  *
1611
1415
  * @param entryName - relate to rsbuild source.entry
1612
1416
  * @returns the return of entry module.
1613
- */
1614
- loadBundle: <T = unknown>(entryName: string) => Promise<T>;
1417
+ */ loadBundle: <T = unknown>(entryName: string) => Promise<T>;
1615
1418
  /**
1616
1419
  * Get the compiled HTML template.
1617
- */
1618
- getTransformedHtml: (entryName: string) => Promise<string>;
1420
+ */ getTransformedHtml: (entryName: string) => Promise<string>;
1619
1421
  /**
1620
1422
  * Send HMR message to the current environment only.
1621
- */
1622
- hot: {
1423
+ */ hot: {
1623
1424
  send: HotSend;
1624
1425
  };
1625
1426
  /**
1626
1427
  * Provides some context information about the current environment
1627
- */
1628
- context: EnvironmentContext;
1428
+ */ context: EnvironmentContext;
1629
1429
  }>;
1630
1430
  export type SetupMiddlewaresContext = Pick<RsbuildDevServer, 'sockWrite' | 'environments'>;
1631
1431
  export type SetupMiddlewaresFn = (middlewares: {
@@ -1634,106 +1434,89 @@ export type SetupMiddlewaresFn = (middlewares: {
1634
1434
  }, server: SetupMiddlewaresContext) => void;
1635
1435
  export type OverlayOptions = {
1636
1436
  /**
1637
- * Whether to show build errors in the overlay. You can pass a filter
1638
- * function to control which formatted build errors are rendered.
1639
- * Return false from the filter function to hide a specific error.
1640
- * @default true
1641
- */
1642
- errors?: boolean | ((error: Error) => boolean);
1643
- /**
1644
- * Whether to show runtime errors in the overlay. You can pass a filter
1645
- * function to control which runtime errors are rendered.
1646
- * Return false from the filter function to hide a specific error.
1647
- * @default false
1648
- */
1649
- 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);
1650
1448
  };
1651
1449
  export type ClientConfig = {
1652
1450
  /**
1653
- * The path for the WebSocket request.
1654
- * @default '/rsbuild-hmr'
1655
- */
1656
- path?: string;
1657
- /**
1658
- * The port number for the WebSocket request.
1659
- * @default location.port
1660
- */
1661
- port?: string | number;
1662
- /**
1663
- * The host for the WebSocket request.
1664
- * @default location.hostname
1665
- */
1666
- host?: string;
1667
- /**
1668
- * The protocol name for the WebSocket request.
1669
- * @default location.protocol === 'https:' ? 'wss' : 'ws'
1670
- */
1671
- protocol?: 'ws' | 'wss';
1672
- /**
1673
- * The maximum number of reconnection attempts after a WebSocket request is disconnected.
1674
- * @default 100
1675
- */
1676
- reconnect?: number;
1677
- /**
1678
- * Whether to display an error overlay in the browser.
1679
- * @default true
1680
- */
1681
- overlay?: boolean | OverlayOptions;
1682
- /**
1683
- * Controls the log level for client-side logging in the browser console.
1684
- * @default 'info'
1685
- */
1686
- 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';
1687
1478
  };
1688
1479
  export type NormalizedClientConfig = Optional<Required<ClientConfig>, 'protocol'>;
1689
1480
  export type { ChokidarOptions };
1690
1481
  export type WatchFiles = {
1691
1482
  /**
1692
- * Paths of the files or directories to watch, supports glob syntax.
1693
- */
1694
- paths: string | string[];
1483
+ * Paths of the files or directories to watch, supports glob syntax.
1484
+ */ paths: string | string[];
1695
1485
  /**
1696
- * Watch options passed to [chokidar](https://github.com/paulmillr/chokidar).
1697
- */
1698
- options?: ChokidarOptions;
1486
+ * Watch options passed to [chokidar](https://github.com/paulmillr/chokidar).
1487
+ */ options?: ChokidarOptions;
1699
1488
  /**
1700
- * Specifies whether to reload the page or restart the dev server when files change.
1701
- * @default 'reload-page'
1702
- */
1703
- 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';
1704
1492
  };
1705
1493
  export type CliShortcut = {
1706
1494
  /**
1707
- * The key to trigger the shortcut.
1708
- */
1709
- key: string;
1495
+ * The key to trigger the shortcut.
1496
+ */ key: string;
1710
1497
  /**
1711
- * The description of the shortcut.
1712
- */
1713
- description: string;
1498
+ * The description of the shortcut.
1499
+ */ description: string;
1714
1500
  /**
1715
- * The action to execute when the shortcut is triggered.
1716
- */
1717
- action: () => void | Promise<void>;
1501
+ * The action to execute when the shortcut is triggered.
1502
+ */ action: () => void | Promise<void>;
1718
1503
  };
1719
1504
  export type WriteToDisk = boolean | ((filename: string) => boolean);
1720
1505
  export type BrowserLogsStackTrace = 'summary' | 'full' | 'none';
1721
1506
  export type LiveReload = boolean | {
1722
1507
  /**
1723
- * Whether to trigger a full page reload when the HTML template changes.
1724
- * @default true
1725
- */
1726
- html?: boolean;
1508
+ * Whether to trigger a full page reload when the HTML template changes.
1509
+ * @default true
1510
+ */ html?: boolean;
1727
1511
  };
1728
1512
  export interface DevConfig {
1729
1513
  /**
1730
- * Controls whether to forward browser runtime errors to the terminal. When `true`, the dev
1731
- * client listens for `window.error` events and unhandled Promise rejections in the browser,
1732
- * then sends them to the dev server where they are printed in the terminal (prefixed with
1733
- * `[browser]`).
1734
- * @default { stackTrace: 'summary' }
1735
- */
1736
- 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 | {
1737
1520
  /**
1738
1521
  * Controls how the error stack trace is displayed in the terminal when forwarding
1739
1522
  * browser errors.
@@ -1741,77 +1524,64 @@ export interface DevConfig {
1741
1524
  * - `'full'` – Print the full stack trace with all frames.
1742
1525
  * - `'none'` – Hide stack traces.
1743
1526
  * @default 'summary'
1744
- */
1745
- stackTrace?: BrowserLogsStackTrace;
1527
+ */ stackTrace?: BrowserLogsStackTrace;
1746
1528
  };
1747
1529
  /**
1748
- * Whether to enable Hot Module Replacement.
1749
- * @default true
1750
- */
1751
- hmr?: boolean;
1752
- /**
1753
- * Whether to reload the page when file changes are detected.
1754
- * @default true
1755
- */
1756
- liveReload?: LiveReload;
1757
- /**
1758
- * Set the URL prefix of static assets in development mode,
1759
- * similar to the [output.publicPath](https://rspack.rs/config/output#outputpublicpath)
1760
- * config of Rspack.
1761
- * @default `server.base`
1762
- */
1763
- assetPrefix?: LiteralUnion<'auto', string> | boolean;
1764
- /**
1765
- * Whether to render progress bars to display the build progress.
1766
- * @default false
1767
- */
1768
- progressBar?: boolean | ProgressBarConfig;
1769
- /**
1770
- * Config for Rsbuild client code.
1771
- */
1772
- client?: ClientConfig;
1773
- /**
1774
- * Whether to enable CLI shortcuts.
1775
- * @default true when using Rsbuild CLI, otherwise false
1776
- */
1777
- 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 | {
1778
1554
  /**
1779
1555
  * Customize the CLI shortcuts.
1780
1556
  * @param shortcuts - The default CLI shortcuts.
1781
1557
  * @returns - The customized CLI shortcuts.
1782
- */
1783
- custom?: (shortcuts: CliShortcut[]) => CliShortcut[];
1558
+ */ custom?: (shortcuts: CliShortcut[]) => CliShortcut[];
1784
1559
  /**
1785
1560
  * Whether to print the help hint when the server is started.
1786
1561
  * - `true`: Print the default help hint.
1787
1562
  * - `false`: Disable the help hint.
1788
1563
  * - `string`: Print a custom help hint.
1789
1564
  * @default true
1790
- */
1791
- help?: boolean | string;
1565
+ */ help?: boolean | string;
1792
1566
  };
1793
1567
  /**
1794
- * Used to add custom middleware to the dev server.
1795
- * @deprecated Use `server.setup` instead
1796
- * @default undefined
1797
- */
1798
- setupMiddlewares?: SetupMiddlewaresFn | SetupMiddlewaresFn[];
1799
- /**
1800
- * Controls whether the build output from development mode is written to disk.
1801
- * @default false
1802
- */
1803
- writeToDisk?: WriteToDisk;
1804
- /**
1805
- * Watch specified files and directories for changes. When a file change is detected,
1806
- * it can trigger a page reload or restart the dev server.
1807
- * @default undefined
1808
- */
1809
- watchFiles?: WatchFiles | WatchFiles[];
1810
- /**
1811
- * Enable lazy compilation (compilation on demand).
1812
- * @default { imports: true, entries: false }
1813
- */
1814
- 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;
1815
1585
  }
1816
1586
  export type NormalizedDevConfig = Omit<DevConfig, 'watchFiles'> & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk' | 'cliShortcuts' | 'browserLogs'>> & {
1817
1587
  watchFiles: WatchFiles[];
@@ -1819,48 +1589,42 @@ export type NormalizedDevConfig = Omit<DevConfig, 'watchFiles'> & Required<Pick<
1819
1589
  };
1820
1590
  export interface ResolveConfig {
1821
1591
  /**
1822
- * Force Rsbuild to resolve the specified packages from project root,
1823
- * which is useful for deduplicating packages and reducing the bundle size.
1824
- */
1825
- dedupe?: string[];
1826
- /**
1827
- * Set the alias for the module path, which is used to simplify the import path or
1828
- * redirect the module reference.
1829
- * Similar to the [resolve.alias](https://rspack.rs/config/resolve) config of Rspack.
1830
- * @default { '@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')) }
1831
- */
1832
- alias?: ConfigChain<Alias>;
1833
- /**
1834
- * Set the strategy for path alias resolution, to control the priority relationship
1835
- * between the `paths` option in `tsconfig.json` and the `resolve.alias` option of Rsbuild.
1836
- * - `prefer-tsconfig`: The `paths` option in `tsconfig.json` will take precedence over the
1837
- * `resolve.alias` option of Rsbuild.
1838
- * - `prefer-alias`: The `resolve.alias` option of Rsbuild will take precedence over the
1839
- * `paths` option in `tsconfig.json`.
1840
- * @default 'prefer-tsconfig'
1841
- */
1842
- aliasStrategy?: AliasStrategy;
1843
- /**
1844
- * Automatically resolve file extensions when importing modules.
1845
- * This means you can import files without explicitly writing their extensions.
1846
- * @default ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json']
1847
- */
1848
- extensions?: string[];
1849
- /**
1850
- * Specifies the condition names used to match entry points in the exports field
1851
- * of a package.
1852
- * @default Inherits from Rspack. See https://rspack.rs/config/resolve#resolveconditionnames
1853
- */
1854
- conditionNames?: string[];
1855
- /**
1856
- * Controls the priority of fields in a package.json used to locate a package's
1857
- * entry file. It is the ordered list of package.json fields Rspack will try
1858
- * when resolving an npm package's entry point.
1859
- * @default
1860
- * - If `output.target` is `'web'`, `'web-worker'`, or not specified, the default value is `["browser", "module", "main"]`.
1861
- * - If `output.target` is `'node'`, the default value is `["module", "main"]`.
1862
- */
1863
- 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[];
1864
1628
  }
1865
1629
  export type NormalizedResolveConfig = ResolveConfig & Pick<Required<ResolveConfig>, 'alias' | 'aliasStrategy' | 'extensions'>;
1866
1630
  export type ModuleFederationConfig = {
@@ -1869,115 +1633,92 @@ export type ModuleFederationConfig = {
1869
1633
  export type NormalizedModuleFederationConfig = ModuleFederationConfig;
1870
1634
  export type RsbuildConfigMeta = {
1871
1635
  /**
1872
- * Path to the rsbuild config file.
1873
- */
1874
- configFilePath: string;
1636
+ * Path to the rsbuild config file.
1637
+ */ configFilePath: string;
1875
1638
  };
1876
1639
  /**
1877
1640
  * Only some dev options can be defined in the environment config
1878
- */
1879
- export type AllowedEnvironmentDevKeys = 'hmr' | 'client' | 'liveReload' | 'browserLogs' | 'assetPrefix' | 'progressBar' | 'lazyCompilation' | 'writeToDisk';
1641
+ */ export type AllowedEnvironmentDevKeys = 'hmr' | 'client' | 'liveReload' | 'browserLogs' | 'assetPrefix' | 'progressBar' | 'lazyCompilation' | 'writeToDisk';
1880
1642
  /**
1881
1643
  * The Rsbuild config to run in the specified environment.
1882
- */
1883
- export interface EnvironmentConfig {
1644
+ */ export interface EnvironmentConfig {
1884
1645
  /**
1885
- * Options for local development.
1886
- */
1887
- dev?: Pick<DevConfig, AllowedEnvironmentDevKeys>;
1646
+ * Options for local development.
1647
+ */ dev?: Pick<DevConfig, AllowedEnvironmentDevKeys>;
1888
1648
  /**
1889
- * Options for HTML generation.
1890
- */
1891
- html?: HtmlConfig;
1649
+ * Options for HTML generation.
1650
+ */ html?: HtmlConfig;
1892
1651
  /**
1893
- * Options for the low-level tools.
1894
- */
1895
- tools?: ToolsConfig;
1652
+ * Options for the low-level tools.
1653
+ */ tools?: ToolsConfig;
1896
1654
  /**
1897
- * Options for module resolution.
1898
- */
1899
- resolve?: ResolveConfig;
1655
+ * Options for module resolution.
1656
+ */ resolve?: ResolveConfig;
1900
1657
  /**
1901
- * Options for input source code.
1902
- */
1903
- source?: SourceConfig;
1658
+ * Options for input source code.
1659
+ */ source?: SourceConfig;
1904
1660
  /**
1905
- * Options for build outputs.
1906
- */
1907
- output?: OutputConfig;
1661
+ * Options for build outputs.
1662
+ */ output?: OutputConfig;
1908
1663
  /**
1909
- * Options for Web security.
1910
- */
1911
- security?: SecurityConfig;
1664
+ * Options for Web security.
1665
+ */ security?: SecurityConfig;
1912
1666
  /**
1913
- * Options for build performance and runtime performance.
1914
- */
1915
- performance?: PerformanceConfig;
1667
+ * Options for build performance and runtime performance.
1668
+ */ performance?: PerformanceConfig;
1916
1669
  /**
1917
- * Options for chunk splitting.
1918
- */
1919
- splitChunks?: SplitChunksConfig | false;
1670
+ * Options for chunk splitting.
1671
+ */ splitChunks?: SplitChunksConfig | false;
1920
1672
  /**
1921
- * Options for module federation.
1922
- */
1923
- moduleFederation?: ModuleFederationConfig;
1673
+ * Options for module federation.
1674
+ */ moduleFederation?: ModuleFederationConfig;
1924
1675
  /**
1925
- * Configure Rsbuild plugins.
1926
- */
1927
- plugins?: RsbuildPlugins;
1676
+ * Configure Rsbuild plugins.
1677
+ */ plugins?: RsbuildPlugins;
1928
1678
  }
1929
1679
  export type LogLevel = 'info' | 'warn' | 'error' | 'silent';
1930
1680
  /**
1931
1681
  * The Rsbuild config.
1932
- */
1933
- export interface RsbuildConfig extends EnvironmentConfig {
1934
- /**
1935
- * Specify the build mode for Rsbuild, as each mode has different default behavior and optimizations.
1936
- * @default Depends on `process.env.NODE_ENV`:
1937
- * - `'production'` if NODE_ENV is 'production'
1938
- * - `'development'` if NODE_ENV is 'development'
1939
- * - otherwise `'none'`
1940
- */
1941
- mode?: RsbuildMode;
1942
- /**
1943
- * Specify the project root directory. Can be an absolute path, or a path relative to `process.cwd()`.
1944
- * @default `process.cwd()`
1945
- */
1946
- root?: string;
1947
- /**
1948
- * Specify the log level of Rsbuild.
1949
- * - 'info': Output all logs.
1950
- * - 'warn': Output `warn` and `error` level logs.
1951
- * - 'error': Output `error` level logs.
1952
- * - 'silent': Do not output any logs.
1953
- * @default 'info'
1954
- */
1955
- logLevel?: LogLevel;
1956
- /**
1957
- * Use a custom logger instance for the current Rsbuild instance.
1958
- * You can create one via `createLogger()`.
1959
- */
1960
- customLogger?: Logger;
1961
- /**
1962
- * Options for local development.
1963
- */
1964
- dev?: DevConfig;
1965
- /**
1966
- * Options for the Rsbuild server.
1967
- * Mainly applies to local development and preview.
1968
- * Some options (e.g. `publicDir`, `base`) also affect production builds.
1969
- */
1970
- server?: ServerConfig;
1971
- /**
1972
- * Configure Rsbuild config by environment.
1973
- * The key represents the environment name.
1974
- * The value is the Rsbuild config for the specified environment.
1975
- */
1976
- environments?: Record<string, EnvironmentConfig>;
1977
- /**
1978
- * @private
1979
- */
1980
- _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;
1981
1722
  }
1982
1723
  export type MergedEnvironmentConfig = {
1983
1724
  mode: RsbuildMode;
@@ -1998,8 +1739,7 @@ export type MergedEnvironmentConfig = {
1998
1739
  };
1999
1740
  /**
2000
1741
  * The normalized Rsbuild environment config.
2001
- */
2002
- export type NormalizedEnvironmentConfig = TwoLevelReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
1742
+ */ export type NormalizedEnvironmentConfig = TwoLevelReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
2003
1743
  dev: NormalizedDevConfig;
2004
1744
  server: NormalizedServerConfig;
2005
1745
  _privateMeta?: RsbuildConfigMeta;