diff --git a/.changeset/honest-yaks-tan.md b/.changeset/honest-yaks-tan.md new file mode 100644 index 000000000000..0cff6de29ac8 --- /dev/null +++ b/.changeset/honest-yaks-tan.md @@ -0,0 +1,5 @@ +--- +"@rspack/cli": patch +--- + +add definePlugin helper diff --git a/packages/rspack-cli/src/index.ts b/packages/rspack-cli/src/index.ts index d3630fc3ca51..64d35df36e0e 100644 --- a/packages/rspack-cli/src/index.ts +++ b/packages/rspack-cli/src/index.ts @@ -1,2 +1,2 @@ export * from "./types"; -export { RspackCLI, defineConfig } from "./rspack-cli"; +export { RspackCLI, defineConfig, definePlugin } from "./rspack-cli"; diff --git a/packages/rspack-cli/src/rspack-cli.ts b/packages/rspack-cli/src/rspack-cli.ts index 73f8ad6d40b4..6cd1b9683e14 100644 --- a/packages/rspack-cli/src/rspack-cli.ts +++ b/packages/rspack-cli/src/rspack-cli.ts @@ -16,6 +16,7 @@ import { import { normalizeEnv } from "./utils/options"; import { loadRspackConfig } from "./utils/loadConfig"; import { Mode } from "@rspack/core/src/config"; +import { RspackPluginInstance, RspackPluginFunction } from "@rspack/core"; type RspackEnv = "development" | "production"; export class RspackCLI { @@ -252,3 +253,10 @@ export class RspackCLI { export function defineConfig(config: RspackOptions): RspackOptions { return config; } + +// Note: use union type will make apply function's `compiler` type to be `any` +export function definePlugin(plugin: RspackPluginFunction): RspackPluginFunction +export function definePlugin(plugin: RspackPluginInstance): RspackPluginInstance +export function definePlugin(plugin: any): any { + return plugin; +}