@ohos-ports/rsbuild-core 2.2.9-beta.0

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 (269) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -0
  3. package/bin/rsbuild.js +20 -0
  4. package/compiled/@rstackjs/load-config/index.d.ts +87 -0
  5. package/compiled/@rstackjs/load-config/license +21 -0
  6. package/compiled/@rstackjs/load-config/package.json +1 -0
  7. package/compiled/chokidar/index.d.ts +385 -0
  8. package/compiled/chokidar/license +21 -0
  9. package/compiled/chokidar/package.json +1 -0
  10. package/compiled/connect-next/index.d.ts +57 -0
  11. package/compiled/connect-next/license +26 -0
  12. package/compiled/connect-next/package.json +1 -0
  13. package/compiled/cors/index.d.ts +56 -0
  14. package/compiled/cors/license +22 -0
  15. package/compiled/cors/package.json +1 -0
  16. package/compiled/css-loader/api.js +85 -0
  17. package/compiled/css-loader/getUrl.js +26 -0
  18. package/compiled/css-loader/index.d.ts +1 -0
  19. package/compiled/css-loader/index.js +2 -0
  20. package/compiled/css-loader/license +20 -0
  21. package/compiled/css-loader/noSourceMaps.js +5 -0
  22. package/compiled/css-loader/package.json +1 -0
  23. package/compiled/css-loader/sourceMaps.js +16 -0
  24. package/compiled/html-rspack-plugin/default_index.ejs +9 -0
  25. package/compiled/html-rspack-plugin/htmlLoader.js +157 -0
  26. package/compiled/html-rspack-plugin/index.d.ts +395 -0
  27. package/compiled/html-rspack-plugin/index.js +2400 -0
  28. package/compiled/html-rspack-plugin/license +20 -0
  29. package/compiled/html-rspack-plugin/package.json +1 -0
  30. package/compiled/http-proxy-middleware/index.d.ts +455 -0
  31. package/compiled/http-proxy-middleware/license +22 -0
  32. package/compiled/http-proxy-middleware/package.json +1 -0
  33. package/compiled/jiti/LICENSE +21 -0
  34. package/compiled/jiti/README.md +258 -0
  35. package/compiled/jiti/dist/babel.cjs +47446 -0
  36. package/compiled/jiti/dist/jiti.cjs +5990 -0
  37. package/compiled/jiti/lib/jiti-cli.mjs +19 -0
  38. package/compiled/jiti/lib/jiti-hooks.mjs +89 -0
  39. package/compiled/jiti/lib/jiti-native.mjs +76 -0
  40. package/compiled/jiti/lib/jiti-register.d.mts +1 -0
  41. package/compiled/jiti/lib/jiti-register.mjs +2 -0
  42. package/compiled/jiti/lib/jiti-static.mjs +19 -0
  43. package/compiled/jiti/lib/jiti.cjs +24 -0
  44. package/compiled/jiti/lib/jiti.d.cts +8 -0
  45. package/compiled/jiti/lib/jiti.d.mts +8 -0
  46. package/compiled/jiti/lib/jiti.mjs +23 -0
  47. package/compiled/jiti/lib/types.d.ts +420 -0
  48. package/compiled/jiti/package.json +146 -0
  49. package/compiled/postcss/index.js +1 -0
  50. package/compiled/postcss/lib/at-rule.d.ts +139 -0
  51. package/compiled/postcss/lib/comment.d.ts +67 -0
  52. package/compiled/postcss/lib/container.d.ts +474 -0
  53. package/compiled/postcss/lib/css-syntax-error.d.ts +247 -0
  54. package/compiled/postcss/lib/declaration.d.ts +150 -0
  55. package/compiled/postcss/lib/document.d.ts +68 -0
  56. package/compiled/postcss/lib/fromJSON.d.ts +9 -0
  57. package/compiled/postcss/lib/input.d.ts +226 -0
  58. package/compiled/postcss/lib/lazy-result.d.ts +189 -0
  59. package/compiled/postcss/lib/list.d.ts +60 -0
  60. package/compiled/postcss/lib/no-work-result.d.ts +45 -0
  61. package/compiled/postcss/lib/node.d.ts +555 -0
  62. package/compiled/postcss/lib/parse.d.ts +9 -0
  63. package/compiled/postcss/lib/postcss.d.ts +464 -0
  64. package/compiled/postcss/lib/previous-map.d.ts +80 -0
  65. package/compiled/postcss/lib/processor.d.ts +114 -0
  66. package/compiled/postcss/lib/result.d.ts +204 -0
  67. package/compiled/postcss/lib/root.d.ts +86 -0
  68. package/compiled/postcss/lib/rule.d.ts +126 -0
  69. package/compiled/postcss/lib/source-map-js.d.ts +4 -0
  70. package/compiled/postcss/lib/stringifier.d.ts +45 -0
  71. package/compiled/postcss/lib/stringify.d.ts +9 -0
  72. package/compiled/postcss/lib/warning.d.ts +146 -0
  73. package/compiled/postcss/license +20 -0
  74. package/compiled/postcss/package.json +1 -0
  75. package/compiled/postcss-loader/index.d.ts +1 -0
  76. package/compiled/postcss-loader/index.js +721 -0
  77. package/compiled/postcss-loader/license +20 -0
  78. package/compiled/postcss-loader/package.json +1 -0
  79. package/compiled/rslog/index.d.ts +98 -0
  80. package/compiled/rslog/license +21 -0
  81. package/compiled/rslog/package.json +1 -0
  82. package/compiled/rspack-chain/license +22 -0
  83. package/compiled/rspack-chain/package.json +1 -0
  84. package/compiled/rspack-chain/types/index.d.ts +515 -0
  85. package/compiled/rspack-manifest-plugin/index.d.ts +52 -0
  86. package/compiled/rspack-manifest-plugin/license +21 -0
  87. package/compiled/rspack-manifest-plugin/package.json +1 -0
  88. package/compiled/style-loader/index.d.ts +1 -0
  89. package/compiled/style-loader/index.js +370 -0
  90. package/compiled/style-loader/license +20 -0
  91. package/compiled/style-loader/package.json +1 -0
  92. package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
  93. package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
  94. package/compiled/style-loader/runtime/insertBySelector.js +34 -0
  95. package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
  96. package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
  97. package/compiled/style-loader/runtime/isOldIE.js +17 -0
  98. package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
  99. package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
  100. package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
  101. package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
  102. package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
  103. package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
  104. package/compiled/ws/index.d.ts +445 -0
  105. package/compiled/ws/license +21 -0
  106. package/compiled/ws/package.json +1 -0
  107. package/dist/build.d.ts +4 -0
  108. package/dist/c.js +10 -0
  109. package/dist/chokidar.js +2 -0
  110. package/dist/chokidar.js.LICENSE.txt +1 -0
  111. package/dist/cli/commands.d.ts +31 -0
  112. package/dist/cli/index.d.ts +7 -0
  113. package/dist/cli/init.d.ts +7 -0
  114. package/dist/client/f~0.js +22 -0
  115. package/dist/client/hmr.js +267 -0
  116. package/dist/client/overlay.js +214 -0
  117. package/dist/configChain.d.ts +84 -0
  118. package/dist/connect-next.js +2 -0
  119. package/dist/connect-next.js.LICENSE.txt +57 -0
  120. package/dist/constants.d.ts +67 -0
  121. package/dist/cors.js +188 -0
  122. package/dist/cors.js.LICENSE.txt +11 -0
  123. package/dist/createCompiler.d.ts +6 -0
  124. package/dist/createContext.d.ts +12 -0
  125. package/dist/createRsbuild.d.ts +4 -0
  126. package/dist/cssUrlLoader.mjs +34 -0
  127. package/dist/defaultConfig.d.ts +23 -0
  128. package/dist/freshImport.js +90 -0
  129. package/dist/helpers/cachedImport.d.ts +2 -0
  130. package/dist/helpers/compiler.d.ts +5 -0
  131. package/dist/helpers/css.d.ts +3 -0
  132. package/dist/helpers/exitHook.d.ts +3 -0
  133. package/dist/helpers/format.d.ts +4 -0
  134. package/dist/helpers/fs.d.ts +16 -0
  135. package/dist/helpers/html.d.ts +2 -0
  136. package/dist/helpers/index.d.ts +29 -0
  137. package/dist/helpers/overlayConfig.d.ts +4 -0
  138. package/dist/helpers/packageJson.d.ts +9 -0
  139. package/dist/helpers/path.d.ts +22 -0
  140. package/dist/helpers/restartManager.d.ts +15 -0
  141. package/dist/helpers/stats.d.ts +17 -0
  142. package/dist/helpers/url.d.ts +11 -0
  143. package/dist/helpers/vendors.d.ts +12 -0
  144. package/dist/helpers/version.d.ts +7 -0
  145. package/dist/hooks.d.ts +41 -0
  146. package/dist/http-proxy-middleware.js +14 -0
  147. package/dist/http-proxy-middleware.js.LICENSE.txt +34 -0
  148. package/dist/ignoreCssLoader.mjs +9 -0
  149. package/dist/index.d.ts +28 -0
  150. package/dist/index.js +1 -0
  151. package/dist/initConfigs.d.ts +18 -0
  152. package/dist/initPlugins.d.ts +7 -0
  153. package/dist/inspectConfig.d.ts +7 -0
  154. package/dist/launch-editor-middleware.js +1 -0
  155. package/dist/loadConfig.d.ts +31 -0
  156. package/dist/loadEnv.d.ts +54 -0
  157. package/dist/loader/cssUrlLoader.d.ts +9 -0
  158. package/dist/loader/ignoreCssLoader.d.ts +10 -0
  159. package/dist/loader/transformLoader.d.ts +8 -0
  160. package/dist/loader/transformRawLoader.d.ts +4 -0
  161. package/dist/loader/workerLoader.d.ts +6 -0
  162. package/dist/logger.d.ts +24 -0
  163. package/dist/m.js +10348 -0
  164. package/dist/m.js.LICENSE.txt +26 -0
  165. package/dist/manifest-plugin.js +1 -0
  166. package/dist/memfs.js +1 -0
  167. package/dist/mergeConfig.d.ts +7 -0
  168. package/dist/open.js +2 -0
  169. package/dist/pluginHelper.d.ts +4 -0
  170. package/dist/pluginManager.d.ts +19 -0
  171. package/dist/plugins/appIcon.d.ts +2 -0
  172. package/dist/plugins/asset.d.ts +3 -0
  173. package/dist/plugins/basic.d.ts +4 -0
  174. package/dist/plugins/cache.d.ts +2 -0
  175. package/dist/plugins/cleanOutput.d.ts +2 -0
  176. package/dist/plugins/css.d.ts +8 -0
  177. package/dist/plugins/define.d.ts +2 -0
  178. package/dist/plugins/entry.d.ts +2 -0
  179. package/dist/plugins/externals.d.ts +9 -0
  180. package/dist/plugins/fileSize.d.ts +7 -0
  181. package/dist/plugins/html.d.ts +9 -0
  182. package/dist/plugins/inlineChunk.d.ts +6 -0
  183. package/dist/plugins/lazyCompilation.d.ts +2 -0
  184. package/dist/plugins/manifest.d.ts +2 -0
  185. package/dist/plugins/minimize.d.ts +10 -0
  186. package/dist/plugins/moduleFederation.d.ts +2 -0
  187. package/dist/plugins/nodeAddons.d.ts +2 -0
  188. package/dist/plugins/nonce.d.ts +2 -0
  189. package/dist/plugins/output.d.ts +2 -0
  190. package/dist/plugins/progress.d.ts +2 -0
  191. package/dist/plugins/resolve.d.ts +2 -0
  192. package/dist/plugins/resourceHints.d.ts +2 -0
  193. package/dist/plugins/rsdoctor.d.ts +2 -0
  194. package/dist/plugins/rspackProfile.d.ts +4 -0
  195. package/dist/plugins/server.d.ts +3 -0
  196. package/dist/plugins/sourceMap.d.ts +2 -0
  197. package/dist/plugins/splitChunks.d.ts +4 -0
  198. package/dist/plugins/sri.d.ts +2 -0
  199. package/dist/plugins/swc.d.ts +4 -0
  200. package/dist/plugins/target.d.ts +2 -0
  201. package/dist/plugins/wasm.d.ts +2 -0
  202. package/dist/plugins/worker.d.ts +2 -0
  203. package/dist/r.js +7 -0
  204. package/dist/range-parser.js +55 -0
  205. package/dist/range-parser.js.LICENSE.txt +6 -0
  206. package/dist/remapping.js +201 -0
  207. package/dist/restart.d.ts +15 -0
  208. package/dist/rslib-runtime.js +49 -0
  209. package/dist/rspack-plugins/RsbuildHtmlPlugin.d.ts +37 -0
  210. package/dist/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +36 -0
  211. package/dist/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +27 -0
  212. package/dist/rspack-plugins/resource-hints/extractChunks.d.ts +22 -0
  213. package/dist/rspack-plugins/resource-hints/getResourceType.d.ts +21 -0
  214. package/dist/rspackConfig.d.ts +8 -0
  215. package/dist/server/ansiHTML.d.ts +3 -0
  216. package/dist/server/assets-middleware/getFileFromUrl.d.ts +11 -0
  217. package/dist/server/assets-middleware/index.d.ts +35 -0
  218. package/dist/server/assets-middleware/memoryFileSystem.d.ts +2 -0
  219. package/dist/server/assets-middleware/middleware.d.ts +7 -0
  220. package/dist/server/assets-middleware/parseTokenList.d.ts +1 -0
  221. package/dist/server/assets-middleware/setupOutputFileSystem.d.ts +3 -0
  222. package/dist/server/assets-middleware/setupWriteToDisk.d.ts +15 -0
  223. package/dist/server/browserLogs.d.ts +8 -0
  224. package/dist/server/buildManager.d.ts +32 -0
  225. package/dist/server/cliShortcuts.d.ts +19 -0
  226. package/dist/server/compileState.d.ts +5 -0
  227. package/dist/server/devMiddlewares.d.ts +18 -0
  228. package/dist/server/devServer.d.ts +47 -0
  229. package/dist/server/environment.d.ts +8 -0
  230. package/dist/server/gracefulShutdown.d.ts +8 -0
  231. package/dist/server/gzipMiddleware.d.ts +2 -0
  232. package/dist/server/helper.d.ts +118 -0
  233. package/dist/server/historyApiFallback.d.ts +10 -0
  234. package/dist/server/hmrFallback.d.ts +1 -0
  235. package/dist/server/httpServer.d.ts +7 -0
  236. package/dist/server/middlewares.d.ts +31 -0
  237. package/dist/server/open.d.ts +12 -0
  238. package/dist/server/overlay.d.ts +3 -0
  239. package/dist/server/previewServer.d.ts +4 -0
  240. package/dist/server/proxy.d.ts +7 -0
  241. package/dist/server/publicPathnames.d.ts +2 -0
  242. package/dist/server/runner/asModule.d.ts +2 -0
  243. package/dist/server/runner/basic.d.ts +25 -0
  244. package/dist/server/runner/cjs.d.ts +10 -0
  245. package/dist/server/runner/esm.d.ts +6 -0
  246. package/dist/server/runner/index.d.ts +6 -0
  247. package/dist/server/runner/type.d.ts +42 -0
  248. package/dist/server/serverSetup.d.ts +2 -0
  249. package/dist/server/socketServer.d.ts +113 -0
  250. package/dist/server/watchFiles.d.ts +15 -0
  251. package/dist/sirv.js +122 -0
  252. package/dist/tinyglobby.js +1 -0
  253. package/dist/trace-mapping.js +548 -0
  254. package/dist/transformLoader.mjs +36 -0
  255. package/dist/transformRawLoader.mjs +4 -0
  256. package/dist/types/config.d.ts +1796 -0
  257. package/dist/types/context.d.ts +89 -0
  258. package/dist/types/hooks.d.ts +261 -0
  259. package/dist/types/index.d.ts +8 -0
  260. package/dist/types/plugin.d.ts +479 -0
  261. package/dist/types/rsbuild.d.ts +241 -0
  262. package/dist/types/rspack.d.ts +10 -0
  263. package/dist/types/thirdParty.d.ts +161 -0
  264. package/dist/types/utils.d.ts +16 -0
  265. package/dist/workerLoader.mjs +94 -0
  266. package/dist/ws.js +2 -0
  267. package/package.json +107 -0
  268. package/static/openChrome.applescript +95 -0
  269. package/types.d.ts +422 -0
@@ -0,0 +1,241 @@
1
+ import type { Compiler, MultiCompiler } from '@rspack/core';
2
+ import type { LoadConfigResult } from '../loadConfig.js';
3
+ import type { LoadEnvOptions } from '../loadEnv.js';
4
+ import type { Logger } from '../logger.js';
5
+ import type { RsbuildDevServer } from '../server/devServer.js';
6
+ import type { StartDevServerResult, StartPreviewServerResult } from '../server/helper.js';
7
+ import type { NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config.js';
8
+ import type { RsbuildContext } from './context.js';
9
+ import type { RestartFn } from './hooks.js';
10
+ import type { RsbuildPlugin, RsbuildPluginAPI } from './plugin.js';
11
+ import type { Rspack } from './rspack.js';
12
+ import type { Falsy } from './utils.js';
13
+ export type StartDevServerOptions = {
14
+ /**
15
+ * Whether to get port silently and not print any logs.
16
+ * @default false
17
+ */ getPortSilently?: boolean;
18
+ };
19
+ export type CreateDevServerOptions = StartDevServerOptions & {
20
+ /**
21
+ * Whether to trigger Rsbuild compilation
22
+ * @default true
23
+ */ runCompile?: boolean;
24
+ };
25
+ export type PreviewOptions = {
26
+ /**
27
+ * Whether to get port silently and not print any logs.
28
+ * @default false
29
+ */ getPortSilently?: boolean;
30
+ /**
31
+ * Whether to check if the dist directory exists and is not empty.
32
+ * @default true
33
+ */ checkDistDir?: boolean;
34
+ };
35
+ export type BuildOptions = {
36
+ /**
37
+ * Whether to watch for file changes and rebuild.
38
+ * @default false
39
+ */ watch?: boolean;
40
+ };
41
+ export type Build = (options?: BuildOptions) => Promise<BuildResult>;
42
+ export type BuildResult = {
43
+ /**
44
+ * Close the build and call the `onCloseBuild` hook.
45
+ * In watch mode, this method will stop watching.
46
+ */ close: () => Promise<void>;
47
+ /**
48
+ * Rspack's [stats](https://rspack.rs/api/javascript-api/stats) object.
49
+ */ stats?: Rspack.Stats | Rspack.MultiStats;
50
+ };
51
+ export type InitConfigsOptions = Pick<RsbuildContext, 'action'>;
52
+ export type InspectConfigOptions = {
53
+ /**
54
+ * Inspect the config in the specified mode.
55
+ * Available options: 'development', 'production', or 'none'.
56
+ * @default Inferred from `process.env.NODE_ENV`: 'development' when unset,
57
+ * 'development' or 'production' when matching, otherwise 'none'.
58
+ */ mode?: RsbuildMode;
59
+ /**
60
+ * Enables verbose mode to display the complete function
61
+ * content in the configuration.
62
+ * @default false
63
+ */ verbose?: boolean;
64
+ /**
65
+ * Specify the output path for inspection results.
66
+ * @default '<context.distPath>/.rsbuild'
67
+ */ outputPath?: string;
68
+ /**
69
+ * Whether to write the inspection results to disk.
70
+ * @default false
71
+ */ writeToDisk?: boolean;
72
+ /**
73
+ * Extra configurations to be output.
74
+ * - key: The name of the configuration
75
+ * - value: The configuration object
76
+ * @example
77
+ * extraConfigs: {
78
+ * // Output `rstest.config.mjs` file
79
+ * 'rstest': {
80
+ * // ...
81
+ * },
82
+ * }
83
+ */ extraConfigs?: Record<string, unknown>;
84
+ };
85
+ export type InspectConfigResult = {
86
+ rsbuildConfig: string;
87
+ bundlerConfigs: string[];
88
+ environmentConfigs: string[];
89
+ origin: {
90
+ rsbuildConfig: Omit<NormalizedConfig, 'environments'>;
91
+ environmentConfigs: Record<string, NormalizedEnvironmentConfig>;
92
+ bundlerConfigs: Rspack.Configuration[];
93
+ };
94
+ };
95
+ export type CreateCompiler = () => Promise<Compiler | MultiCompiler>;
96
+ type RsbuildConfigInput = RsbuildConfig | LoadConfigResult;
97
+ export type CreateRsbuildOptions = {
98
+ /**
99
+ * The root path of current project.
100
+ * @default process.cwd()
101
+ */ cwd?: string;
102
+ /**
103
+ * The name of the framework or tool that is currently invoking Rsbuild.
104
+ * This allows plugins to tailor their behavior based on the calling context.
105
+ * Rsbuild plugins can access this value via `api.context.callerName`.
106
+ * @default 'rsbuild'
107
+ */ callerName?: string;
108
+ /**
109
+ * Only build specified environments.
110
+ * For example, passing `['web']` will only build the `web` environment.
111
+ * If not specified or passing an empty array, all environments will be built.
112
+ */ environment?: string[];
113
+ /**
114
+ * Alias for `config`.
115
+ * This option will be deprecated in the future.
116
+ */ rsbuildConfig?: RsbuildConfigInput | (() => Promise<RsbuildConfigInput>);
117
+ /**
118
+ * Rsbuild configuration or the result returned by `loadConfig`.
119
+ * Passing a function to load the config asynchronously with custom logic.
120
+ */ config?: RsbuildConfigInput | (() => Promise<RsbuildConfigInput>);
121
+ /**
122
+ * Whether to call `loadEnv` to load environment variables and define them
123
+ * as global variables via `source.define`.
124
+ * @default false
125
+ */ loadEnv?: boolean | LoadEnvOptions;
126
+ /**
127
+ * Function used to restart the current dev server or watch build.
128
+ */ restart?: RestartFn;
129
+ };
130
+ export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, 'cwd' | 'callerName'>> & Pick<CreateRsbuildOptions, 'loadEnv' | 'environment' | 'restart'> & {
131
+ rsbuildConfig: RsbuildConfig;
132
+ };
133
+ export type CreateDevServer = (options?: CreateDevServerOptions) => Promise<RsbuildDevServer>;
134
+ export type StartDevServer = (options?: StartDevServerOptions) => Promise<StartDevServerResult>;
135
+ export type InspectConfig = (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
136
+ export type AddPluginsOptions = {
137
+ /**
138
+ * Insert before the specified plugin.
139
+ */ before?: string;
140
+ /**
141
+ * Specify the environment that the plugin will be applied to.
142
+ * If not specified, the plugin will be be registered as a global plugin and
143
+ * applied to all environments.
144
+ */ environment?: string;
145
+ };
146
+ export type AddPlugins = (plugins: (RsbuildPlugin | Falsy)[], options?: AddPluginsOptions) => void;
147
+ export type RsbuildInstance = {
148
+ /**
149
+ * The logger associated with the current Rsbuild instance.
150
+ * It reflects `config.customLogger` when provided, otherwise uses a logger
151
+ * created specifically for the current Rsbuild instance.
152
+ */ logger: Logger;
153
+ /**
154
+ * Register one or more Rsbuild plugins, which can be called multiple times.
155
+ * This method needs to be called before compiling. If it is called after
156
+ * compiling, it will not affect the compilation result.
157
+ */ addPlugins: AddPlugins;
158
+ /**
159
+ * Get all the Rsbuild plugins registered in the current Rsbuild instance.
160
+ */ getPlugins: (options?: {
161
+ /**
162
+ * Get the plugins in the specified environment.
163
+ * If environment is not specified, get the global plugins.
164
+ */ environment: string;
165
+ }) => RsbuildPlugin[];
166
+ /**
167
+ * Removes one or more Rsbuild plugins, which can be called multiple times.
168
+ * This method needs to be called before compiling. If it is called after
169
+ * compiling, it will not affect the compilation result.
170
+ */ removePlugins: (pluginNames: string[], options?: {
171
+ /**
172
+ * Remove the plugin in the specified environment.
173
+ * If environment is not specified, remove it in all environments.
174
+ */ environment?: string;
175
+ }) => void;
176
+ /**
177
+ * Perform a production mode build. This method will generate optimized
178
+ * production bundles and emit them to the output directory.
179
+ */ build: Build;
180
+ /**
181
+ * Start a server to preview the production build locally.
182
+ * This method should be executed after `rsbuild.build`.
183
+ */ preview: (options?: PreviewOptions) => Promise<StartPreviewServerResult>;
184
+ /**
185
+ * Initialize and return the internal Rspack configurations used by Rsbuild.
186
+ * This method processes all plugins and configurations to generate the final
187
+ * Rspack configs. Note: You typically don't need to call this method directly
188
+ * since it's automatically invoked by methods like `rsbuild.build` and
189
+ * `rsbuild.startDevServer`.
190
+ */ initConfigs: (options?: InitConfigsOptions) => Promise<Rspack.Configuration[]>;
191
+ /**
192
+ * Inspect and debug Rsbuild's internal configurations. It provides access to:
193
+ * - The resolved Rsbuild configuration
194
+ * - The environment-specific Rsbuild configurations
195
+ * - The generated Rspack configurations
196
+ *
197
+ * The method serializes these configurations to strings and optionally writes
198
+ * them to disk for inspection.
199
+ */ inspectConfig: (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
200
+ /**
201
+ * Create an Rspack [Compiler](https://rspack.rs/api/javascript-api/compiler)
202
+ * instance. If there are multiple [environments](/config/environments) for
203
+ * this build, the return value is `MultiCompiler`.
204
+ */ createCompiler: CreateCompiler;
205
+ /**
206
+ * Rsbuild includes a built-in dev server designed to improve the development
207
+ * experience. When you run the `rsbuild dev` command, the server starts
208
+ * automatically and provides features such as page preview, routing, and hot
209
+ * module reloading.
210
+ *
211
+ * If you want to integrate the Rsbuild dev server into a custom server, you
212
+ * can use the `createDevServer` method to create a dev server instance and
213
+ * call its methods as needed.
214
+ *
215
+ * If you want to directly start the Rsbuild dev server, use the
216
+ * `rsbuild.startDevServer` method.
217
+ */ createDevServer: CreateDevServer;
218
+ /**
219
+ * Start the local dev server. This method will:
220
+ *
221
+ * 1. Start a development server that serves your application.
222
+ * 2. Watch for file changes and trigger recompilation.
223
+ */ startDevServer: StartDevServer;
224
+ } & Pick<RsbuildPluginAPI, 'context' | 'expose' | 'getNormalizedConfig' | 'getRsbuildConfig' | 'isPluginExists' | 'modifyEnvironmentConfig' | 'modifyRsbuildConfig' | 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterDevCompile' | 'onAfterEnvironmentCompile' | 'onAfterStartDevServer' | 'onAfterStartPreviewServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeDevCompile' | 'onBeforeEnvironmentCompile' | 'onBeforeStartDevServer' | 'onBeforeStartPreviewServer' | 'onCloseBuild' | 'onCloseDevServer' | 'onDevCompileDone' | 'onExit' | 'onRestart'>;
225
+ export type RsbuildTarget = 'web' | 'node' | 'web-worker';
226
+ export type RsbuildEntryDescription = Rspack.EntryDescription & {
227
+ /**
228
+ * Whether to generate an HTML file for the entry.
229
+ *
230
+ * @default true
231
+ */ html?: boolean;
232
+ };
233
+ export type RsbuildEntry = Record<string, string | string[] | RsbuildEntryDescription>;
234
+ export type RsbuildMode = 'development' | 'production' | 'none';
235
+ export type RsbuildStatsItem = Pick<Rspack.StatsCompilation, 'errors' | 'warnings' | 'entrypoints' | 'hash'>;
236
+ /**
237
+ * A subset of Rspack's StatsCompilation with only the fields we need
238
+ */ export type RsbuildStats = RsbuildStatsItem & {
239
+ children: RsbuildStatsItem[];
240
+ };
241
+ export { };
@@ -0,0 +1,10 @@
1
+ import type * as Rspack from '@rspack/core';
2
+ import type { RspackChain } from '../../compiled/rspack-chain/types/index.js';
3
+ import type { TransformHandler } from './plugin.js';
4
+ export type { Rspack, RspackChain };
5
+ declare module '@rspack/core' {
6
+ interface Compiler {
7
+ __rsbuildTransformer?: Record<string, TransformHandler>;
8
+ }
9
+ }
10
+ export type RspackRule = Rspack.RuleSetRules[number];
@@ -0,0 +1,161 @@
1
+ import type { CssExtractRspackLoaderOptions, CssExtractRspackPluginOptions } from '@rspack/core';
2
+ import type * as Connect from '../../compiled/connect-next/index.js';
3
+ import type HtmlRspackPlugin from '../../compiled/html-rspack-plugin/index.js';
4
+ import type { AcceptedPlugin, ProcessOptions } from '../../compiled/postcss/lib/postcss.js';
5
+ import type { Rspack } from './rspack.js';
6
+ import type { LiteralUnion } from './utils.js';
7
+ export type { Connect };
8
+ export type { HtmlRspackPlugin };
9
+ export interface CSSExtractOptions {
10
+ pluginOptions?: CssExtractRspackPluginOptions;
11
+ loaderOptions?: CssExtractRspackLoaderOptions;
12
+ }
13
+ /**
14
+ * A loose PostCSS plugin type that accepts plugins from different
15
+ * PostCSS versions. This helps avoid type conflicts when user
16
+ * projects use different PostCSS versions.
17
+ */ export type LoosePostCSSPlugin = any;
18
+ export type PostCSSOptions = ProcessOptions & {
19
+ config?: boolean;
20
+ plugins?: LoosePostCSSPlugin[];
21
+ };
22
+ export type PostCSSLoaderOptions = {
23
+ /**
24
+ * Enable PostCSS Parser support in CSS-in-JS. If you use JS styles the postcss-js parser, add the execute option.
25
+ * @default undefined
26
+ */ execute?: boolean;
27
+ /**
28
+ * Whether to generate source maps.
29
+ * @default `rsbuildConfig.output.sourceMap.css`
30
+ */ sourceMap?: boolean;
31
+ /**
32
+ * The special implementation option determines which implementation of PostCSS to use.
33
+ * @default `@rsbuild/core/compiled/postcss`
34
+ */ implementation?: unknown;
35
+ /**
36
+ * Allows to set PostCSS options and plugins.
37
+ * @default undefined
38
+ */ postcssOptions?: PostCSSOptions | ((loaderContext: Rspack.LoaderContext) => PostCSSOptions);
39
+ };
40
+ export type PostCSSPlugin = AcceptedPlugin;
41
+ export type CSSLoaderModulesMode = 'local' | 'global' | 'pure' | 'icss' | ((resourcePath: string) => 'local' | 'global' | 'pure' | 'icss');
42
+ export type CSSLoaderExportLocalsConvention = 'asIs' | 'as-is' | 'camelCase' | 'camel-case' | 'camelCaseOnly' | 'camel-case-only' | 'dashes' | 'dashesOnly' | 'dashes-only' | ((name: string) => string);
43
+ export interface CSSLoaderModulesOptions {
44
+ /**
45
+ * Allows auto enable CSS Modules/ICSS based on the filename, query or fragment.
46
+ */ auto?: boolean | RegExp | ((resourcePath: string, resourceQuery: string, resourceFragment: string) => boolean);
47
+ /**
48
+ * Allow `css-loader` to export names from global class or id, so you can use that as local name.
49
+ */ exportGlobals?: boolean;
50
+ /**
51
+ * Style of exported class names.
52
+ */ exportLocalsConvention?: CSSLoaderExportLocalsConvention;
53
+ /**
54
+ * Export only locals.
55
+ */ exportOnlyLocals?: boolean;
56
+ /**
57
+ * Allows to specify a function to generate the classname.
58
+ */ getLocalIdent?: (context: Rspack.LoaderContext, localIdentName: string, localName: string) => string;
59
+ /**
60
+ * Allows to configure the generated local ident name.
61
+ */ localIdentName?: string;
62
+ /**
63
+ * Allows to redefine basic loader context for local ident name.
64
+ */ localIdentContext?: string;
65
+ /**
66
+ * Allows to add custom hash to generate more unique classes.
67
+ */ localIdentHashSalt?: string;
68
+ /**
69
+ * Allows to specify hash function to generate classes.
70
+ */ localIdentHashFunction?: string;
71
+ /**
72
+ * Allows to specify hash digest to generate classes.
73
+ */ localIdentHashDigest?: string;
74
+ /**
75
+ * Allows to specify custom RegExp for local ident name.
76
+ */ localIdentRegExp?: string | RegExp;
77
+ /**
78
+ * Controls the level of compilation applied to the input styles.
79
+ */ mode?: CSSLoaderModulesMode;
80
+ /**
81
+ * Enables/disables ES modules named export for locals.
82
+ */ namedExport?: boolean;
83
+ /**
84
+ * Enables a callback to output the CSS Modules mapping JSON.
85
+ */ getJSON?: (context: {
86
+ resourcePath: string;
87
+ imports: object[];
88
+ exports: object[];
89
+ replacements: object[];
90
+ }) => Promise<void> | void;
91
+ }
92
+ export interface CSSLoaderOptions {
93
+ /**
94
+ * Allow to enable/disables handling the CSS functions url and image-set.
95
+ * If set to false, css-loader will not parse any paths specified in url or image-set
96
+ * @default true
97
+ */ url?: boolean | {
98
+ filter: (url: string, resourcePath: string) => boolean;
99
+ };
100
+ /**
101
+ * Allows to enables/disables @import at-rules handling.
102
+ * @default true
103
+ */ import?: boolean | {
104
+ filter: (url: string, media: string, resourcePath: string, supports?: string, layer?: string) => boolean;
105
+ };
106
+ /**
107
+ * Allows to enable/disable CSS Modules or ICSS and setup configuration:
108
+ */ modules?: boolean | LiteralUnion<'local' | 'global' | 'pure' | 'icss', string> | CSSLoaderModulesOptions;
109
+ /**
110
+ * By default generation of source maps depends on the devtool option.
111
+ */ sourceMap?: boolean;
112
+ /**
113
+ * Allows to enables/disables or setups number of loaders applied before CSS loader for @import at-rules,
114
+ * CSS Modules and ICSS imports, i.e. @import/composes/@value value from './values.css'/etc.
115
+ * @default 0
116
+ */ importLoaders?: number;
117
+ /**
118
+ * By default, css-loader generates JS modules that use the ES modules syntax.
119
+ * There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.
120
+ * @default true
121
+ */ esModule?: boolean;
122
+ /**
123
+ * Allows exporting styles as array with modules, string or constructable stylesheet (i.e. CSSStyleSheet)
124
+ * @default 'array'
125
+ */ exportType?: 'array' | 'string' | 'css-style-sheet';
126
+ }
127
+ export type StyleLoaderInjectType = 'styleTag' | 'singletonStyleTag' | 'lazyStyleTag' | 'lazySingletonStyleTag' | 'linkTag';
128
+ export interface StyleLoaderOptions {
129
+ /**
130
+ * By default, style-loader generates JS modules that use the ES modules syntax.
131
+ * There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.
132
+ * @default true
133
+ */ esModule?: boolean;
134
+ /**
135
+ * Allows to setup how styles will be injected into the DOM.
136
+ * @default 'styleTag'
137
+ */ injectType?: StyleLoaderInjectType;
138
+ /**
139
+ * If defined, the style-loader will attach given attributes with their values on <style> / <link> element.
140
+ * @default {}
141
+ */ attributes?: Record<string, string>;
142
+ /**
143
+ * By default, style-loader appends <style>/<link> elements to the end of the style target,
144
+ * which is the <head> tag of the page unless specified by insert.
145
+ * This will cause CSS created by the loader to take priority over CSS already present in the target.
146
+ * You can use other values if the standard behavior is not suitable for you, but we do not recommend doing this.
147
+ * If you target an iframe, make sure you have sufficient access rights.
148
+ *
149
+ * Supports:
150
+ * - a CSS selector where styles are injected
151
+ * - an absolute path to a custom insert module
152
+ *
153
+ * @default 'head'
154
+ */ insert?: LiteralUnion<'head' | 'body', string>;
155
+ /**
156
+ * Allows to setup an absolute path to a custom module that overrides
157
+ * the default styleTagTransform behavior.
158
+ *
159
+ * @default undefined
160
+ */ styleTagTransform?: string;
161
+ }
@@ -0,0 +1,16 @@
1
+ export type Falsy = false | null | undefined;
2
+ export type OneOrMany<T> = T | T[];
3
+ export type MaybePromise<T> = T | Promise<T>;
4
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
5
+ // https://github.com/microsoft/TypeScript/issues/29729
6
+ export type LiteralUnion<T extends U, U> = T | (U & Record<never, never>);
7
+ /**
8
+ * Creates a type with readonly properties at the first and second levels only.
9
+ */ export type TwoLevelReadonly<T> = keyof T extends never ? T : {
10
+ readonly [k in keyof T]: T[k] extends object ? {
11
+ readonly [p in keyof T[k]]: T[k][p];
12
+ } : T[k];
13
+ };
14
+ export type ConfigChain<T> = OneOrMany<T | ((config: T) => T | void)>;
15
+ export type ConfigChainWithContext<T, Ctx> = OneOrMany<T | ((config: T, ctx: Ctx) => T | void)>;
16
+ export type ConfigChainAsyncWithContext<T, Ctx> = OneOrMany<T | ((config: T, ctx: Ctx) => MaybePromise<T | void>)>;
@@ -0,0 +1,94 @@
1
+ import node_path from "node:path";
2
+ let INLINE_QUERY_REGEX = /[?&]inline(?:&|=|$)/, JS_FILE_REGEX = /\.m?js(?:\?.*)?$/, SOURCE_MAPPING_URL_REGEX = /(?:\/\*# sourceMappingURL=.*?\*\/|\/\/# sourceMappingURL=.*)$/gm, getWorkerOptionsCode = (isModule)=>`{
3
+ ${isModule ? 'type: "module",' : ''}
4
+ name: options && options.name
5
+ }`, deleteAsset = (compilation, filename)=>{
6
+ compilation.getAsset(filename) && compilation.deleteAsset(filename);
7
+ }, workerLoader_workerLoader = async function workerLoader() {
8
+ let callback = this.async(), isModule = !!this._compilation.outputOptions.module;
9
+ try {
10
+ if (!INLINE_QUERY_REGEX.test(this.resourceQuery)) return void callback(null, (({ resourcePath, isModule })=>{
11
+ let resourcePath1, workerRequest = (resourcePath1 = resourcePath, `./${node_path.basename(resourcePath1).replace(/\\/g, '/')}`), workerOptions = getWorkerOptionsCode(isModule);
12
+ return `export default function WorkerWrapper(options) {
13
+ return new Worker(new URL(${JSON.stringify(workerRequest)}, import.meta.url), ${workerOptions});
14
+ }`;
15
+ })({
16
+ resourcePath: this.resourcePath,
17
+ isModule
18
+ }));
19
+ let source = await ((context)=>{
20
+ let compiler = context._compiler, compilation = context._compilation, { rspack } = compiler, { outputOptions } = compilation, compilerName = `rsbuild-worker ${context.resourcePath}`, childCompiler = compilation.createChildCompiler(compilerName, {
21
+ publicPath: outputOptions.publicPath,
22
+ globalObject: 'self',
23
+ module: outputOptions.module,
24
+ chunkFormat: outputOptions.module ? 'module' : void 0,
25
+ chunkLoading: outputOptions.module ? 'import' : void 0,
26
+ workerChunkLoading: outputOptions.workerChunkLoading,
27
+ wasmLoading: outputOptions.wasmLoading,
28
+ workerWasmLoading: outputOptions.workerWasmLoading
29
+ }, []);
30
+ new rspack.webworker.WebWorkerTemplatePlugin().apply(childCompiler);
31
+ let moduleOptions = childCompiler.options.module, parserOptions = moduleOptions.parser ?? {};
32
+ return childCompiler.options.module = {
33
+ ...moduleOptions,
34
+ parser: {
35
+ ...parserOptions,
36
+ javascript: {
37
+ ...parserOptions.javascript,
38
+ dynamicImportMode: 'eager'
39
+ }
40
+ }
41
+ }, new rspack.LoaderTargetPlugin('webworker').apply(childCompiler), new rspack.EntryPlugin(context.context ?? node_path.dirname(context.resourcePath), context.resourcePath, node_path.parse(context.resourcePath).name).apply(childCompiler), new Promise((resolve, reject)=>{
42
+ childCompiler.runAsChild((error, entries, childCompilation)=>{
43
+ if (error) return void reject(error);
44
+ let entry = entries?.[0];
45
+ if (!entry || !childCompilation) return void reject(Error(`[rsbuild:worker] Failed to compile inline worker "${context.resourcePath}".`));
46
+ let workerFilename = [
47
+ ...entry.files
48
+ ].filter((file)=>JS_FILE_REGEX.test(file))[0];
49
+ if (!workerFilename) return void reject(Error(`[rsbuild:worker] Failed to find the inline worker output for "${context.resourcePath}".`));
50
+ if (childCompilation.getAssets().map((asset)=>asset.name).filter((file)=>file !== workerFilename && JS_FILE_REGEX.test(file)).length > 0) return void reject(Error(`[rsbuild:worker] Inline workers do not support code splitting yet. Use ?worker instead, or remove dynamic imports from "${context.resourcePath}".`));
51
+ let asset = childCompilation.getAsset(workerFilename);
52
+ if (!asset) return void reject(Error(`[rsbuild:worker] Failed to read the inline worker output "${workerFilename}".`));
53
+ for (let file of (deleteAsset(compilation, workerFilename), deleteAsset(compilation, `${workerFilename}.map`), childCompilation.fileDependencies))context.addDependency(file);
54
+ for (let dir of childCompilation.contextDependencies)context.addContextDependency(dir);
55
+ for (let missing of childCompilation.missingDependencies)context.addMissingDependency(missing);
56
+ resolve(asset.source.source().toString());
57
+ });
58
+ });
59
+ })(this);
60
+ callback(null, (({ source, isModule })=>{
61
+ let workerOptions = getWorkerOptionsCode(isModule), revokeCode = isModule ? 'URL.revokeObjectURL(import.meta.url);' : '(self.URL || self.webkitURL).revokeObjectURL(self.location.href);';
62
+ return `const jsContent = ${JSON.stringify(source.replace(SOURCE_MAPPING_URL_REGEX, ''))};
63
+ const workerURL = typeof self !== "undefined" && (self.URL || self.webkitURL);
64
+ const blob = workerURL && self.Blob && new Blob([${JSON.stringify(revokeCode)}, jsContent], { type: "text/javascript;charset=utf-8" });
65
+
66
+ export default function WorkerWrapper(options) {
67
+ let objURL;
68
+ try {
69
+ objURL = blob && workerURL.createObjectURL(blob);
70
+ if (!objURL) throw "";
71
+ const worker = new Worker(objURL, ${workerOptions});
72
+ worker.addEventListener("error", () => {
73
+ workerURL.revokeObjectURL(objURL);
74
+ });
75
+ return worker;
76
+ } catch (e) {
77
+ if (objURL) {
78
+ workerURL.revokeObjectURL(objURL);
79
+ }
80
+ return new Worker(
81
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent),
82
+ ${workerOptions}
83
+ );
84
+ }
85
+ }`;
86
+ })({
87
+ source,
88
+ isModule
89
+ }));
90
+ } catch (error) {
91
+ callback(error instanceof Error ? error : Error(String(error)));
92
+ }
93
+ };
94
+ export default workerLoader_workerLoader;