@ohos-ports/rsbuild-core 1.7.2-beta.1

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