import type HtmlWebpackPlugin from 'html-webpack-plugin';
import type { ChainIdentifier } from '../chain';
import type { RspackChain } from '../chain';
import type { HtmlBasicTag, RsbuildConfig } from './config';
import type { RsbuildTarget } from './rsbuild';
import type { Rspack, RspackConfig } from './rspack';
import type { MultiStats, Stats } from './stats';
import type { WebpackConfig } from './thirdParty';
import type { MaybePromise, NodeEnv } from './utils';
export type OnBeforeBuildFn = (params: {
bundlerConfigs?: B extends 'rspack' ? RspackConfig[] : WebpackConfig[];
}) => MaybePromise;
export type OnAfterBuildFn = (params: {
isFirstCompile: boolean;
stats?: Stats | MultiStats;
}) => MaybePromise;
export type OnCloseDevServerFn = () => MaybePromise;
export type OnDevCompileDoneFn = (params: {
isFirstCompile: boolean;
stats: Stats | MultiStats;
}) => MaybePromise;
export type OnBeforeStartDevServerFn = () => MaybePromise;
export type OnBeforeStartProdServerFn = () => MaybePromise;
export type Routes = Array<{
entryName: string;
pathname: string;
}>;
export type OnAfterStartDevServerFn = (params: {
port: number;
routes: Routes;
}) => MaybePromise;
export type OnAfterStartProdServerFn = (params: {
port: number;
routes: Routes;
}) => MaybePromise;
export type OnBeforeCreateCompilerFn = (params: {
bundlerConfigs: B extends 'rspack' ? RspackConfig[] : WebpackConfig[];
}) => MaybePromise;
export type OnAfterCreateCompilerFn = (params: {
compiler: Compiler;
}) => MaybePromise;
export type OnExitFn = () => void;
type HTMLTags = {
headTags: HtmlBasicTag[];
bodyTags: HtmlBasicTag[];
};
export type ModifyHTMLTagsContext = {
/**
* The Compilation object of Rspack.
*/
compilation: Rspack.Compilation;
/**
* URL prefix of assets.
* @example 'https://example.com/'
*/
assetPrefix: string;
/**
* The name of the HTML file, relative to the dist directory.
* @example 'index.html'
*/
filename: string;
};
export type ModifyHTMLTagsFn = (tags: HTMLTags, context: ModifyHTMLTagsContext) => MaybePromise;
export type ModifyRsbuildConfigUtils = {
/** Merge multiple Rsbuild config objects into one. */
mergeRsbuildConfig: (...configs: RsbuildConfig[]) => RsbuildConfig;
};
export type ModifyRsbuildConfigFn = (config: RsbuildConfig, utils: ModifyRsbuildConfigUtils) => MaybePromise;
export type ModifyChainUtils = {
env: NodeEnv;
isDev: boolean;
isProd: boolean;
target: RsbuildTarget;
isServer: boolean;
isServiceWorker: boolean;
isWebWorker: boolean;
CHAIN_ID: ChainIdentifier;
HtmlPlugin: typeof HtmlWebpackPlugin;
};
interface PluginInstance {
apply: (compiler: any) => void;
[k: string]: any;
}
export type ModifyBundlerChainUtils = ModifyChainUtils & {
bundler: {
BannerPlugin: PluginInstance;
DefinePlugin: PluginInstance;
IgnorePlugin: PluginInstance;
ProvidePlugin: PluginInstance;
HotModuleReplacementPlugin: PluginInstance;
};
};
export type ModifyBundlerChainFn = (chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise;
export type CreateAsyncHook any> = {
tap: (cb: Callback) => void;
call: (...args: Parameters) => Promise>;
};
export {};