diff --git a/README.md b/README.md index 049bade2..5fe0c136 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,27 @@ export const unplugin = createUnplugin((options: UserOptions, meta) => { }) ``` +### Creating platform specific plugins + +The package exports a set of functions in place of `createUnplugin` that allow for the creation of plugins for specific bundlers. +Each of the function takes the same generic factory argument as `createUnplugin`. + +```ts +import { + creteEsbuildPlugin, + getRollupPlugin, + getRspackPlugin, + getVitePlugin, + getWebpackPlugin +} from 'unplugin' + +const vitePlugin = getVitePlugin({ /* options */ }) +const rollupPlugin = getRollupPlugin({ /* options */ }) +const esbuildPlugin = creteEsbuildPlugin({ /* options */ }) +const webpackPlugin = getWebpackPlugin({ /* options */ }) +const rspackPlugin = getRspackPlugin({ /* options */ }) +``` + ## Conventions - Plugins powered by unplugin should have a clear name with `unplugin-` prefix. diff --git a/src/define.ts b/src/define.ts index 2bed0a04..a94c139e 100644 --- a/src/define.ts +++ b/src/define.ts @@ -30,3 +30,33 @@ export function createUnplugin( }, } } + +export function creteEsbuildPlugin( + factory: UnpluginFactory, +) { + return getEsbuildPlugin(factory) +} + +export function creteRollupPlugin( + factory: UnpluginFactory, +) { + return getRollupPlugin(factory) +} + +export function creteVitePlugin( + factory: UnpluginFactory, +) { + return getVitePlugin(factory) +} + +export function creteWebpackPlugin( + factory: UnpluginFactory, +) { + return getWebpackPlugin(factory) +} + +export function creteRspackPlugin( + factory: UnpluginFactory, +) { + return getRspackPlugin(factory) +}