@ohos-ports/rsbuild-core 1.1.14-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 (244) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/bin/rsbuild.js +20 -0
  4. package/compiled/chokidar/index.d.ts +345 -0
  5. package/compiled/chokidar/index.js +1778 -0
  6. package/compiled/chokidar/license +21 -0
  7. package/compiled/chokidar/package.json +1 -0
  8. package/compiled/connect/index.d.ts +90 -0
  9. package/compiled/connect/index.js +1240 -0
  10. package/compiled/connect/license +25 -0
  11. package/compiled/connect/package.json +1 -0
  12. package/compiled/connect-history-api-fallback/index.d.ts +1 -0
  13. package/compiled/connect-history-api-fallback/index.js +149 -0
  14. package/compiled/connect-history-api-fallback/license +21 -0
  15. package/compiled/connect-history-api-fallback/package.json +1 -0
  16. package/compiled/cors/index.d.ts +1 -0
  17. package/compiled/cors/index.js +371 -0
  18. package/compiled/cors/license +22 -0
  19. package/compiled/cors/package.json +1 -0
  20. package/compiled/css-loader/api.js +85 -0
  21. package/compiled/css-loader/getUrl.js +26 -0
  22. package/compiled/css-loader/index.d.ts +1 -0
  23. package/compiled/css-loader/index.js +8008 -0
  24. package/compiled/css-loader/license +20 -0
  25. package/compiled/css-loader/noSourceMaps.js +5 -0
  26. package/compiled/css-loader/package.json +1 -0
  27. package/compiled/css-loader/sourceMaps.js +16 -0
  28. package/compiled/html-rspack-plugin/default_index.ejs +9 -0
  29. package/compiled/html-rspack-plugin/index.d.ts +289 -0
  30. package/compiled/html-rspack-plugin/index.js +1583 -0
  31. package/compiled/html-rspack-plugin/license +20 -0
  32. package/compiled/html-rspack-plugin/loader.js +162 -0
  33. package/compiled/html-rspack-plugin/package.json +1 -0
  34. package/compiled/http-proxy-middleware/index.d.ts +318 -0
  35. package/compiled/http-proxy-middleware/index.js +5280 -0
  36. package/compiled/http-proxy-middleware/license +22 -0
  37. package/compiled/http-proxy-middleware/package.json +1 -0
  38. package/compiled/jiti/index.d.ts +1 -0
  39. package/compiled/jiti/index.js +416 -0
  40. package/compiled/jiti/license +21 -0
  41. package/compiled/jiti/package.json +1 -0
  42. package/compiled/launch-editor-middleware/index.d.ts +1 -0
  43. package/compiled/launch-editor-middleware/index.js +694 -0
  44. package/compiled/launch-editor-middleware/license +21 -0
  45. package/compiled/launch-editor-middleware/package.json +1 -0
  46. package/compiled/mrmime/index.d.ts +4 -0
  47. package/compiled/mrmime/index.js +452 -0
  48. package/compiled/mrmime/package.json +1 -0
  49. package/compiled/on-finished/index.d.ts +13 -0
  50. package/compiled/on-finished/index.js +197 -0
  51. package/compiled/on-finished/license +23 -0
  52. package/compiled/on-finished/package.json +1 -0
  53. package/compiled/open/index.d.ts +153 -0
  54. package/compiled/open/index.js +409 -0
  55. package/compiled/open/package.json +1 -0
  56. package/compiled/open/xdg-open +1066 -0
  57. package/compiled/picocolors/index.d.ts +55 -0
  58. package/compiled/picocolors/index.js +108 -0
  59. package/compiled/picocolors/license +15 -0
  60. package/compiled/picocolors/package.json +1 -0
  61. package/compiled/postcss/index.d.ts +1 -0
  62. package/compiled/postcss/index.js +5997 -0
  63. package/compiled/postcss/license +20 -0
  64. package/compiled/postcss/package.json +1 -0
  65. package/compiled/postcss-load-config/index.d.ts +1 -0
  66. package/compiled/postcss-load-config/index.js +739 -0
  67. package/compiled/postcss-load-config/license +20 -0
  68. package/compiled/postcss-load-config/package.json +1 -0
  69. package/compiled/postcss-loader/index.d.ts +1 -0
  70. package/compiled/postcss-loader/index.js +741 -0
  71. package/compiled/postcss-loader/license +20 -0
  72. package/compiled/postcss-loader/package.json +1 -0
  73. package/compiled/rsbuild-dev-middleware/index.d.ts +1 -0
  74. package/compiled/rsbuild-dev-middleware/index.js +6158 -0
  75. package/compiled/rsbuild-dev-middleware/license +20 -0
  76. package/compiled/rsbuild-dev-middleware/package.json +1 -0
  77. package/compiled/rslog/index.d.ts +66 -0
  78. package/compiled/rslog/index.js +334 -0
  79. package/compiled/rslog/license +21 -0
  80. package/compiled/rslog/package.json +1 -0
  81. package/compiled/rspack-chain/index.d.ts +611 -0
  82. package/compiled/rspack-chain/index.js +1740 -0
  83. package/compiled/rspack-chain/license +373 -0
  84. package/compiled/rspack-chain/package.json +1 -0
  85. package/compiled/rspack-manifest-plugin/index.d.ts +44 -0
  86. package/compiled/rspack-manifest-plugin/index.js +394 -0
  87. package/compiled/rspack-manifest-plugin/license +21 -0
  88. package/compiled/rspack-manifest-plugin/package.json +1 -0
  89. package/compiled/sirv/index.d.ts +1 -0
  90. package/compiled/sirv/index.js +709 -0
  91. package/compiled/sirv/package.json +1 -0
  92. package/compiled/style-loader/index.d.ts +1 -0
  93. package/compiled/style-loader/index.js +427 -0
  94. package/compiled/style-loader/license +20 -0
  95. package/compiled/style-loader/package.json +1 -0
  96. package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
  97. package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
  98. package/compiled/style-loader/runtime/insertBySelector.js +34 -0
  99. package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
  100. package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
  101. package/compiled/style-loader/runtime/isOldIE.js +17 -0
  102. package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
  103. package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
  104. package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
  105. package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
  106. package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
  107. package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
  108. package/compiled/tinyglobby/index.d.ts +25 -0
  109. package/compiled/tinyglobby/index.js +2749 -0
  110. package/compiled/tinyglobby/index1.js +17 -0
  111. package/compiled/tinyglobby/license +21 -0
  112. package/compiled/tinyglobby/package.json +1 -0
  113. package/compiled/webpack-bundle-analyzer/index.d.ts +160 -0
  114. package/compiled/webpack-bundle-analyzer/index.js +13480 -0
  115. package/compiled/webpack-bundle-analyzer/license +20 -0
  116. package/compiled/webpack-bundle-analyzer/package.json +1 -0
  117. package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
  118. package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
  119. package/compiled/webpack-merge/index.d.ts +31 -0
  120. package/compiled/webpack-merge/index.js +1200 -0
  121. package/compiled/webpack-merge/license +20 -0
  122. package/compiled/webpack-merge/package.json +1 -0
  123. package/compiled/ws/index.d.ts +401 -0
  124. package/compiled/ws/index.js +3153 -0
  125. package/compiled/ws/license +20 -0
  126. package/compiled/ws/package.json +1 -0
  127. package/dist/client/hmr.js +143 -0
  128. package/dist/client/overlay.js +210 -0
  129. package/dist/ignoreCssLoader.mjs +4 -0
  130. package/dist/index.cjs +7251 -0
  131. package/dist/index.js +7118 -0
  132. package/dist/transformLoader.mjs +22 -0
  133. package/dist/transformRawLoader.mjs +22 -0
  134. package/dist-types/cli/commands.d.ts +23 -0
  135. package/dist-types/cli/index.d.ts +1 -0
  136. package/dist-types/cli/init.d.ts +7 -0
  137. package/dist-types/cli/prepare.d.ts +1 -0
  138. package/dist-types/client/hmr.d.ts +1 -0
  139. package/dist-types/client/overlay.d.ts +1 -0
  140. package/dist-types/config.d.ts +90 -0
  141. package/dist-types/configChain.d.ts +139 -0
  142. package/dist-types/constants.d.ts +37 -0
  143. package/dist-types/createContext.d.ts +11 -0
  144. package/dist-types/createRsbuild.d.ts +2 -0
  145. package/dist-types/helpers/format.d.ts +5 -0
  146. package/dist-types/helpers/fs.d.ts +13 -0
  147. package/dist-types/helpers/index.d.ts +47 -0
  148. package/dist-types/helpers/path.d.ts +11 -0
  149. package/dist-types/helpers/stats.d.ts +9 -0
  150. package/dist-types/hooks.d.ts +48 -0
  151. package/dist-types/index.d.ts +26 -0
  152. package/dist-types/initPlugins.d.ts +6 -0
  153. package/dist-types/internal.d.ts +6 -0
  154. package/dist-types/loadEnv.d.ts +50 -0
  155. package/dist-types/loader/ignoreCssLoader.d.ts +2 -0
  156. package/dist-types/loader/transformLoader.d.ts +7 -0
  157. package/dist-types/loader/transformRawLoader.d.ts +3 -0
  158. package/dist-types/logger.d.ts +4 -0
  159. package/dist-types/mergeConfig.d.ts +2 -0
  160. package/dist-types/package.json +1 -0
  161. package/dist-types/pluginHelper.d.ts +12 -0
  162. package/dist-types/pluginManager.d.ts +9 -0
  163. package/dist-types/plugins/appIcon.d.ts +2 -0
  164. package/dist-types/plugins/asset.d.ts +3 -0
  165. package/dist-types/plugins/basic.d.ts +5 -0
  166. package/dist-types/plugins/bundleAnalyzer.d.ts +2 -0
  167. package/dist-types/plugins/cache.d.ts +2 -0
  168. package/dist-types/plugins/cleanOutput.d.ts +3 -0
  169. package/dist-types/plugins/css.d.ts +3 -0
  170. package/dist-types/plugins/define.d.ts +2 -0
  171. package/dist-types/plugins/entry.d.ts +2 -0
  172. package/dist-types/plugins/externals.d.ts +2 -0
  173. package/dist-types/plugins/fileSize.d.ts +4 -0
  174. package/dist-types/plugins/html.d.ts +9 -0
  175. package/dist-types/plugins/inlineChunk.d.ts +2 -0
  176. package/dist-types/plugins/lazyCompilation.d.ts +2 -0
  177. package/dist-types/plugins/manifest.d.ts +2 -0
  178. package/dist-types/plugins/minimize.d.ts +10 -0
  179. package/dist-types/plugins/moduleFederation.d.ts +2 -0
  180. package/dist-types/plugins/moment.d.ts +2 -0
  181. package/dist-types/plugins/nodeAddons.d.ts +2 -0
  182. package/dist-types/plugins/nonce.d.ts +2 -0
  183. package/dist-types/plugins/output.d.ts +2 -0
  184. package/dist-types/plugins/performance.d.ts +5 -0
  185. package/dist-types/plugins/progress.d.ts +2 -0
  186. package/dist-types/plugins/resolve.d.ts +2 -0
  187. package/dist-types/plugins/resourceHints.d.ts +2 -0
  188. package/dist-types/plugins/rsdoctor.d.ts +2 -0
  189. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  190. package/dist-types/plugins/server.d.ts +2 -0
  191. package/dist-types/plugins/splitChunks.d.ts +4 -0
  192. package/dist-types/plugins/sri.d.ts +2 -0
  193. package/dist-types/plugins/swc.d.ts +7 -0
  194. package/dist-types/plugins/target.d.ts +2 -0
  195. package/dist-types/plugins/wasm.d.ts +2 -0
  196. package/dist-types/provider/build.d.ts +3 -0
  197. package/dist-types/provider/createCompiler.d.ts +27 -0
  198. package/dist-types/provider/helpers.d.ts +12 -0
  199. package/dist-types/provider/initConfigs.d.ts +10 -0
  200. package/dist-types/provider/inspectConfig.d.ts +6 -0
  201. package/dist-types/provider/provider.d.ts +2 -0
  202. package/dist-types/provider/rspackConfig.d.ts +8 -0
  203. package/dist-types/rspack/RsbuildHtmlPlugin.d.ts +37 -0
  204. package/dist-types/rspack/preload/HtmlPreloadOrPrefetchPlugin.d.ts +29 -0
  205. package/dist-types/rspack/preload/helpers/determineAsValue.d.ts +22 -0
  206. package/dist-types/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +29 -0
  207. package/dist-types/rspack/preload/helpers/extractChunks.d.ts +28 -0
  208. package/dist-types/rspack/preload/helpers/index.d.ts +4 -0
  209. package/dist-types/rspack/preload/helpers/type.d.ts +13 -0
  210. package/dist-types/server/ansiHTML.d.ts +12 -0
  211. package/dist-types/server/cliShortcuts.d.ts +10 -0
  212. package/dist-types/server/compilerDevMiddleware.d.ts +31 -0
  213. package/dist-types/server/devMiddleware.d.ts +27 -0
  214. package/dist-types/server/devServer.d.ts +60 -0
  215. package/dist-types/server/environment.d.ts +8 -0
  216. package/dist-types/server/getDevMiddlewares.d.ts +25 -0
  217. package/dist-types/server/gzipMiddleware.d.ts +4 -0
  218. package/dist-types/server/helper.d.ts +71 -0
  219. package/dist-types/server/httpServer.d.ts +8 -0
  220. package/dist-types/server/middlewares.d.ts +34 -0
  221. package/dist-types/server/open.d.ts +10 -0
  222. package/dist-types/server/prodServer.d.ts +25 -0
  223. package/dist-types/server/proxy.d.ts +6 -0
  224. package/dist-types/server/restart.d.ts +14 -0
  225. package/dist-types/server/runner/asModule.d.ts +2 -0
  226. package/dist-types/server/runner/basic.d.ts +25 -0
  227. package/dist-types/server/runner/cjs.d.ts +10 -0
  228. package/dist-types/server/runner/esm.d.ts +6 -0
  229. package/dist-types/server/runner/index.d.ts +8 -0
  230. package/dist-types/server/runner/type.d.ts +36 -0
  231. package/dist-types/server/socketServer.d.ts +26 -0
  232. package/dist-types/server/watchFiles.d.ts +14 -0
  233. package/dist-types/types/config.d.ts +1309 -0
  234. package/dist-types/types/context.d.ts +52 -0
  235. package/dist-types/types/hooks.d.ts +146 -0
  236. package/dist-types/types/index.d.ts +8 -0
  237. package/dist-types/types/plugin.d.ts +329 -0
  238. package/dist-types/types/rsbuild.d.ts +156 -0
  239. package/dist-types/types/rspack.d.ts +16 -0
  240. package/dist-types/types/thirdParty.d.ts +176 -0
  241. package/dist-types/types/utils.d.ts +12 -0
  242. package/package.json +61 -0
  243. package/static/openChrome.applescript +95 -0
  244. package/types.d.ts +221 -0
@@ -0,0 +1,52 @@
1
+ import type { Hooks } from '../hooks';
2
+ import type { NormalizedConfig, RsbuildConfig } from './config';
3
+ import type { EnvironmentContext } from './hooks';
4
+ import type { RsbuildPluginAPI } from './plugin';
5
+ export type BundlerType = 'rspack' | 'webpack';
6
+ /** The public context */
7
+ export type RsbuildContext = {
8
+ /** The Rsbuild core version. */
9
+ version: string;
10
+ /** The root path of current project. */
11
+ rootPath: string;
12
+ /** Absolute path of output files. */
13
+ distPath: string;
14
+ /** Absolute path of cache files. */
15
+ cachePath: string;
16
+ /** Info of dev server */
17
+ devServer?: {
18
+ hostname: string;
19
+ port: number;
20
+ https: boolean;
21
+ };
22
+ bundlerType: BundlerType;
23
+ };
24
+ /** The inner context. */
25
+ export type InternalContext = RsbuildContext & {
26
+ /** All hooks. */
27
+ hooks: Readonly<Hooks>;
28
+ /** Current Rsbuild config. */
29
+ config: Readonly<RsbuildConfig>;
30
+ /** The original Rsbuild config passed from the createRsbuild method. */
31
+ originalConfig: Readonly<RsbuildConfig>;
32
+ /** The normalized Rsbuild config. */
33
+ normalizedConfig?: NormalizedConfig;
34
+ /**
35
+ * Get the plugin API.
36
+ *
37
+ * When environment is undefined, the global plugin API is returned, which can be used in all environments.
38
+ * */
39
+ getPluginAPI?: (environment?: string) => RsbuildPluginAPI;
40
+ /** The environment context. */
41
+ environments: Record<string, EnvironmentContext>;
42
+ /** Only build specified environment. */
43
+ specifiedEnvironments?: string[];
44
+ /**
45
+ * The command type.
46
+ *
47
+ * - dev: `rsbuild dev` or `rsbuild.startDevServer()`
48
+ * - build: `rsbuild build` or `rsbuild.build()`
49
+ * - preview: `rsbuild preview` or `rsbuild.preview()`
50
+ */
51
+ command?: 'dev' | 'build' | 'preview';
52
+ };
@@ -0,0 +1,146 @@
1
+ import type { ChainIdentifier } from '..';
2
+ import type RspackChain from '../../compiled/rspack-chain/index.js';
3
+ import type { EnvironmentConfig, HtmlBasicTag, MergedEnvironmentConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
4
+ import type { RsbuildEntry, RsbuildTarget } from './rsbuild';
5
+ import type { Rspack } from './rspack';
6
+ import type { HtmlRspackPlugin, WebpackConfig } from './thirdParty';
7
+ import type { MaybePromise } from './utils';
8
+ type CompileCommonParams = {
9
+ isFirstCompile: boolean;
10
+ isWatch: boolean;
11
+ };
12
+ export type OnBeforeEnvironmentCompile<B = 'rspack'> = (params: CompileCommonParams & {
13
+ environment: EnvironmentContext;
14
+ bundlerConfig?: B extends 'rspack' ? Rspack.Configuration : WebpackConfig;
15
+ }) => MaybePromise<void>;
16
+ export type OnCloseBuildFn = () => MaybePromise<void>;
17
+ export type OnBeforeBuildFn<B = 'rspack'> = (params: CompileCommonParams & {
18
+ environments: Record<string, EnvironmentContext>;
19
+ bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : WebpackConfig[];
20
+ }) => MaybePromise<void>;
21
+ export type OnAfterEnvironmentCompileFn = (params: CompileCommonParams & {
22
+ stats?: Rspack.Stats;
23
+ environment: EnvironmentContext;
24
+ }) => MaybePromise<void>;
25
+ export type OnAfterBuildFn = (params: CompileCommonParams & {
26
+ stats?: Rspack.Stats | Rspack.MultiStats;
27
+ environments: Record<string, EnvironmentContext>;
28
+ }) => MaybePromise<void>;
29
+ export type OnCloseDevServerFn = () => MaybePromise<void>;
30
+ export type OnDevCompileDoneFn = (params: {
31
+ isFirstCompile: boolean;
32
+ stats: Rspack.Stats | Rspack.MultiStats;
33
+ environments: Record<string, EnvironmentContext>;
34
+ }) => MaybePromise<void>;
35
+ export type OnBeforeStartDevServerFn = (params: {
36
+ environments: Record<string, EnvironmentContext>;
37
+ }) => MaybePromise<void>;
38
+ export type OnBeforeStartProdServerFn = () => MaybePromise<void>;
39
+ export type Routes = Array<{
40
+ entryName: string;
41
+ pathname: string;
42
+ }>;
43
+ export type OnAfterStartDevServerFn = (params: {
44
+ port: number;
45
+ routes: Routes;
46
+ environments: Record<string, EnvironmentContext>;
47
+ }) => MaybePromise<void>;
48
+ export type OnAfterStartProdServerFn = (params: {
49
+ port: number;
50
+ routes: Routes;
51
+ environments: Record<string, EnvironmentContext>;
52
+ }) => MaybePromise<void>;
53
+ export type OnBeforeCreateCompilerFn<B = 'rspack'> = (params: {
54
+ bundlerConfigs: B extends 'rspack' ? Rspack.Configuration[] : WebpackConfig[];
55
+ environments: Record<string, EnvironmentContext>;
56
+ }) => MaybePromise<void>;
57
+ export type OnAfterCreateCompilerFn<Compiler = Rspack.Compiler | Rspack.MultiCompiler> = (params: {
58
+ compiler: Compiler;
59
+ environments: Record<string, EnvironmentContext>;
60
+ }) => MaybePromise<void>;
61
+ export type OnExitFn = () => void;
62
+ type HTMLTags = {
63
+ headTags: HtmlBasicTag[];
64
+ bodyTags: HtmlBasicTag[];
65
+ };
66
+ export type ModifyHTMLTagsContext = {
67
+ /**
68
+ * The Compilation object of Rspack.
69
+ */
70
+ compilation: Rspack.Compilation;
71
+ /**
72
+ * The Compiler object of Rspack.
73
+ */
74
+ compiler: Rspack.Compiler;
75
+ /**
76
+ * URL prefix of assets.
77
+ * @example 'https://example.com/'
78
+ */
79
+ assetPrefix: string;
80
+ /**
81
+ * The name of the HTML file, relative to the dist directory.
82
+ * @example 'index.html'
83
+ */
84
+ filename: string;
85
+ /**
86
+ * The environment context for current build.
87
+ */
88
+ environment: EnvironmentContext;
89
+ };
90
+ export type ModifyHTMLTagsFn = (tags: HTMLTags, context: ModifyHTMLTagsContext) => MaybePromise<HTMLTags>;
91
+ export type ModifyRsbuildConfigUtils = {
92
+ /** Merge multiple Rsbuild config objects into one. */
93
+ mergeRsbuildConfig: (...configs: RsbuildConfig[]) => RsbuildConfig;
94
+ };
95
+ type ArrayAtLeastOne<A, B> = [A, ...Array<A | B>] | [...Array<A | B>, A];
96
+ export type ModifyEnvironmentConfigUtils = {
97
+ /** environment name. */
98
+ name: string;
99
+ /** Merge multiple Rsbuild environment config objects into one. */
100
+ mergeEnvironmentConfig: (...configs: ArrayAtLeastOne<MergedEnvironmentConfig, EnvironmentConfig>) => MergedEnvironmentConfig;
101
+ };
102
+ export type ModifyRsbuildConfigFn = (config: RsbuildConfig, utils: ModifyRsbuildConfigUtils) => MaybePromise<RsbuildConfig | void>;
103
+ export type ModifyEnvironmentConfigFn = (config: MergedEnvironmentConfig, utils: ModifyEnvironmentConfigUtils) => MaybePromise<MergedEnvironmentConfig | void>;
104
+ export type EnvironmentContext = {
105
+ index: number;
106
+ name: string;
107
+ entry: RsbuildEntry;
108
+ htmlPaths: Record<string, string>;
109
+ distPath: string;
110
+ browserslist: string[];
111
+ tsconfigPath?: string;
112
+ config: NormalizedEnvironmentConfig;
113
+ };
114
+ export type ModifyChainUtils = {
115
+ /**
116
+ * The value of `process.env.NODE_ENV`
117
+ */
118
+ env: string;
119
+ isDev: boolean;
120
+ isProd: boolean;
121
+ target: RsbuildTarget;
122
+ isServer: boolean;
123
+ isWebWorker: boolean;
124
+ CHAIN_ID: ChainIdentifier;
125
+ environment: EnvironmentContext;
126
+ HtmlPlugin: typeof HtmlRspackPlugin;
127
+ };
128
+ interface PluginInstance {
129
+ apply: (compiler: any) => void;
130
+ [k: string]: any;
131
+ }
132
+ export type ModifyBundlerChainUtils = ModifyChainUtils & {
133
+ bundler: {
134
+ BannerPlugin: PluginInstance;
135
+ DefinePlugin: PluginInstance;
136
+ IgnorePlugin: PluginInstance;
137
+ ProvidePlugin: PluginInstance;
138
+ HotModuleReplacementPlugin: PluginInstance;
139
+ };
140
+ };
141
+ export type ModifyBundlerChainFn = (chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>;
142
+ export type CreateAsyncHook<Callback extends (...args: any[]) => any> = {
143
+ tap: (cb: Callback) => void;
144
+ call: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
145
+ };
146
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './rspack';
2
+ export * from './rsbuild';
3
+ export * from './context';
4
+ export * from './utils';
5
+ export * from './plugin';
6
+ export * from './config';
7
+ export * from './hooks';
8
+ export * from './thirdParty';
@@ -0,0 +1,329 @@
1
+ import type { RuleSetRule, Configuration as WebpackConfig, WebpackPluginInstance } from 'webpack';
2
+ import type RspackChain from '../../compiled/rspack-chain/index.js';
3
+ import type { ChainIdentifier } from '../configChain';
4
+ import type { ModifyRspackConfigUtils, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
5
+ import type { RsbuildContext } from './context';
6
+ import type { EnvironmentContext, ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeEnvironmentCompile, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
7
+ import type { RsbuildTarget } from './rsbuild';
8
+ import type { Rspack } from './rspack';
9
+ import type { HtmlRspackPlugin } from './thirdParty';
10
+ import type { Falsy } from './utils';
11
+ import type { 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[]) => any> = {
18
+ tapEnvironment: (params: {
19
+ /**
20
+ * Specify that the callback will only be executed under the specified environment
21
+ */
22
+ environment?: string;
23
+ handler: Callback | HookDescriptor<Callback>;
24
+ }) => void;
25
+ /**
26
+ * Triggered in all environments by default.
27
+ * If you need to specify the environment, please use `tapEnvironment`
28
+ */
29
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
30
+ callInEnvironment: (params: {
31
+ environment?: string;
32
+ args: Parameters<Callback>;
33
+ }) => Promise<Parameters<Callback>>;
34
+ };
35
+ export type AsyncHook<Callback extends (...args: any[]) => any> = {
36
+ tap: (cb: Callback | HookDescriptor<Callback>) => void;
37
+ call: (...args: Parameters<Callback>) => Promise<Parameters<Callback>>;
38
+ };
39
+ export type ModifyRspackConfigFn = (config: Rspack.Configuration, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
40
+ export type ModifyWebpackChainUtils = ModifyChainUtils & {
41
+ webpack: typeof import('webpack');
42
+ CHAIN_ID: ChainIdentifier;
43
+ /**
44
+ * @deprecated Use target instead.
45
+ * */
46
+ name: string;
47
+ /**
48
+ * @deprecated Use HtmlPlugin instead.
49
+ */
50
+ HtmlWebpackPlugin: typeof HtmlRspackPlugin;
51
+ };
52
+ export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
53
+ addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
54
+ appendRules: (rules: RuleSetRule | RuleSetRule[]) => void;
55
+ prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
56
+ appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
57
+ removePlugin: (pluginName: string) => void;
58
+ mergeConfig: typeof import('../../compiled/webpack-merge/index.js').merge;
59
+ };
60
+ export type ModifyWebpackChainFn = (chain: RspackChain, utils: ModifyWebpackChainUtils) => Promise<void> | void;
61
+ export type ModifyWebpackConfigFn = (config: WebpackConfig, utils: ModifyWebpackConfigUtils) => Promise<WebpackConfig | void> | WebpackConfig | void;
62
+ export type PluginMeta = {
63
+ environment: string;
64
+ instance: RsbuildPlugin;
65
+ };
66
+ export type PluginManager = {
67
+ getPlugins: (options?: {
68
+ /**
69
+ * Get the plugins in the specified environment.
70
+ *
71
+ * If environment is not specified, get the global plugins.
72
+ */
73
+ environment: string;
74
+ }) => RsbuildPlugin[];
75
+ addPlugins: (plugins: Array<RsbuildPlugin | Falsy>, options?: {
76
+ /**
77
+ * Insert before the specified plugin.
78
+ */
79
+ before?: string;
80
+ /**
81
+ * Add a plugin for the specified environment.
82
+ * If environment is not specified, it will be registered as a global plugin (effective in all environments)
83
+ */
84
+ environment?: string;
85
+ }) => void;
86
+ removePlugins: (pluginNames: string[], options?: {
87
+ /**
88
+ * Remove the plugin in the specified environment.
89
+ *
90
+ * If environment is not specified, remove it in all environments.
91
+ */
92
+ environment: string;
93
+ }) => void;
94
+ isPluginExists: (pluginName: string, options?: {
95
+ /**
96
+ * Whether it exists in the specified environment.
97
+ *
98
+ * If environment is not specified, determine whether the plugin is a global plugin.
99
+ */
100
+ environment: string;
101
+ }) => boolean;
102
+ /** Get all plugins with environment info */
103
+ getAllPluginsWithMeta: () => PluginMeta[];
104
+ };
105
+ /**
106
+ * The type of the Rsbuild plugin object.
107
+ */
108
+ export type RsbuildPlugin = {
109
+ /**
110
+ * The name of the plugin, a unique identifier.
111
+ */
112
+ name: string;
113
+ /**
114
+ * The setup function of the plugin, which can be an async function.
115
+ * This function is called once when the plugin is initialized.
116
+ * @param api provides the context info, utility functions and lifecycle hooks.
117
+ */
118
+ setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
119
+ /**
120
+ * Declare the names of pre-plugins, which will be executed before the current plugin.
121
+ */
122
+ pre?: string[];
123
+ /**
124
+ * Declare the names of post-plugins, which will be executed after the current plugin.
125
+ */
126
+ post?: string[];
127
+ /**
128
+ * Declare the plugins that need to be removed, you can pass an array of plugin names.
129
+ */
130
+ remove?: string[];
131
+ };
132
+ type LooseRsbuildPlugin = Omit<RsbuildPlugin, 'setup'> & {
133
+ setup: (api: any) => MaybePromise<void>;
134
+ };
135
+ export type RsbuildPlugins = (LooseRsbuildPlugin | Falsy | Promise<LooseRsbuildPlugin | Falsy | RsbuildPlugins> | RsbuildPlugins)[];
136
+ export type GetRsbuildConfig = {
137
+ (): Readonly<RsbuildConfig>;
138
+ (type: 'original' | 'current'): Readonly<RsbuildConfig>;
139
+ (type: 'normalized'): NormalizedConfig;
140
+ };
141
+ type PluginHook<T extends (...args: any[]) => any> = (options: T | HookDescriptor<T>) => void;
142
+ type TransformResult = string | {
143
+ code: string;
144
+ map?: string | Rspack.sources.RawSourceMap | null;
145
+ };
146
+ export type TransformContext = {
147
+ /**
148
+ * The code of the module.
149
+ */
150
+ code: string;
151
+ /**
152
+ * The absolute path of the module, including the query.
153
+ * @example '/home/user/project/src/index.js?foo=123'
154
+ */
155
+ resource: string;
156
+ /**
157
+ * The absolute path of the module, without the query.
158
+ * @example '/home/user/project/src/index.js'
159
+ */
160
+ resourcePath: string;
161
+ /**
162
+ * The query of the module.
163
+ * @example '?foo=123'
164
+ */
165
+ resourceQuery: string;
166
+ /**
167
+ * The environment context for current build.
168
+ */
169
+ environment: EnvironmentContext;
170
+ /**
171
+ * Add an additional file as the dependency.
172
+ * The file will be watched and changes to the file will trigger rebuild.
173
+ * @param file The absolute path of the module
174
+ */
175
+ addDependency: (file: string) => void;
176
+ /**
177
+ * Emits a file to the build output.
178
+ * @param name file name of the asset
179
+ * @param content the source of the asset
180
+ * @param sourceMap source map of the asset
181
+ * @param assetInfo additional asset information
182
+ */
183
+ emitFile: Rspack.LoaderContext['emitFile'];
184
+ /**
185
+ * Compile and execute a module at the build time.
186
+ */
187
+ importModule: Rspack.LoaderContext['importModule'];
188
+ };
189
+ export type TransformHandler = (context: TransformContext) => MaybePromise<TransformResult>;
190
+ export type TransformDescriptor = {
191
+ /**
192
+ * Include modules that match the test assertion, the same as `rule.test`
193
+ * @see https://rspack.dev/config/module#ruletest
194
+ */
195
+ test?: Rspack.RuleSetCondition;
196
+ /**
197
+ * A condition that matches the resource query.
198
+ * @see https://rspack.dev/config/module#ruleresourcequery
199
+ */
200
+ resourceQuery?: Rspack.RuleSetCondition;
201
+ /**
202
+ * Match based on the Rsbuild targets and only apply the transform to
203
+ * certain targets.
204
+ * @see https://rsbuild.dev/config/output/target
205
+ */
206
+ targets?: RsbuildTarget[];
207
+ /**
208
+ * Match based on the Rsbuild environment names and only apply the transform
209
+ * to certain environments.
210
+ * @see https://rsbuild.dev/config/environments
211
+ */
212
+ environments?: string[];
213
+ /**
214
+ * If raw is `true`, the transform handler will receive the Buffer type code
215
+ * instead of the string type.
216
+ * @see https://rspack.dev/api/loader-api/examples#raw-loader
217
+ */
218
+ raw?: boolean;
219
+ /**
220
+ * Used to mark the layer of the matching module.
221
+ * A group of modules could be united in one layer which could then be used in
222
+ * split chunks, stats or entry options.
223
+ * @see https://rspack.dev/config/module#rulelayer
224
+ */
225
+ layer?: string;
226
+ /**
227
+ * Matches all modules that match this resource, and will match against layer of
228
+ * the module that issued the current module.
229
+ * @see https://rspack.dev/config/module#ruleissuerlayer
230
+ */
231
+ issuerLayer?: string;
232
+ };
233
+ export type TransformFn = (descriptor: TransformDescriptor, handler: TransformHandler) => void;
234
+ 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';
235
+ export type ProcessAssetsDescriptor = {
236
+ /**
237
+ * Specifies the order in which your asset processing logic should run relative to other plugins.
238
+ */
239
+ stage: ProcessAssetsStage;
240
+ /**
241
+ * Match based on the Rsbuild targets and only process the assets of certain targets.
242
+ * @see https://rsbuild.dev/config/output/target
243
+ */
244
+ targets?: RsbuildTarget[];
245
+ /**
246
+ * Match based on the Rsbuild environment names and only process the assets of certain environments.
247
+ * @see https://rsbuild.dev/config/environments
248
+ */
249
+ environments?: string[];
250
+ };
251
+ export type RspackSources = Pick<typeof Rspack.sources, 'Source' | 'RawSource' | 'OriginalSource' | 'SourceMapSource' | 'CachedSource' | 'ConcatSource' | 'ReplaceSource' | 'PrefixSource' | 'SizeOnlySource' | 'CompatSource'>;
252
+ export type ProcessAssetsHandler = (context: {
253
+ assets: Record<string, Rspack.sources.Source>;
254
+ compiler: Rspack.Compiler;
255
+ compilation: Rspack.Compilation;
256
+ /**
257
+ * The environment context for current build.
258
+ */
259
+ environment: EnvironmentContext;
260
+ /**
261
+ * Contains multiple classes which represent an Rspack `Source`.
262
+ */
263
+ sources: RspackSources;
264
+ }) => Promise<void> | void;
265
+ export type ResolveHandler = (context: {
266
+ /** Module request information */
267
+ resolveData: Rspack.ResolveData;
268
+ /** The environment context for current build. */
269
+ environment: EnvironmentContext;
270
+ compiler: Rspack.Compiler;
271
+ compilation: Rspack.Compilation;
272
+ }) => Promise<void> | void;
273
+ export type ResolveFn = (handler: ResolveHandler) => void;
274
+ export type ProcessAssetsFn = (descriptor: ProcessAssetsDescriptor, handler: ProcessAssetsHandler) => void;
275
+ declare function getNormalizedConfig(): NormalizedConfig;
276
+ declare function getNormalizedConfig(options: {
277
+ environment: string;
278
+ }): NormalizedEnvironmentConfig;
279
+ /**
280
+ * Define a generic Rsbuild plugin API that provider can extend as needed.
281
+ */
282
+ export type RsbuildPluginAPI = Readonly<{
283
+ context: Readonly<RsbuildContext>;
284
+ isPluginExists: PluginManager['isPluginExists'];
285
+ onExit: PluginHook<OnExitFn>;
286
+ onCloseBuild: PluginHook<OnCloseBuildFn>;
287
+ onAfterBuild: PluginHook<OnAfterBuildFn>;
288
+ onBeforeBuild: PluginHook<OnBeforeBuildFn>;
289
+ onAfterEnvironmentCompile: PluginHook<OnAfterEnvironmentCompileFn>;
290
+ onBeforeEnvironmentCompile: PluginHook<OnBeforeEnvironmentCompile>;
291
+ onCloseDevServer: PluginHook<OnCloseDevServerFn>;
292
+ onDevCompileDone: PluginHook<OnDevCompileDoneFn>;
293
+ onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
294
+ onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
295
+ onAfterStartProdServer: PluginHook<OnAfterStartProdServerFn>;
296
+ onBeforeStartProdServer: PluginHook<OnBeforeStartProdServerFn>;
297
+ onAfterCreateCompiler: PluginHook<OnAfterCreateCompilerFn>;
298
+ onBeforeCreateCompiler: PluginHook<OnBeforeCreateCompilerFn>;
299
+ modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
300
+ modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
301
+ modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
302
+ modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
303
+ /** Only works when bundler is Rspack */
304
+ modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
305
+ /** Only works when bundler is Webpack */
306
+ modifyWebpackChain: PluginHook<ModifyWebpackChainFn>;
307
+ /** Only works when bundler is Webpack */
308
+ modifyWebpackConfig: PluginHook<ModifyWebpackConfigFn>;
309
+ getRsbuildConfig: GetRsbuildConfig;
310
+ getNormalizedConfig: typeof getNormalizedConfig;
311
+ /**
312
+ * For plugin communication
313
+ */
314
+ expose: <T = any>(id: string | symbol, api: T) => void;
315
+ useExposed: <T = any>(id: string | symbol) => T | undefined;
316
+ /**
317
+ * Used to transform the code of modules.
318
+ */
319
+ transform: TransformFn;
320
+ /**
321
+ * Process all the asset generated by Rspack.
322
+ */
323
+ processAssets: ProcessAssetsFn;
324
+ /**
325
+ * Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies.
326
+ */
327
+ resolve: ResolveFn;
328
+ }>;
329
+ export {};