@rsbuild/core 2.0.7 → 2.0.9

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