@rsbuild/core 2.0.8 → 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 (75) hide show
  1. package/dist/1~rslib-runtime.js +8 -5
  2. package/dist/756.js +13 -7
  3. package/dist/memfs.js +4 -4
  4. package/dist-types/build.d.ts +1 -1
  5. package/dist-types/cli/init.d.ts +1 -1
  6. package/dist-types/configChain.d.ts +59 -118
  7. package/dist-types/constants.d.ts +35 -31
  8. package/dist-types/createContext.d.ts +1 -2
  9. package/dist-types/createRsbuild.d.ts +1 -2
  10. package/dist-types/defaultConfig.d.ts +2 -4
  11. package/dist-types/helpers/exitHook.d.ts +1 -1
  12. package/dist-types/helpers/format.d.ts +2 -1
  13. package/dist-types/helpers/fs.d.ts +2 -4
  14. package/dist-types/helpers/index.d.ts +1 -2
  15. package/dist-types/helpers/path.d.ts +4 -8
  16. package/dist-types/helpers/stats.d.ts +3 -5
  17. package/dist-types/helpers/url.d.ts +1 -0
  18. package/dist-types/helpers/vendors.d.ts +2 -3
  19. package/dist-types/helpers/version.d.ts +2 -3
  20. package/dist-types/hooks.d.ts +6 -8
  21. package/dist-types/index.d.ts +10 -5
  22. package/dist-types/initConfigs.d.ts +2 -3
  23. package/dist-types/initPlugins.d.ts +1 -1
  24. package/dist-types/inspectConfig.d.ts +1 -1
  25. package/dist-types/loadConfig.d.ts +24 -32
  26. package/dist-types/loadEnv.d.ts +48 -57
  27. package/dist-types/loader/transformRawLoader.d.ts +1 -0
  28. package/dist-types/logger.d.ts +1 -2
  29. package/dist-types/mergeConfig.d.ts +1 -2
  30. package/dist-types/pluginHelper.d.ts +1 -2
  31. package/dist-types/pluginManager.d.ts +4 -7
  32. package/dist-types/plugins/basic.d.ts +1 -2
  33. package/dist-types/plugins/css.d.ts +4 -0
  34. package/dist-types/plugins/fileSize.d.ts +6 -5
  35. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  36. package/dist-types/plugins/server.d.ts +1 -0
  37. package/dist-types/plugins/swc.d.ts +1 -2
  38. package/dist-types/restart.d.ts +4 -5
  39. package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +2 -3
  40. package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +2 -3
  41. package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +3 -4
  42. package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +1 -2
  43. package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +2 -3
  44. package/dist-types/rspackConfig.d.ts +1 -1
  45. package/dist-types/server/ansiHTML.d.ts +1 -2
  46. package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +1 -2
  47. package/dist-types/server/assets-middleware/index.d.ts +3 -5
  48. package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +1 -2
  49. package/dist-types/server/browserLogs.d.ts +1 -2
  50. package/dist-types/server/buildManager.d.ts +4 -6
  51. package/dist-types/server/cliShortcuts.d.ts +3 -1
  52. package/dist-types/server/devMiddlewares.d.ts +2 -3
  53. package/dist-types/server/devServer.d.ts +18 -23
  54. package/dist-types/server/gracefulShutdown.d.ts +2 -4
  55. package/dist-types/server/gzipMiddleware.d.ts +1 -1
  56. package/dist-types/server/helper.d.ts +36 -45
  57. package/dist-types/server/historyApiFallback.d.ts +8 -1
  58. package/dist-types/server/httpServer.d.ts +1 -1
  59. package/dist-types/server/middlewares.d.ts +4 -8
  60. package/dist-types/server/open.d.ts +1 -1
  61. package/dist-types/server/runner/basic.d.ts +4 -5
  62. package/dist-types/server/runner/index.d.ts +3 -1
  63. package/dist-types/server/socketServer.d.ts +24 -18
  64. package/dist-types/server/watchFiles.d.ts +1 -1
  65. package/dist-types/types/config.d.ts +1192 -1465
  66. package/dist-types/types/context.d.ts +63 -92
  67. package/dist-types/types/hooks.d.ts +106 -150
  68. package/dist-types/types/plugin.d.ts +359 -444
  69. package/dist-types/types/rsbuild.d.ts +156 -191
  70. package/dist-types/types/thirdParty.d.ts +101 -132
  71. package/dist-types/types/utils.d.ts +2 -5
  72. package/package.json +3 -3
  73. package/dist-types/client/hmr.d.ts +0 -3
  74. package/dist-types/client/log.d.ts +0 -13
  75. package/dist-types/client/overlay.d.ts +0 -1
@@ -10,86 +10,74 @@ import type { Rspack } from './rspack';
10
10
  import type { Falsy } from './utils';
11
11
  export type StartDevServerOptions = {
12
12
  /**
13
- * Whether to get port silently and not print any logs.
14
- * @default false
15
- */
16
- getPortSilently?: boolean;
13
+ * Whether to get port silently and not print any logs.
14
+ * @default false
15
+ */ getPortSilently?: boolean;
17
16
  };
18
17
  export type CreateDevServerOptions = StartDevServerOptions & {
19
18
  /**
20
- * Whether to trigger Rsbuild compilation
21
- * @default true
22
- */
23
- runCompile?: boolean;
19
+ * Whether to trigger Rsbuild compilation
20
+ * @default true
21
+ */ runCompile?: boolean;
24
22
  };
25
23
  export type PreviewOptions = {
26
24
  /**
27
- * Whether to get port silently and not print any logs.
28
- * @default false
29
- */
30
- getPortSilently?: boolean;
25
+ * Whether to get port silently and not print any logs.
26
+ * @default false
27
+ */ getPortSilently?: boolean;
31
28
  /**
32
- * Whether to check if the dist directory exists and is not empty.
33
- * @default true
34
- */
35
- checkDistDir?: boolean;
29
+ * Whether to check if the dist directory exists and is not empty.
30
+ * @default true
31
+ */ checkDistDir?: boolean;
36
32
  };
37
33
  export type BuildOptions = {
38
34
  /**
39
- * Whether to watch for file changes and rebuild.
40
- * @default false
41
- */
42
- watch?: boolean;
35
+ * Whether to watch for file changes and rebuild.
36
+ * @default false
37
+ */ watch?: boolean;
43
38
  };
44
39
  export type Build = (options?: BuildOptions) => Promise<BuildResult>;
45
40
  export type BuildResult = {
46
41
  /**
47
- * Close the build and call the `onCloseBuild` hook.
48
- * In watch mode, this method will stop watching.
49
- */
50
- close: () => Promise<void>;
42
+ * Close the build and call the `onCloseBuild` hook.
43
+ * In watch mode, this method will stop watching.
44
+ */ close: () => Promise<void>;
51
45
  /**
52
- * Rspack's [stats](https://rspack.rs/api/javascript-api/stats) object.
53
- */
54
- stats?: Rspack.Stats | Rspack.MultiStats;
46
+ * Rspack's [stats](https://rspack.rs/api/javascript-api/stats) object.
47
+ */ stats?: Rspack.Stats | Rspack.MultiStats;
55
48
  };
56
49
  export type InitConfigsOptions = Pick<RsbuildContext, 'action'>;
57
50
  export type InspectConfigOptions = {
58
51
  /**
59
- * Inspect the config in the specified mode.
60
- * Available options: 'development' or 'production'.
61
- * @default 'development'
62
- */
63
- mode?: RsbuildMode;
64
- /**
65
- * Enables verbose mode to display the complete function
66
- * content in the configuration.
67
- * @default false
68
- */
69
- verbose?: boolean;
70
- /**
71
- * Specify the output path for inspection results.
72
- * @default 'output.distPath.root'
73
- */
74
- outputPath?: string;
75
- /**
76
- * Whether to write the inspection results to disk.
77
- * @default false
78
- */
79
- writeToDisk?: boolean;
80
- /**
81
- * Extra configurations to be output.
82
- * - key: The name of the configuration
83
- * - value: The configuration object
84
- * @example
85
- * extraConfigs: {
86
- * // Output `rstest.config.mjs` file
87
- * 'rstest': {
88
- * // ...
89
- * },
90
- * }
91
- */
92
- extraConfigs?: Record<string, unknown>;
52
+ * Inspect the config in the specified mode.
53
+ * Available options: 'development' or 'production'.
54
+ * @default 'development'
55
+ */ mode?: RsbuildMode;
56
+ /**
57
+ * Enables verbose mode to display the complete function
58
+ * content in the configuration.
59
+ * @default false
60
+ */ verbose?: boolean;
61
+ /**
62
+ * Specify the output path for inspection results.
63
+ * @default 'output.distPath.root'
64
+ */ outputPath?: string;
65
+ /**
66
+ * Whether to write the inspection results to disk.
67
+ * @default false
68
+ */ writeToDisk?: boolean;
69
+ /**
70
+ * Extra configurations to be output.
71
+ * - key: The name of the configuration
72
+ * - value: The configuration object
73
+ * @example
74
+ * extraConfigs: {
75
+ * // Output `rstest.config.mjs` file
76
+ * 'rstest': {
77
+ * // ...
78
+ * },
79
+ * }
80
+ */ extraConfigs?: Record<string, unknown>;
93
81
  };
94
82
  export type InspectConfigResult = {
95
83
  rsbuildConfig: string;
@@ -104,39 +92,33 @@ export type InspectConfigResult = {
104
92
  export type CreateCompiler = () => Promise<Compiler | MultiCompiler>;
105
93
  export type CreateRsbuildOptions = {
106
94
  /**
107
- * The root path of current project.
108
- * @default process.cwd()
109
- */
110
- cwd?: string;
111
- /**
112
- * The name of the framework or tool that is currently invoking Rsbuild.
113
- * This allows plugins to tailor their behavior based on the calling context.
114
- * Rsbuild plugins can access this value via `api.context.callerName`.
115
- * @default 'rsbuild'
116
- */
117
- callerName?: string;
118
- /**
119
- * Only build specified environments.
120
- * For example, passing `['web']` will only build the `web` environment.
121
- * If not specified or passing an empty array, all environments will be built.
122
- */
123
- environment?: string[];
124
- /**
125
- * Alias for `config`.
126
- * This option will be deprecated in the future.
127
- */
128
- rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
129
- /**
130
- * Rsbuild configurations.
131
- * Passing a function to load the config asynchronously with custom logic.
132
- */
133
- config?: RsbuildConfig | (() => Promise<RsbuildConfig>);
134
- /**
135
- * Whether to call `loadEnv` to load environment variables and define them
136
- * as global variables via `source.define`.
137
- * @default false
138
- */
139
- loadEnv?: boolean | LoadEnvOptions;
95
+ * The root path of current project.
96
+ * @default process.cwd()
97
+ */ cwd?: string;
98
+ /**
99
+ * The name of the framework or tool that is currently invoking Rsbuild.
100
+ * This allows plugins to tailor their behavior based on the calling context.
101
+ * Rsbuild plugins can access this value via `api.context.callerName`.
102
+ * @default 'rsbuild'
103
+ */ callerName?: string;
104
+ /**
105
+ * Only build specified environments.
106
+ * For example, passing `['web']` will only build the `web` environment.
107
+ * If not specified or passing an empty array, all environments will be built.
108
+ */ environment?: string[];
109
+ /**
110
+ * Alias for `config`.
111
+ * This option will be deprecated in the future.
112
+ */ rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
113
+ /**
114
+ * Rsbuild configurations.
115
+ * Passing a function to load the config asynchronously with custom logic.
116
+ */ config?: RsbuildConfig | (() => Promise<RsbuildConfig>);
117
+ /**
118
+ * Whether to call `loadEnv` to load environment variables and define them
119
+ * as global variables via `source.define`.
120
+ * @default false
121
+ */ loadEnv?: boolean | LoadEnvOptions;
140
122
  };
141
123
  export type ResolvedCreateRsbuildOptions = Required<Pick<CreateRsbuildOptions, 'cwd' | 'callerName'>> & Pick<CreateRsbuildOptions, 'loadEnv' | 'environment'> & {
142
124
  rsbuildConfig: RsbuildConfig;
@@ -146,123 +128,106 @@ export type StartDevServer = (options?: StartDevServerOptions) => Promise<StartD
146
128
  export type InspectConfig = (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
147
129
  export type AddPluginsOptions = {
148
130
  /**
149
- * Insert before the specified plugin.
150
- */
151
- before?: string;
131
+ * Insert before the specified plugin.
132
+ */ before?: string;
152
133
  /**
153
- * Specify the environment that the plugin will be applied to.
154
- * If not specified, the plugin will be be registered as a global plugin and
155
- * applied to all environments.
156
- */
157
- environment?: string;
134
+ * Specify the environment that the plugin will be applied to.
135
+ * If not specified, the plugin will be be registered as a global plugin and
136
+ * applied to all environments.
137
+ */ environment?: string;
158
138
  };
159
139
  export type AddPlugins = (plugins: (RsbuildPlugin | Falsy)[], options?: AddPluginsOptions) => void;
160
140
  export type RsbuildInstance = {
161
141
  /**
162
- * The logger associated with the current Rsbuild instance.
163
- * It reflects `config.customLogger` when provided, otherwise uses a logger
164
- * created specifically for the current Rsbuild instance.
165
- */
166
- logger: Logger;
167
- /**
168
- * Register one or more Rsbuild plugins, which can be called multiple times.
169
- * This method needs to be called before compiling. If it is called after
170
- * compiling, it will not affect the compilation result.
171
- */
172
- addPlugins: AddPlugins;
173
- /**
174
- * Get all the Rsbuild plugins registered in the current Rsbuild instance.
175
- */
176
- getPlugins: (options?: {
142
+ * The logger associated with the current Rsbuild instance.
143
+ * It reflects `config.customLogger` when provided, otherwise uses a logger
144
+ * created specifically for the current Rsbuild instance.
145
+ */ logger: Logger;
146
+ /**
147
+ * Register one or more Rsbuild plugins, which can be called multiple times.
148
+ * This method needs to be called before compiling. If it is called after
149
+ * compiling, it will not affect the compilation result.
150
+ */ addPlugins: AddPlugins;
151
+ /**
152
+ * Get all the Rsbuild plugins registered in the current Rsbuild instance.
153
+ */ getPlugins: (options?: {
177
154
  /**
178
- * Get the plugins in the specified environment.
179
- * If environment is not specified, get the global plugins.
180
- */
181
- environment: string;
155
+ * Get the plugins in the specified environment.
156
+ * If environment is not specified, get the global plugins.
157
+ */ environment: string;
182
158
  }) => RsbuildPlugin[];
183
159
  /**
184
- * Removes one or more Rsbuild plugins, which can be called multiple times.
185
- * This method needs to be called before compiling. If it is called after
186
- * compiling, it will not affect the compilation result.
187
- */
188
- removePlugins: (pluginNames: string[], options?: {
160
+ * Removes one or more Rsbuild plugins, which can be called multiple times.
161
+ * This method needs to be called before compiling. If it is called after
162
+ * compiling, it will not affect the compilation result.
163
+ */ removePlugins: (pluginNames: string[], options?: {
189
164
  /**
190
- * Remove the plugin in the specified environment.
191
- * If environment is not specified, remove it in all environments.
192
- */
193
- environment?: string;
165
+ * Remove the plugin in the specified environment.
166
+ * If environment is not specified, remove it in all environments.
167
+ */ environment?: string;
194
168
  }) => void;
195
169
  /**
196
- * Perform a production mode build. This method will generate optimized
197
- * production bundles and emit them to the output directory.
198
- */
199
- build: Build;
200
- /**
201
- * Start a server to preview the production build locally.
202
- * This method should be executed after `rsbuild.build`.
203
- */
204
- preview: (options?: PreviewOptions) => Promise<StartPreviewServerResult>;
205
- /**
206
- * Initialize and return the internal Rspack configurations used by Rsbuild.
207
- * This method processes all plugins and configurations to generate the final
208
- * Rspack configs. Note: You typically don't need to call this method directly
209
- * since it's automatically invoked by methods like `rsbuild.build` and
210
- * `rsbuild.startDevServer`.
211
- */
212
- initConfigs: (options?: InitConfigsOptions) => Promise<Rspack.Configuration[]>;
213
- /**
214
- * Inspect and debug Rsbuild's internal configurations. It provides access to:
215
- * - The resolved Rsbuild configuration
216
- * - The environment-specific Rsbuild configurations
217
- * - The generated Rspack configurations
218
- *
219
- * The method serializes these configurations to strings and optionally writes
220
- * them to disk for inspection.
221
- */
222
- inspectConfig: (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
223
- /**
224
- * Create an Rspack [Compiler](https://rspack.rs/api/javascript-api/compiler)
225
- * instance. If there are multiple [environments](/config/environments) for
226
- * this build, the return value is `MultiCompiler`.
227
- */
228
- createCompiler: CreateCompiler;
229
- /**
230
- * Rsbuild includes a built-in dev server designed to improve the development
231
- * experience. When you run the `rsbuild dev` command, the server starts
232
- * automatically and provides features such as page preview, routing, and hot
233
- * module reloading.
234
- *
235
- * If you want to integrate the Rsbuild dev server into a custom server, you
236
- * can use the `createDevServer` method to create a dev server instance and
237
- * call its methods as needed.
238
- *
239
- * If you want to directly start the Rsbuild dev server, use the
240
- * `rsbuild.startDevServer` method.
241
- */
242
- createDevServer: CreateDevServer;
243
- /**
244
- * Start the local dev server. This method will:
245
- *
246
- * 1. Start a development server that serves your application.
247
- * 2. Watch for file changes and trigger recompilation.
248
- */
249
- startDevServer: StartDevServer;
170
+ * Perform a production mode build. This method will generate optimized
171
+ * production bundles and emit them to the output directory.
172
+ */ build: Build;
173
+ /**
174
+ * Start a server to preview the production build locally.
175
+ * This method should be executed after `rsbuild.build`.
176
+ */ preview: (options?: PreviewOptions) => Promise<StartPreviewServerResult>;
177
+ /**
178
+ * Initialize and return the internal Rspack configurations used by Rsbuild.
179
+ * This method processes all plugins and configurations to generate the final
180
+ * Rspack configs. Note: You typically don't need to call this method directly
181
+ * since it's automatically invoked by methods like `rsbuild.build` and
182
+ * `rsbuild.startDevServer`.
183
+ */ initConfigs: (options?: InitConfigsOptions) => Promise<Rspack.Configuration[]>;
184
+ /**
185
+ * Inspect and debug Rsbuild's internal configurations. It provides access to:
186
+ * - The resolved Rsbuild configuration
187
+ * - The environment-specific Rsbuild configurations
188
+ * - The generated Rspack configurations
189
+ *
190
+ * The method serializes these configurations to strings and optionally writes
191
+ * them to disk for inspection.
192
+ */ inspectConfig: (options?: InspectConfigOptions) => Promise<InspectConfigResult>;
193
+ /**
194
+ * Create an Rspack [Compiler](https://rspack.rs/api/javascript-api/compiler)
195
+ * instance. If there are multiple [environments](/config/environments) for
196
+ * this build, the return value is `MultiCompiler`.
197
+ */ createCompiler: CreateCompiler;
198
+ /**
199
+ * Rsbuild includes a built-in dev server designed to improve the development
200
+ * experience. When you run the `rsbuild dev` command, the server starts
201
+ * automatically and provides features such as page preview, routing, and hot
202
+ * module reloading.
203
+ *
204
+ * If you want to integrate the Rsbuild dev server into a custom server, you
205
+ * can use the `createDevServer` method to create a dev server instance and
206
+ * call its methods as needed.
207
+ *
208
+ * If you want to directly start the Rsbuild dev server, use the
209
+ * `rsbuild.startDevServer` method.
210
+ */ createDevServer: CreateDevServer;
211
+ /**
212
+ * Start the local dev server. This method will:
213
+ *
214
+ * 1. Start a development server that serves your application.
215
+ * 2. Watch for file changes and trigger recompilation.
216
+ */ startDevServer: StartDevServer;
250
217
  } & 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'>;
251
218
  export type RsbuildTarget = 'web' | 'node' | 'web-worker';
252
219
  export type RsbuildEntryDescription = Rspack.EntryDescription & {
253
220
  /**
254
- * Whether to generate an HTML file for the entry.
255
- *
256
- * @default true
257
- */
258
- html?: boolean;
221
+ * Whether to generate an HTML file for the entry.
222
+ *
223
+ * @default true
224
+ */ html?: boolean;
259
225
  };
260
226
  export type RsbuildEntry = Record<string, string | string[] | RsbuildEntryDescription>;
261
227
  export type RsbuildMode = 'development' | 'production' | 'none';
262
228
  export type RsbuildStatsItem = Pick<Rspack.StatsCompilation, 'errors' | 'warnings' | 'entrypoints' | 'hash'>;
263
229
  /**
264
230
  * A subset of Rspack's StatsCompilation with only the fields we need
265
- */
266
- export type RsbuildStats = RsbuildStatsItem & {
231
+ */ export type RsbuildStats = RsbuildStatsItem & {
267
232
  children: RsbuildStatsItem[];
268
233
  };