@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,585 @@
1
+ /** @ts-ignore `webpack` type only exists when `@rsbuild/webpack` is installed */
2
+ import type { RuleSetRule, Configuration as WebpackConfig, WebpackPluginInstance } from 'webpack';
3
+ import type { ChainIdentifier } from '../configChain';
4
+ import type { Logger } from '../logger';
5
+ import type { ModifyRspackConfigUtils, NarrowedRspackConfig, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig, RspackMerge } from './config';
6
+ import type { RsbuildContext } from './context';
7
+ import type { EnvironmentContext, ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnExitFn } from './hooks';
8
+ import type { AddPluginsOptions, RsbuildInstance, RsbuildTarget } from './rsbuild';
9
+ import type { Rspack, RspackChain } from './rspack';
10
+ import type { HtmlRspackPlugin } from './thirdParty';
11
+ import type { Falsy, MaybePromise } from './utils';
12
+ type HookOrder = 'pre' | 'post' | 'default';
13
+ export type HookDescriptor<T extends (...args: any[]) => any> = {
14
+ handler: T;
15
+ order: HookOrder;
16
+ };
17
+ export type EnvironmentAsyncHook<Callback extends (...args: any[]) => T, T = any> = {
18
+ /**
19
+ * Registers a callback function to be executed when the hook is triggered.
20
+ * The callback can be a plain function or a HookDescriptor that includes execution order.
21
+ * The callback will be executed in all environments by default.
22
+ * If you need to specify the environment, use `tapEnvironment`
23
+ * @param cb The callback function or hook descriptor to register
24
+ */
25
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
26
+ /**
27
+ * Registers a callback function to be executed when the hook is triggered.
28
+ * The callback will only be executed under the specified environment.
29
+ */
30
+ tapEnvironment: (params: {
31
+ /**
32
+ * Specify the environment that the callback will be executed under.
33
+ */
34
+ environment?: string;
35
+ /**
36
+ * The callback function or hook descriptor to register
37
+ */
38
+ handler: Callback | HookDescriptor<Callback>;
39
+ }) => void;
40
+ /**
41
+ * Executes callbacks in sequence independently and collects all their results into an array.
42
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
43
+ * @returns A promise that resolves with an array containing the results of all callbacks
44
+ */
45
+ callChain: (params: {
46
+ /**
47
+ * Specify the environment for filtering callbacks.
48
+ */
49
+ environment?: string;
50
+ /**
51
+ * The parameters to pass to each callback
52
+ */
53
+ args: Parameters<Callback>;
54
+ /**
55
+ * The callback function to be executed after each callback
56
+ */
57
+ afterEach?: (args: Parameters<Callback>) => void;
58
+ }) => Promise<Parameters<Callback>>;
59
+ /**
60
+ * Executes callbacks in sequence independently and collects all their results into an array.
61
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
62
+ * @returns A promise that resolves with an array containing the results of all callbacks
63
+ */
64
+ callBatch: (params: {
65
+ /**
66
+ * Specify the environment for filtering callbacks.
67
+ */
68
+ environment?: string;
69
+ /**
70
+ * The parameters to pass to each callback
71
+ */
72
+ args: Parameters<Callback>;
73
+ }) => Promise<Awaited<ReturnType<Callback>>[]>;
74
+ };
75
+ export type AsyncHook<Callback extends (...args: any[]) => T, T = any> = {
76
+ /**
77
+ * Registers a callback function to be executed when the hook is triggered.
78
+ * The callback can be a plain function or a HookDescriptor that includes execution order.
79
+ * @param cb The callback function or hook descriptor to register
80
+ */
81
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
82
+ /**
83
+ * Executes callbacks in sequence, passing the result of each callback as the first argument
84
+ * to the next callback in the chain. If a callback returns undefined, the original arguments
85
+ * will be passed to the next callback.
86
+ * @param params The initial parameters to pass to the first callback
87
+ * @returns A promise that resolves with the final parameters after all callbacks have executed
88
+ */
89
+ callChain: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
90
+ /**
91
+ * Executes callbacks in sequence independently and collects all their results into an array.
92
+ * Each callback receives the original parameters, and their results don't affect subsequent callbacks.
93
+ * @param params The parameters to pass to each callback
94
+ * @returns A promise that resolves with an array containing the results of all callbacks
95
+ */
96
+ callBatch: (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>[]>;
97
+ };
98
+ export type ModifyRspackConfigFn = (config: NarrowedRspackConfig, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
99
+ export type ModifyWebpackChainUtils = ModifyChainUtils & {
100
+ /** @ts-ignore `webpack` type only exists when `@rsbuild/webpack` is installed */
101
+ webpack: typeof import('webpack');
102
+ CHAIN_ID: ChainIdentifier;
103
+ /**
104
+ * @deprecated Use target instead.
105
+ */
106
+ name: string;
107
+ /**
108
+ * @deprecated Use HtmlPlugin instead.
109
+ */
110
+ HtmlWebpackPlugin: typeof HtmlRspackPlugin;
111
+ };
112
+ export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
113
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
114
+ appendRules: (rules: RuleSetRule | RuleSetRule[]) => void;
115
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
116
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
117
+ removePlugin: (pluginName: string) => void;
118
+ mergeConfig: RspackMerge;
119
+ };
120
+ export type ModifyWebpackChainFn = (chain: RspackChain, utils: ModifyWebpackChainUtils) => Promise<void> | void;
121
+ export type ModifyWebpackConfigFn = (config: WebpackConfig, utils: ModifyWebpackConfigUtils) => Promise<WebpackConfig | void> | WebpackConfig | void;
122
+ export type PluginMeta = {
123
+ environment?: AddPluginsOptions['environment'];
124
+ instance: RsbuildPlugin;
125
+ };
126
+ export type PluginManager = Pick<RsbuildInstance, 'getPlugins' | 'addPlugins' | 'isPluginExists' | 'removePlugins'> & {
127
+ /** Get all plugins with environment info */
128
+ getAllPluginsWithMeta: () => PluginMeta[];
129
+ };
130
+ export type RsbuildPluginApplyFn = (this: void,
131
+ /**
132
+ * The original Rsbuild configuration object (before plugin processing)
133
+ */
134
+ config: RsbuildConfig, context: Pick<RsbuildContext, 'action'>) => boolean;
135
+ export type RsbuildPluginApply = 'serve' | 'build' | RsbuildPluginApplyFn;
136
+ /**
137
+ * Defines the structure and behavior of an Rsbuild plugin.
138
+ * Rsbuild plugins provide a standardized way to extend build functionality through
139
+ * lifecycle hooks and configuration modifications.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * const myPlugin = (): RsbuildPlugin => ({
144
+ * name: 'my-plugin',
145
+ * setup(api) {
146
+ * api.onBeforeBuild(() => {
147
+ * console.log('Build starting...');
148
+ * });
149
+ * }
150
+ * });
151
+ * ```
152
+ */
153
+ export type RsbuildPlugin = {
154
+ /**
155
+ * The name of the plugin, a unique identifier.
156
+ */
157
+ name: string;
158
+ /**
159
+ * Conditional apply the plugin during serve or build.
160
+ * - `'serve'`: Apply the plugin when starting the dev server or preview server.
161
+ * - `'build'`: Apply the plugin during build.
162
+ * - Can be a function that returns `true` to apply the plugin or `false` to skip it.
163
+ * - If not specified, the plugin will be applied during both serve and build.
164
+ */
165
+ apply?: RsbuildPluginApply;
166
+ /**
167
+ * The setup function of the plugin, which can be an async function.
168
+ * This function is called once when the plugin is initialized.
169
+ * @param api provides the context info, utility functions and lifecycle hooks.
170
+ */
171
+ setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
172
+ /**
173
+ * Specifies the execution order of the plugin.
174
+ * - `'pre'`: Execute the plugin before other plugins.
175
+ * - `'post'`: Execute the plugin after other plugins.
176
+ * - If not specified, the plugin will execute in the order they were registered.
177
+ *
178
+ * This affects the order in which hooks are registered, but if a hook specifies
179
+ * an `order` property, the `order` takes higher precedence.
180
+ */
181
+ enforce?: 'pre' | 'post';
182
+ /**
183
+ * Declare the names of pre-plugins, which will be executed before the current plugin.
184
+ * This has higher precedence than the `enforce` property.
185
+ */
186
+ pre?: string[];
187
+ /**
188
+ * Declare the names of post-plugins, which will be executed after the current plugin.
189
+ * This has higher precedence than the `enforce` property.
190
+ */
191
+ post?: string[];
192
+ /**
193
+ * Declare the plugins that need to be removed, you can pass an array of plugin names.
194
+ */
195
+ remove?: string[];
196
+ };
197
+ type LooseRsbuildPlugin = Omit<RsbuildPlugin, 'setup' | 'apply'> & {
198
+ apply?: any;
199
+ setup: (api: any) => MaybePromise<void>;
200
+ };
201
+ export type RsbuildPlugins = (LooseRsbuildPlugin | Falsy | Promise<LooseRsbuildPlugin | Falsy | RsbuildPlugins> | RsbuildPlugins)[];
202
+ export type GetRsbuildConfig = {
203
+ (): Readonly<RsbuildConfig>;
204
+ (type: 'original' | 'current'): Readonly<RsbuildConfig>;
205
+ (type: 'normalized'): NormalizedConfig;
206
+ };
207
+ type PluginHook<T extends (...args: any[]) => any> = (options: T | HookDescriptor<T>) => void;
208
+ type TransformResult = string | Buffer | {
209
+ code: string | Buffer;
210
+ map?: string | Rspack.RawSourceMap | null;
211
+ };
212
+ export type TransformContext<Raw extends boolean = false> = {
213
+ /**
214
+ * The code of the module.
215
+ * When `raw` is true, this will be a Buffer instead of a string.
216
+ */
217
+ code: Raw extends true ? Buffer : string;
218
+ /**
219
+ * The directory path of the currently processed module,
220
+ * which changes with the location of each processed module.
221
+ */
222
+ context: string | null;
223
+ /**
224
+ * The absolute path of the module, including the query.
225
+ * @example '/home/user/project/src/index.js?foo=123'
226
+ */
227
+ resource: string;
228
+ /**
229
+ * The absolute path of the module, without the query.
230
+ * @example '/home/user/project/src/index.js'
231
+ */
232
+ resourcePath: string;
233
+ /**
234
+ * The query of the module.
235
+ * @example '?foo=123'
236
+ */
237
+ resourceQuery: string;
238
+ /**
239
+ * The environment context for current build.
240
+ */
241
+ environment: EnvironmentContext;
242
+ /**
243
+ * Add an additional file as the dependency.
244
+ * The file will be watched and changes to the file will trigger rebuild.
245
+ * @param file The absolute path of the module
246
+ */
247
+ addDependency: (file: string) => void;
248
+ /**
249
+ * Add a non-existing file as a dependency.
250
+ * Similar to addDependency, but handles the creation of files during compilation before watchers are attached correctly.
251
+ * The file will be watched and changes to the file will trigger rebuild.
252
+ * @param file The absolute path of the module
253
+ */
254
+ addMissingDependency(file: string): void;
255
+ /**
256
+ * Add a directory as dependency.
257
+ * The directory will be watched and changes to the directory will trigger rebuild.
258
+ * @param context The absolute path of the directory
259
+ */
260
+ addContextDependency(context: string): void;
261
+ /**
262
+ * Emits a file to the build output.
263
+ * @param name file name of the asset
264
+ * @param content the source of the asset
265
+ * @param sourceMap source map of the asset
266
+ * @param assetInfo additional asset information
267
+ */
268
+ emitFile: Rspack.LoaderContext['emitFile'];
269
+ /**
270
+ * Compile and execute a module at the build time.
271
+ */
272
+ importModule: Rspack.LoaderContext['importModule'];
273
+ /**
274
+ * Resolve a module specifier.
275
+ */
276
+ resolve: Rspack.LoaderContext['resolve'];
277
+ };
278
+ export type TransformHandler<Raw extends boolean = false> = (context: TransformContext<Raw>) => MaybePromise<TransformResult>;
279
+ export type TransformDescriptor = {
280
+ /**
281
+ * Include modules that match the test assertion, the same as `rules[].test`
282
+ * @see https://rspack.rs/config/module-rules#rulestest
283
+ */
284
+ test?: Rspack.RuleSetCondition;
285
+ /**
286
+ * A condition that matches the resource query.
287
+ * @see https://rspack.rs/config/module-rules#rulesresourcequery
288
+ */
289
+ resourceQuery?: Rspack.RuleSetCondition;
290
+ /**
291
+ * Match based on the Rsbuild targets and only apply the transform to
292
+ * certain targets.
293
+ * @see https://rsbuild.rs/config/output/target
294
+ */
295
+ targets?: RsbuildTarget[];
296
+ /**
297
+ * Match based on the Rsbuild environment names and only apply the transform
298
+ * to certain environments.
299
+ * @see https://rsbuild.rs/config/environments
300
+ */
301
+ environments?: string[];
302
+ /**
303
+ * If raw is `true`, the transform handler will receive the Buffer type code
304
+ * instead of the string type.
305
+ * @see https://rspack.rs/api/loader-api/examples#raw-loader
306
+ */
307
+ raw?: boolean;
308
+ /**
309
+ * Marks the layer of the matching module, can be used to group a group of
310
+ * modules into one layer
311
+ * @see https://rspack.rs/config/module-rules#ruleslayer
312
+ */
313
+ layer?: string;
314
+ /**
315
+ * Matches all modules that match this resource, and will match against layer of
316
+ * the module that issued the current module.
317
+ * @see https://rspack.rs/config/module-rules#rulesissuerlayer
318
+ */
319
+ issuerLayer?: string;
320
+ /**
321
+ * Matches all modules that match this resource, and will match against Resource
322
+ * (the absolute path without query and fragment) of the module that issued the
323
+ * current module.
324
+ * @see https://rspack.rs/config/module-rules#rulesissuer
325
+ */
326
+ issuer?: Rspack.RuleSetCondition;
327
+ /**
328
+ * Matches [import attributes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with)
329
+ * @see https://rspack.rs/config/module-rules#ruleswith
330
+ */
331
+ with?: Record<string, Rspack.RuleSetCondition>;
332
+ /**
333
+ * Matches modules based on MIME type instead of file extension. It's primarily
334
+ * useful for data URI module (like `data:text/javascript,...`).
335
+ * @see https://rspack.rs/config/module-rules#rulesmimetype
336
+ */
337
+ mimetype?: Rspack.RuleSetCondition;
338
+ /**
339
+ * The original property for specifying execution order, now deprecated in favor of `order`.
340
+ * @deprecated Use `order` instead.
341
+ */
342
+ enforce?: 'pre' | 'post';
343
+ /**
344
+ * Specifies the execution order of the transform function.
345
+ * - When specified as 'pre', the transform function will execute before other
346
+ * transform functions (or Rspack loaders).
347
+ * - When specified as 'post', the transform function will execute after other
348
+ * transform functions (or Rspack loaders).
349
+ * @see https://rspack.rs/config/module-rules#rulesenforce
350
+ */
351
+ order?: HookOrder;
352
+ };
353
+ export type TransformHook = <T extends TransformDescriptor>(descriptor: T, handler: TransformHandler<T['raw'] extends true ? true : false>) => void;
354
+ export type ProcessAssetsStage = 'additional' | 'pre-process' | 'derived' | 'additions' | 'none' | 'optimize' | 'optimize-count' | 'optimize-compatibility' | 'optimize-size' | 'dev-tooling' | 'optimize-inline' | 'summarize' | 'optimize-hash' | 'optimize-transfer' | 'analyse' | 'report';
355
+ export type ProcessAssetsDescriptor = {
356
+ /**
357
+ * Specifies the order in which your asset processing logic should run relative to other plugins.
358
+ */
359
+ stage: ProcessAssetsStage;
360
+ /**
361
+ * Match based on the Rsbuild targets and only process the assets of certain targets.
362
+ * @see https://rsbuild.rs/config/output/target
363
+ */
364
+ targets?: RsbuildTarget[];
365
+ /**
366
+ * Match based on the Rsbuild environment names and only process the assets of certain environments.
367
+ * @see https://rsbuild.rs/config/environments
368
+ */
369
+ environments?: string[];
370
+ };
371
+ export type RspackSources = Pick<typeof Rspack.sources, 'Source' | 'RawSource' | 'OriginalSource' | 'SourceMapSource' | 'CachedSource' | 'ConcatSource' | 'ReplaceSource' | 'PrefixSource' | 'SizeOnlySource' | 'CompatSource'>;
372
+ export type ProcessAssetsHandler = (context: {
373
+ assets: Record<string, Rspack.sources.Source>;
374
+ compiler: Rspack.Compiler;
375
+ compilation: Rspack.Compilation;
376
+ /**
377
+ * The environment context for current build.
378
+ */
379
+ environment: EnvironmentContext;
380
+ /**
381
+ * Contains multiple classes which represent an Rspack `Source`.
382
+ */
383
+ sources: RspackSources;
384
+ }) => Promise<void> | void;
385
+ export type ResolveHandler = (context: {
386
+ /** Module request information */
387
+ resolveData: Rspack.ResolveData;
388
+ /** The environment context for current build. */
389
+ environment: EnvironmentContext;
390
+ compiler: Rspack.Compiler;
391
+ compilation: Rspack.Compilation;
392
+ }) => Promise<void> | void;
393
+ export type ResolveHook = (handler: ResolveHandler) => void;
394
+ export type ProcessAssetsHook = (descriptor: ProcessAssetsDescriptor, handler: ProcessAssetsHandler) => void;
395
+ declare function getNormalizedConfig(): NormalizedConfig;
396
+ declare function getNormalizedConfig(options: {
397
+ environment: string;
398
+ }): NormalizedEnvironmentConfig;
399
+ /**
400
+ * The API interface provided to Rsbuild plugins through the `setup` function.
401
+ * It allows plugins to interact with the build process, modify configurations,
402
+ * register hooks, and access context information.
403
+ */
404
+ export type RsbuildPluginAPI = Readonly<{
405
+ /**
406
+ * A read-only object that provides some context information.
407
+ */
408
+ context: Readonly<RsbuildContext>;
409
+ /**
410
+ * Explicitly expose some properties or methods of the current plugin,
411
+ * and other plugins can get these APIs through `api.useExposed`.
412
+ */
413
+ expose: <T = any>(id: string | symbol, api: T) => void;
414
+ /**
415
+ * Get the Rsbuild config, this method must be called after the
416
+ * `modifyRsbuildConfig` hook is executed.
417
+ */
418
+ getRsbuildConfig: GetRsbuildConfig;
419
+ /**
420
+ * Get the all normalized Rsbuild config or the Rsbuild config of a specified
421
+ * environment, this method must be called after the
422
+ * `modifyRsbuildConfig` hook is executed.
423
+ */
424
+ getNormalizedConfig: typeof getNormalizedConfig;
425
+ /**
426
+ * A logger instance used to output log information in a unified format.
427
+ * Use this instead of `console.log` to maintain consistent logging with Rsbuild.
428
+ * Equivalent to `import { logger } from '@rsbuild/core'`.
429
+ */
430
+ logger: Logger;
431
+ /**
432
+ * Determines if a plugin has been registered in the current Rsbuild instance.
433
+ */
434
+ isPluginExists: (pluginName: string, options?: {
435
+ /**
436
+ * Whether it exists in the specified environment.
437
+ * If environment is not specified, determine whether the plugin is a global plugin.
438
+ */
439
+ environment: string;
440
+ }) => boolean;
441
+ /**
442
+ * Allows you to modify the Rspack configuration using the `rspack-chain` API,
443
+ * providing the same functionality as `tools.bundlerChain`.
444
+ */
445
+ modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
446
+ /**
447
+ * Modify the Rsbuild configuration of a specific environment.
448
+ */
449
+ modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
450
+ /**
451
+ * Modify the final HTML content. The hook receives a HTML string
452
+ * and a context object, and you can return a new HTML string to
453
+ * replace the original one. This hook is triggered after the
454
+ * `modifyHTMLTags` hook.
455
+ */
456
+ modifyHTML: PluginHook<ModifyHTMLFn>;
457
+ /**
458
+ * Modify the tags that are injected into the HTML.
459
+ * This hook is triggered before the `modifyHTML` hook.
460
+ */
461
+ modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
462
+ /**
463
+ * To modify the Rspack config, you can directly modify the config object,
464
+ * or return a new object to replace the previous object.
465
+ */
466
+ modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
467
+ /**
468
+ * Modify the config passed to the Rsbuild, you can directly modify the config object,
469
+ * or return a new object to replace the previous object.
470
+ */
471
+ modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
472
+ /**
473
+ * Allows you to modify the webpack configuration using the `rspack-chain` API,
474
+ * providing the same functionality as `tools.bundlerChain`.
475
+ */
476
+ modifyWebpackChain: PluginHook<ModifyWebpackChainFn>;
477
+ /**
478
+ * To modify the webpack config, you can directly modify the config object,
479
+ * or return a new object to replace the previous object.
480
+ */
481
+ modifyWebpackConfig: PluginHook<ModifyWebpackConfigFn>;
482
+ /**
483
+ * A callback function that is triggered after running the production build.
484
+ * You can access the build result information via the
485
+ * [stats](https://rspack.rs/api/javascript-api/stats) parameter.
486
+ */
487
+ onAfterBuild: PluginHook<OnAfterBuildFn>;
488
+ /**
489
+ * A callback function that is triggered after the compiler instance has been
490
+ * created, but before the build process. This hook is called when you run
491
+ * `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
492
+ */
493
+ onAfterCreateCompiler: PluginHook<OnAfterCreateCompilerFn>;
494
+ /**
495
+ * Called after each development mode build, you can use `isFirstCompile`
496
+ * to determine whether it is the first build.
497
+ */
498
+ onAfterDevCompile: PluginHook<OnAfterDevCompileFn>;
499
+ /**
500
+ * A callback function that is triggered after the compilation of a single environment.
501
+ * You can access the build result information via the
502
+ * [stats](https://rspack.rs/api/javascript-api/stats) parameter.
503
+ */
504
+ onAfterEnvironmentCompile: PluginHook<OnAfterEnvironmentCompileFn>;
505
+ /**
506
+ * Called after starting the dev server, you can get the port number with the
507
+ * `port` parameter, and the page routes info with the `routes` parameter.
508
+ */
509
+ onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
510
+ /**
511
+ * Called after starting the production preview server, you can get the port
512
+ * number with the `port` parameter, and the page routes info with the
513
+ * `routes` parameter.
514
+ */
515
+ onAfterStartProdServer: PluginHook<OnAfterStartProdServerFn>;
516
+ /**
517
+ * A callback function that is triggered before the production build is executed.
518
+ */
519
+ onBeforeBuild: PluginHook<OnBeforeBuildFn>;
520
+ /**
521
+ * A callback function that is triggered before the dev build is executed.
522
+ */
523
+ onBeforeDevCompile: PluginHook<OnBeforeDevCompileFn>;
524
+ /**
525
+ * A callback function that is triggered after the Compiler instance has been
526
+ * created, but before the build process begins. This hook is called when you
527
+ * run `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
528
+ */
529
+ onBeforeCreateCompiler: PluginHook<OnBeforeCreateCompilerFn>;
530
+ /**
531
+ * A callback function that is triggered before the compilation of a single environment.
532
+ */
533
+ onBeforeEnvironmentCompile: PluginHook<OnBeforeEnvironmentCompileFn>;
534
+ /**
535
+ * Called before starting the dev server.
536
+ */
537
+ onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
538
+ /**
539
+ * Called before starting the production preview server.
540
+ */
541
+ onBeforeStartProdServer: PluginHook<OnBeforeStartProdServerFn>;
542
+ /**
543
+ * Called when closing the build instance. Can be used to perform cleanup
544
+ * operations when the building is closed.
545
+ */
546
+ onCloseBuild: PluginHook<OnCloseBuildFn>;
547
+ /**
548
+ * Called when closing the dev server. Can be used to perform cleanup
549
+ * operations when the dev server is closed.
550
+ */
551
+ onCloseDevServer: PluginHook<OnCloseDevServerFn>;
552
+ /**
553
+ * Alias for the `onAfterDevCompile` hook.
554
+ * @deprecated Use `onAfterDevCompile` instead (added in v1.5.0).
555
+ * Both hooks have identical functionality.
556
+ */
557
+ onDevCompileDone: PluginHook<OnAfterDevCompileFn>;
558
+ /**
559
+ * Called when the process is going to exit, this hook can only execute
560
+ * synchronous code.
561
+ */
562
+ onExit: PluginHook<OnExitFn>;
563
+ /**
564
+ * Modify assets before emitting, the same as Rspack's
565
+ * [compilation.hooks.processAssets](https://rspack.rs/api/plugin-api/compilation-hooks#processassets) hook.
566
+ */
567
+ processAssets: ProcessAssetsHook;
568
+ /**
569
+ * Intercept and modify module request information before module resolution begins.
570
+ * The same as Rspack's [normalModuleFactory.hooks.resolve](https://rspack.rs/api/plugin-api/normal-module-factory-hooks#resolve) hook.
571
+ */
572
+ resolve: ResolveHook;
573
+ /**
574
+ * A simplified wrapper around Rspack loaders, `api.transform` lets you
575
+ * easily transform the code of specific modules during the build process.
576
+ * You can match files by module path, query, or other conditions, and
577
+ * apply custom transformations to their contents.
578
+ */
579
+ transform: TransformHook;
580
+ /**
581
+ * Get the properties or methods exposed by other plugins.
582
+ */
583
+ useExposed: <T = any>(id: string | symbol) => T | undefined;
584
+ }>;
585
+ export {};