@rsbuild/core 1.2.7 → 1.2.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.
- package/README.md +10 -2
- package/compiled/css-loader/index.js +41 -41
- package/compiled/postcss/index.js +107 -105
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-load-config/index.js +10 -10
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rsbuild-dev-middleware/index.js +25 -25
- package/compiled/style-loader/index.js +10 -10
- package/dist/index.cjs +149 -106
- package/dist/index.js +149 -106
- package/dist-types/createRsbuild.d.ts +3 -0
- package/dist-types/rspack/preload/HtmlPreloadOrPrefetchPlugin.d.ts +3 -3
- package/dist-types/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +2 -2
- package/dist-types/server/devServer.d.ts +11 -6
- package/dist-types/server/getDevMiddlewares.d.ts +7 -2
- package/dist-types/server/runner/basic.d.ts +6 -0
- package/dist-types/server/runner/index.d.ts +6 -4
- package/dist-types/server/runner/type.d.ts +7 -1
- package/dist-types/server/watchFiles.d.ts +3 -2
- package/dist-types/types/config.d.ts +11 -3
- package/dist-types/types/hooks.d.ts +9 -1
- package/dist-types/types/plugin.d.ts +201 -74
- package/dist-types/types/rsbuild.d.ts +96 -29
- package/package.json +4 -4
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
19
|
-
import type { HtmlRspackPlugin,
|
|
19
|
+
import type { HtmlRspackPlugin, PreloadOrPrefetchOption } from '../../types';
|
|
20
20
|
type LinkType = 'preload' | 'prefetch';
|
|
21
21
|
export declare class HtmlPreloadOrPrefetchPlugin implements RspackPluginInstance {
|
|
22
|
-
readonly options:
|
|
22
|
+
readonly options: PreloadOrPrefetchOption;
|
|
23
23
|
name: string;
|
|
24
24
|
resourceHints: HtmlRspackPlugin.HtmlTagObject[];
|
|
25
25
|
type: LinkType;
|
|
26
26
|
HTMLCount: number;
|
|
27
|
-
constructor(options: true |
|
|
27
|
+
constructor(options: true | PreloadOrPrefetchOption, type: LinkType, HTMLCount: number);
|
|
28
28
|
apply(compiler: Compiler): void;
|
|
29
29
|
}
|
|
30
30
|
export {};
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
import type { Chunk, Compilation } from '@rspack/core';
|
|
19
|
-
import type {
|
|
19
|
+
import type { PreloadOrPrefetchOption } from '../../../types';
|
|
20
20
|
import type { BeforeAssetTagGenerationHtmlPluginData } from './type';
|
|
21
21
|
interface DoesChunkBelongToHtmlOptions {
|
|
22
22
|
chunk: Chunk;
|
|
23
23
|
compilation?: Compilation;
|
|
24
24
|
htmlPluginData: BeforeAssetTagGenerationHtmlPluginData;
|
|
25
|
-
pluginOptions?:
|
|
25
|
+
pluginOptions?: PreloadOrPrefetchOption;
|
|
26
26
|
}
|
|
27
27
|
export declare function recursiveChunkEntryNames(chunk: Chunk): string[];
|
|
28
28
|
export declare function doesChunkBelongToHtml({ chunk, htmlPluginData, }: DoesChunkBelongToHtmlOptions): boolean;
|
|
@@ -5,7 +5,17 @@ import type { CreateCompiler, CreateDevServerOptions, EnvironmentAPI, InternalCo
|
|
|
5
5
|
type HTTPServer = Server | Http2SecureServer;
|
|
6
6
|
export type RsbuildDevServer = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* The `connect` app instance.
|
|
9
|
+
* Can be used to attach custom middlewares to the dev server.
|
|
10
|
+
*/
|
|
11
|
+
middlewares: Connect.Server;
|
|
12
|
+
/**
|
|
13
|
+
* The Node.js HTTP server instance.
|
|
14
|
+
* Will be `Http2SecureServer` if `server.https` config is used.
|
|
15
|
+
*/
|
|
16
|
+
httpServer: import('node:http').Server | import('node:http2').Http2SecureServer | null;
|
|
17
|
+
/**
|
|
18
|
+
* Start listening on the Rsbuild dev server.
|
|
9
19
|
* Do not call this method if you are using a custom server.
|
|
10
20
|
*/
|
|
11
21
|
listen: () => Promise<{
|
|
@@ -24,11 +34,6 @@ export type RsbuildDevServer = {
|
|
|
24
34
|
* By default, Rsbuild server listens on port `3000` and automatically increments the port number if the port is occupied.
|
|
25
35
|
*/
|
|
26
36
|
port: number;
|
|
27
|
-
/**
|
|
28
|
-
* The `connect` app instance.
|
|
29
|
-
* Can be used to attach custom middlewares to the dev server.
|
|
30
|
-
*/
|
|
31
|
-
middlewares: Connect.Server;
|
|
32
37
|
/**
|
|
33
38
|
* Notify that the Rsbuild server has been started.
|
|
34
39
|
* Rsbuild will trigger `onAfterStartDevServer` hook in this stage.
|
|
@@ -16,10 +16,15 @@ export type RsbuildDevMiddlewareOptions = {
|
|
|
16
16
|
output: {
|
|
17
17
|
distPath: string;
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Callbacks returned by the `onBeforeStartDevServer` hook.
|
|
21
|
+
*/
|
|
22
|
+
postCallbacks: (() => void)[];
|
|
19
23
|
};
|
|
20
24
|
export type Middlewares = Array<RequestHandler | [string, RequestHandler]>;
|
|
21
|
-
export
|
|
25
|
+
export type GetMiddlewaresResult = {
|
|
22
26
|
close: () => Promise<void>;
|
|
23
27
|
onUpgrade: UpgradeEvent;
|
|
24
28
|
middlewares: Middlewares;
|
|
25
|
-
}
|
|
29
|
+
};
|
|
30
|
+
export declare const getMiddlewares: (options: RsbuildDevMiddlewareOptions) => Promise<GetMiddlewaresResult>;
|
|
@@ -2,6 +2,7 @@ import type { CompilerOptions, Runner } from './type';
|
|
|
2
2
|
import type { BasicGlobalContext, BasicModuleScope, BasicRunnerFile, ModuleObject, RunnerRequirer } from './type';
|
|
3
3
|
export interface IBasicRunnerOptions {
|
|
4
4
|
name: string;
|
|
5
|
+
isBundleOutput: (modulePath: string) => boolean;
|
|
5
6
|
runInNewContext?: boolean;
|
|
6
7
|
readFileSync: (path: string) => string;
|
|
7
8
|
dist: string;
|
|
@@ -18,6 +19,11 @@ export declare abstract class BasicRunner implements Runner {
|
|
|
18
19
|
protected abstract createGlobalContext(): BasicGlobalContext;
|
|
19
20
|
protected abstract createBaseModuleScope(): BasicModuleScope;
|
|
20
21
|
protected abstract createModuleScope(requireFn: RunnerRequirer, m: ModuleObject, file: BasicRunnerFile): BasicModuleScope;
|
|
22
|
+
/**
|
|
23
|
+
* Get the file information for a given module path.
|
|
24
|
+
*
|
|
25
|
+
* @returns An object containing the file path, content, and subPath, or null if the module is not an rspack output.
|
|
26
|
+
*/
|
|
21
27
|
protected getFile(modulePath: string[] | string, currentDirectory: string): BasicRunnerFile | null;
|
|
22
28
|
protected preExecute(_code: string, _file: BasicRunnerFile): void;
|
|
23
29
|
protected postExecute(_m: Record<string, any>, _file: BasicRunnerFile): void;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Runner, RunnerFactory, RunnerFactoryOptions } from './type';
|
|
2
2
|
export declare class BasicRunnerFactory implements RunnerFactory {
|
|
3
3
|
protected name: string;
|
|
4
4
|
constructor(name: string);
|
|
5
|
-
create(
|
|
6
|
-
protected createRunner(
|
|
5
|
+
create(options: RunnerFactoryOptions): Runner;
|
|
6
|
+
protected createRunner(options: RunnerFactoryOptions): Runner;
|
|
7
7
|
}
|
|
8
|
-
export declare const run: <T>(bundlePath
|
|
8
|
+
export declare const run: <T>({ bundlePath, ...runnerFactoryOptions }: RunnerFactoryOptions & {
|
|
9
|
+
bundlePath: string;
|
|
10
|
+
}) => Promise<T>;
|
|
@@ -31,6 +31,12 @@ export interface Runner {
|
|
|
31
31
|
run(file: string): Promise<unknown>;
|
|
32
32
|
getRequire(): RunnerRequirer;
|
|
33
33
|
}
|
|
34
|
+
export type RunnerFactoryOptions = {
|
|
35
|
+
dist: string;
|
|
36
|
+
compilerOptions: CompilerOptions;
|
|
37
|
+
readFileSync: (path: string) => string;
|
|
38
|
+
isBundleOutput: (modulePath: string) => boolean;
|
|
39
|
+
};
|
|
34
40
|
export interface RunnerFactory {
|
|
35
|
-
create(
|
|
41
|
+
create(options: RunnerFactoryOptions): Runner;
|
|
36
42
|
}
|
|
@@ -7,8 +7,9 @@ type WatchFilesOptions = {
|
|
|
7
7
|
compileMiddlewareAPI?: CompileMiddlewareAPI;
|
|
8
8
|
root: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type WatchFilesResult = {
|
|
11
11
|
close(): Promise<void>;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
|
+
export declare function setupWatchFiles(options: WatchFilesOptions): Promise<WatchFilesResult | undefined>;
|
|
13
14
|
export declare function createChokidar(pathOrGlobs: string[], root: string, options: ChokidarOptions): Promise<FSWatcher>;
|
|
14
15
|
export {};
|
|
@@ -336,6 +336,11 @@ export type BuildCacheOptions = {
|
|
|
336
336
|
* @default undefined
|
|
337
337
|
*/
|
|
338
338
|
cacheDigest?: Array<string | undefined>;
|
|
339
|
+
/**
|
|
340
|
+
* An array of files containing build dependencies.
|
|
341
|
+
* Rspack will use the hash of each of these files to invalidate the persistent cache.
|
|
342
|
+
*/
|
|
343
|
+
buildDependencies?: string[];
|
|
339
344
|
};
|
|
340
345
|
export type PrintFileSizeAsset = {
|
|
341
346
|
/**
|
|
@@ -393,11 +398,14 @@ export type Preconnect = Array<string | PreconnectOption>;
|
|
|
393
398
|
export type DnsPrefetch = string[];
|
|
394
399
|
export type PreloadIncludeType = 'async-chunks' | 'initial' | 'all-assets' | 'all-chunks';
|
|
395
400
|
export type Filter = Array<string | RegExp> | ((filename: string) => boolean);
|
|
396
|
-
export interface
|
|
401
|
+
export interface PreloadOrPrefetchOption {
|
|
397
402
|
type?: PreloadIncludeType;
|
|
398
403
|
include?: Filter;
|
|
399
404
|
exclude?: Filter;
|
|
405
|
+
dedupe?: boolean;
|
|
400
406
|
}
|
|
407
|
+
export type PreloadOption = PreloadOrPrefetchOption;
|
|
408
|
+
export type PrefetchOption = Omit<PreloadOrPrefetchOption, 'dedupe'>;
|
|
401
409
|
export interface PerformanceConfig {
|
|
402
410
|
/**
|
|
403
411
|
* Whether to remove `console.[methodName]` in production build.
|
|
@@ -441,14 +449,14 @@ export interface PerformanceConfig {
|
|
|
441
449
|
*
|
|
442
450
|
* Specifies that the user agent must preemptively fetch and cache the target resource for current navigation.
|
|
443
451
|
*/
|
|
444
|
-
preload?: true |
|
|
452
|
+
preload?: true | PreloadOption;
|
|
445
453
|
/**
|
|
446
454
|
* Used to control resource `Prefetch`.
|
|
447
455
|
*
|
|
448
456
|
* Specifies that the user agent should preemptively fetch and cache the target resource as it
|
|
449
457
|
* is likely to be required for a followup navigation.
|
|
450
458
|
*/
|
|
451
|
-
prefetch?: true |
|
|
459
|
+
prefetch?: true | PrefetchOption;
|
|
452
460
|
/**
|
|
453
461
|
* Whether capture timing information for each module,
|
|
454
462
|
* same as the [profile](https://webpack.js.org/configuration/other-options/#profile) config of webpack.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChainIdentifier } from '..';
|
|
2
2
|
import type RspackChain from '../../compiled/rspack-chain/index.js';
|
|
3
|
+
import type { RsbuildDevServer } from '../server/devServer';
|
|
3
4
|
import type { EnvironmentConfig, HtmlBasicTag, MergedEnvironmentConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
|
|
4
5
|
import type { RsbuildEntry, RsbuildTarget } from './rsbuild';
|
|
5
6
|
import type { Rspack } from './rspack';
|
|
@@ -33,8 +34,15 @@ export type OnDevCompileDoneFn = (params: {
|
|
|
33
34
|
environments: Record<string, EnvironmentContext>;
|
|
34
35
|
}) => MaybePromise<void>;
|
|
35
36
|
export type OnBeforeStartDevServerFn = (params: {
|
|
37
|
+
/**
|
|
38
|
+
* The dev server instance, the same as the return value of `createDevServer`.
|
|
39
|
+
*/
|
|
40
|
+
server: RsbuildDevServer;
|
|
41
|
+
/**
|
|
42
|
+
* A read-only object that provides some context information about different environments.
|
|
43
|
+
*/
|
|
36
44
|
environments: Record<string, EnvironmentContext>;
|
|
37
|
-
}) => MaybePromise<void>;
|
|
45
|
+
}) => MaybePromise<(() => void) | void>;
|
|
38
46
|
export type OnBeforeStartProdServerFn = () => MaybePromise<void>;
|
|
39
47
|
export type Routes = Array<{
|
|
40
48
|
entryName: string;
|
|
@@ -4,7 +4,7 @@ import type { ChainIdentifier } from '../configChain';
|
|
|
4
4
|
import type { ModifyRspackConfigUtils, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
|
|
5
5
|
import type { RsbuildContext } from './context';
|
|
6
6
|
import type { EnvironmentContext, ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
|
|
7
|
-
import type { RsbuildTarget } from './rsbuild';
|
|
7
|
+
import type { RsbuildInstance, RsbuildTarget } from './rsbuild';
|
|
8
8
|
import type { Rspack } from './rspack';
|
|
9
9
|
import type { HtmlRspackPlugin } from './thirdParty';
|
|
10
10
|
import type { Falsy } from './utils';
|
|
@@ -14,27 +14,82 @@ export type HookDescriptor<T extends (...args: any[]) => any> = {
|
|
|
14
14
|
handler: T;
|
|
15
15
|
order: HookOrder;
|
|
16
16
|
};
|
|
17
|
-
export type EnvironmentAsyncHook<Callback extends (...args: any[]) => any> = {
|
|
17
|
+
export type EnvironmentAsyncHook<Callback extends (...args: any[]) => T, T = any> = {
|
|
18
|
+
/**
|
|
19
|
+
* Registers a callback function to be executed when the hook is triggered.
|
|
20
|
+
* The callback can be a plain function or a HookDescriptor that includes execution order.
|
|
21
|
+
* The callback will be executed in all environments by default.
|
|
22
|
+
* If you need to specify the environment, please use `tapEnvironment`
|
|
23
|
+
* @param cb The callback function or hook descriptor to register
|
|
24
|
+
*/
|
|
25
|
+
tap: (cb: Callback | HookDescriptor<Callback>) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Registers a callback function to be executed when the hook is triggered.
|
|
28
|
+
* The callback will only be executed under the specified environment.
|
|
29
|
+
*/
|
|
18
30
|
tapEnvironment: (params: {
|
|
19
31
|
/**
|
|
20
|
-
* Specify that the callback will
|
|
32
|
+
* Specify the environment that the callback will be executed under.
|
|
21
33
|
*/
|
|
22
34
|
environment?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The callback function or hook descriptor to register
|
|
37
|
+
*/
|
|
23
38
|
handler: Callback | HookDescriptor<Callback>;
|
|
24
39
|
}) => void;
|
|
25
40
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
41
|
+
* Executes callbacks in sequence independently and collects all their results into an array.
|
|
42
|
+
* Each callback receives the original parameters, and their results don't affect subsequent callbacks.
|
|
43
|
+
* @returns A promise that resolves with an array containing the results of all callbacks
|
|
28
44
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
callChain: (params: {
|
|
46
|
+
/**
|
|
47
|
+
* Specify the environment for filtering callbacks.
|
|
48
|
+
*/
|
|
31
49
|
environment?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The parameters to pass to each callback
|
|
52
|
+
*/
|
|
32
53
|
args: Parameters<Callback>;
|
|
33
54
|
}) => Promise<Parameters<Callback>>;
|
|
55
|
+
/**
|
|
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: {
|
|
61
|
+
/**
|
|
62
|
+
* Specify the environment for filtering callbacks.
|
|
63
|
+
*/
|
|
64
|
+
environment?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The parameters to pass to each callback
|
|
67
|
+
*/
|
|
68
|
+
args: Parameters<Callback>;
|
|
69
|
+
}) => Promise<Awaited<ReturnType<Callback>>[]>;
|
|
34
70
|
};
|
|
35
|
-
export type AsyncHook<Callback extends (...args: any[]) => any> = {
|
|
71
|
+
export type AsyncHook<Callback extends (...args: any[]) => T, T = any> = {
|
|
72
|
+
/**
|
|
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
|
+
*/
|
|
36
77
|
tap: (cb: Callback | HookDescriptor<Callback>) => void;
|
|
37
|
-
|
|
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>>[]>;
|
|
38
93
|
};
|
|
39
94
|
export type ModifyRspackConfigFn = (config: Rspack.Configuration, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
|
|
40
95
|
export type ModifyWebpackChainUtils = ModifyChainUtils & {
|
|
@@ -63,42 +118,7 @@ export type PluginMeta = {
|
|
|
63
118
|
environment: string;
|
|
64
119
|
instance: RsbuildPlugin;
|
|
65
120
|
};
|
|
66
|
-
export type PluginManager = {
|
|
67
|
-
getPlugins: (options?: {
|
|
68
|
-
/**
|
|
69
|
-
* Get the plugins in the specified environment.
|
|
70
|
-
*
|
|
71
|
-
* If environment is not specified, get the global plugins.
|
|
72
|
-
*/
|
|
73
|
-
environment: string;
|
|
74
|
-
}) => RsbuildPlugin[];
|
|
75
|
-
addPlugins: (plugins: Array<RsbuildPlugin | Falsy>, options?: {
|
|
76
|
-
/**
|
|
77
|
-
* Insert before the specified plugin.
|
|
78
|
-
*/
|
|
79
|
-
before?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Add a plugin for the specified environment.
|
|
82
|
-
* If environment is not specified, it will be registered as a global plugin (effective in all environments)
|
|
83
|
-
*/
|
|
84
|
-
environment?: string;
|
|
85
|
-
}) => void;
|
|
86
|
-
removePlugins: (pluginNames: string[], options?: {
|
|
87
|
-
/**
|
|
88
|
-
* Remove the plugin in the specified environment.
|
|
89
|
-
*
|
|
90
|
-
* If environment is not specified, remove it in all environments.
|
|
91
|
-
*/
|
|
92
|
-
environment: string;
|
|
93
|
-
}) => void;
|
|
94
|
-
isPluginExists: (pluginName: string, options?: {
|
|
95
|
-
/**
|
|
96
|
-
* Whether it exists in the specified environment.
|
|
97
|
-
*
|
|
98
|
-
* If environment is not specified, determine whether the plugin is a global plugin.
|
|
99
|
-
*/
|
|
100
|
-
environment: string;
|
|
101
|
-
}) => boolean;
|
|
121
|
+
export type PluginManager = Pick<RsbuildInstance, 'getPlugins' | 'addPlugins' | 'isPluginExists' | 'removePlugins'> & {
|
|
102
122
|
/** Get all plugins with environment info */
|
|
103
123
|
getAllPluginsWithMeta: () => PluginMeta[];
|
|
104
124
|
};
|
|
@@ -300,50 +320,157 @@ declare function getNormalizedConfig(options: {
|
|
|
300
320
|
* Define a generic Rsbuild plugin API that provider can extend as needed.
|
|
301
321
|
*/
|
|
302
322
|
export type RsbuildPluginAPI = Readonly<{
|
|
323
|
+
/**
|
|
324
|
+
* A read-only object that provides some context information.
|
|
325
|
+
*/
|
|
303
326
|
context: Readonly<RsbuildContext>;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Explicitly expose some properties or methods of the current plugin,
|
|
329
|
+
* and other plugins can get these APIs through `api.useExposed`.
|
|
330
|
+
*/
|
|
331
|
+
expose: <T = any>(id: string | symbol, api: T) => void;
|
|
332
|
+
/**
|
|
333
|
+
* Get the Rsbuild config, this method must be called after the
|
|
334
|
+
* `modifyRsbuildConfig` hook is executed.
|
|
335
|
+
*/
|
|
336
|
+
getRsbuildConfig: GetRsbuildConfig;
|
|
337
|
+
/**
|
|
338
|
+
* Get the all normalized Rsbuild config or the Rsbuild config of a specified
|
|
339
|
+
* environment, this method must be called after the
|
|
340
|
+
* `modifyRsbuildConfig` hook is executed.
|
|
341
|
+
*/
|
|
342
|
+
getNormalizedConfig: typeof getNormalizedConfig;
|
|
343
|
+
/**
|
|
344
|
+
* Determines if a plugin has been registered in the current Rsbuild instance.
|
|
345
|
+
*/
|
|
346
|
+
isPluginExists: (pluginName: string, options?: {
|
|
347
|
+
/**
|
|
348
|
+
* Whether it exists in the specified environment.
|
|
349
|
+
* If environment is not specified, determine whether the plugin is a global plugin.
|
|
350
|
+
*/
|
|
351
|
+
environment: string;
|
|
352
|
+
}) => boolean;
|
|
353
|
+
/**
|
|
354
|
+
* Allows you to modify the Rspack configuration using the `rspack-chain` API,
|
|
355
|
+
* providing the same functionality as `tools.bundlerChain`.
|
|
356
|
+
*/
|
|
357
|
+
modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
|
|
358
|
+
/**
|
|
359
|
+
* Modify the Rsbuild configuration of a specific environment.
|
|
360
|
+
*/
|
|
361
|
+
modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
|
|
362
|
+
/**
|
|
363
|
+
* Modify the tags that are injected into the HTML.
|
|
364
|
+
*/
|
|
365
|
+
modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
|
|
366
|
+
/**
|
|
367
|
+
* To modify the Rspack config, you can directly modify the config object,
|
|
368
|
+
* or return a new object to replace the previous object.
|
|
369
|
+
*/
|
|
370
|
+
modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
|
|
371
|
+
/**
|
|
372
|
+
* Modify the config passed to the Rsbuild, you can directly modify the config object,
|
|
373
|
+
* or return a new object to replace the previous object.
|
|
374
|
+
*/
|
|
375
|
+
modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
|
|
376
|
+
/**
|
|
377
|
+
* Allows you to modify the webpack configuration using the `rspack-chain` API,
|
|
378
|
+
* providing the same functionality as `tools.bundlerChain`.
|
|
379
|
+
*/
|
|
380
|
+
modifyWebpackChain: PluginHook<ModifyWebpackChainFn>;
|
|
381
|
+
/**
|
|
382
|
+
* To modify the webpack config, you can directly modify the config object,
|
|
383
|
+
* or return a new object to replace the previous object.
|
|
384
|
+
*/
|
|
385
|
+
modifyWebpackConfig: PluginHook<ModifyWebpackConfigFn>;
|
|
386
|
+
/**
|
|
387
|
+
* A callback function that is triggered after running the production build.
|
|
388
|
+
* You can access the build result information via the
|
|
389
|
+
* [stats](https://rspack.dev/api/javascript-api/stats) parameter.
|
|
390
|
+
*/
|
|
307
391
|
onAfterBuild: PluginHook<OnAfterBuildFn>;
|
|
308
|
-
|
|
392
|
+
/**
|
|
393
|
+
* A callback function that is triggered after the compiler instance has been
|
|
394
|
+
* created, but before the build process. This hook is called when you run
|
|
395
|
+
* `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
|
|
396
|
+
*/
|
|
397
|
+
onAfterCreateCompiler: PluginHook<OnAfterCreateCompilerFn>;
|
|
398
|
+
/**
|
|
399
|
+
* A callback function that is triggered after the compilation of a single environment.
|
|
400
|
+
* You can access the build result information via the
|
|
401
|
+
* [stats](https://rspack.dev/api/javascript-api/stats) parameter.
|
|
402
|
+
*/
|
|
309
403
|
onAfterEnvironmentCompile: PluginHook<OnAfterEnvironmentCompileFn>;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Called after starting the dev server, you can get the port number with the
|
|
406
|
+
* `port` parameter, and the page routes info with the `routes` parameter.
|
|
407
|
+
*/
|
|
313
408
|
onAfterStartDevServer: PluginHook<OnAfterStartDevServerFn>;
|
|
314
|
-
|
|
409
|
+
/**
|
|
410
|
+
* Called after starting the production preview server, you can get the port
|
|
411
|
+
* number with the `port` parameter, and the page routes info with the
|
|
412
|
+
* `routes` parameter.
|
|
413
|
+
*/
|
|
315
414
|
onAfterStartProdServer: PluginHook<OnAfterStartProdServerFn>;
|
|
316
|
-
|
|
317
|
-
|
|
415
|
+
/**
|
|
416
|
+
* A callback function that is triggered before the production build is executed.
|
|
417
|
+
*/
|
|
418
|
+
onBeforeBuild: PluginHook<OnBeforeBuildFn>;
|
|
419
|
+
/**
|
|
420
|
+
* A callback function that is triggered after the Compiler instance has been
|
|
421
|
+
* created, but before the build process begins. This hook is called when you
|
|
422
|
+
* run `rsbuild.startDevServer`, `rsbuild.build`, or `rsbuild.createCompiler`.
|
|
423
|
+
*/
|
|
318
424
|
onBeforeCreateCompiler: PluginHook<OnBeforeCreateCompilerFn>;
|
|
319
|
-
modifyHTMLTags: PluginHook<ModifyHTMLTagsFn>;
|
|
320
|
-
modifyRsbuildConfig: PluginHook<ModifyRsbuildConfigFn>;
|
|
321
|
-
modifyEnvironmentConfig: PluginHook<ModifyEnvironmentConfigFn>;
|
|
322
|
-
modifyBundlerChain: PluginHook<ModifyBundlerChainFn>;
|
|
323
|
-
/** Only works when bundler is Rspack */
|
|
324
|
-
modifyRspackConfig: PluginHook<ModifyRspackConfigFn>;
|
|
325
|
-
/** Only works when bundler is webpack */
|
|
326
|
-
modifyWebpackChain: PluginHook<ModifyWebpackChainFn>;
|
|
327
|
-
/** Only works when bundler is webpack */
|
|
328
|
-
modifyWebpackConfig: PluginHook<ModifyWebpackConfigFn>;
|
|
329
|
-
getRsbuildConfig: GetRsbuildConfig;
|
|
330
|
-
getNormalizedConfig: typeof getNormalizedConfig;
|
|
331
425
|
/**
|
|
332
|
-
*
|
|
426
|
+
* A callback function that is triggered before the compilation of a single environment.
|
|
333
427
|
*/
|
|
334
|
-
|
|
335
|
-
useExposed: <T = any>(id: string | symbol) => T | undefined;
|
|
428
|
+
onBeforeEnvironmentCompile: PluginHook<OnBeforeEnvironmentCompileFn>;
|
|
336
429
|
/**
|
|
337
|
-
*
|
|
430
|
+
* Called before starting the dev server.
|
|
338
431
|
*/
|
|
339
|
-
|
|
432
|
+
onBeforeStartDevServer: PluginHook<OnBeforeStartDevServerFn>;
|
|
340
433
|
/**
|
|
341
|
-
*
|
|
434
|
+
* Called before starting the production preview server.
|
|
435
|
+
*/
|
|
436
|
+
onBeforeStartProdServer: PluginHook<OnBeforeStartProdServerFn>;
|
|
437
|
+
/**
|
|
438
|
+
* Called when closing the build instance. Can be used to perform cleanup
|
|
439
|
+
* operations when the building is closed.
|
|
440
|
+
*/
|
|
441
|
+
onCloseBuild: PluginHook<OnCloseBuildFn>;
|
|
442
|
+
/**
|
|
443
|
+
* Called when closing the dev server. Can be used to perform cleanup
|
|
444
|
+
* operations when the dev server is closed.
|
|
445
|
+
*/
|
|
446
|
+
onCloseDevServer: PluginHook<OnCloseDevServerFn>;
|
|
447
|
+
/**
|
|
448
|
+
* Called after each development mode build, you can use `isFirstCompile`
|
|
449
|
+
* to determine whether it is the first build.
|
|
450
|
+
*/
|
|
451
|
+
onDevCompileDone: PluginHook<OnDevCompileDoneFn>;
|
|
452
|
+
/**
|
|
453
|
+
* Called when the process is going to exit, this hook can only execute
|
|
454
|
+
* synchronous code.
|
|
455
|
+
*/
|
|
456
|
+
onExit: PluginHook<OnExitFn>;
|
|
457
|
+
/**
|
|
458
|
+
* Modify assets before emitting, the same as Rspack's
|
|
459
|
+
* [compilation.hooks.processAssets](https://rspack.dev/api/plugin-api/compilation-hooks#processassets) hook.
|
|
342
460
|
*/
|
|
343
461
|
processAssets: ProcessAssetsFn;
|
|
344
462
|
/**
|
|
345
|
-
*
|
|
463
|
+
* Intercept and modify module request information before module resolution begins.
|
|
464
|
+
* The same as Rspack's [normalModuleFactory.hooks.resolve](https://rspack.dev/api/plugin-api/normal-module-factory-hooks#resolve) hook.
|
|
346
465
|
*/
|
|
347
466
|
resolve: ResolveFn;
|
|
467
|
+
/**
|
|
468
|
+
* Used to transform the code of modules.
|
|
469
|
+
*/
|
|
470
|
+
transform: TransformFn;
|
|
471
|
+
/**
|
|
472
|
+
* Get the properties or methods exposed by other plugins.
|
|
473
|
+
*/
|
|
474
|
+
useExposed: <T = any>(id: string | symbol) => T | undefined;
|
|
348
475
|
}>;
|
|
349
476
|
export {};
|