From fc4d00e5e22aafdc9c3c9452b8266c3f1909f83c Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 26 Apr 2023 13:24:24 +0200 Subject: [PATCH 1/3] feat: add top-level functions to create platform-specific plugins --- src/define.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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) +} From 2041690c2c2655f9157bc7d8934e156b236e3a39 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 26 Apr 2023 15:50:40 +0200 Subject: [PATCH 2/3] add docs --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 049bade2..905a4aa3 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 { + getVitePlugin, + getRollupPlugin, + getWebpackPlugin, + creteEsbuildPlugin, + getRspackPlugin +} 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. From 4c03066a3737677468c794a2add6d0213902556d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 26 Apr 2023 15:55:05 +0200 Subject: [PATCH 3/3] lint --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 905a4aa3..5fe0c136 100644 --- a/README.md +++ b/README.md @@ -232,18 +232,18 @@ Each of the function takes the same generic factory argument as `createUnplugin` ```ts import { - getVitePlugin, - getRollupPlugin, - getWebpackPlugin, creteEsbuildPlugin, - getRspackPlugin -} from "unplugin"; - -const vitePlugin = getVitePlugin({ /* options */ }); -const rollupPlugin = getRollupPlugin({ /* options */ }); -const esbuildPlugin = creteEsbuildPlugin({ /* options */ }); -const webpackPlugin = getWebpackPlugin({ /* options */ }); -const rspackPlugin = getRspackPlugin({ /* options */ }); + 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