Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add top-level functions to create platform-specific plugins #301

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions src/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,33 @@ export function createUnplugin<UserOptions, Nested extends boolean = boolean>(
},
}
}

export function creteEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return getEsbuildPlugin(factory)
}

export function creteRollupPlugin<UserOptions, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return getRollupPlugin(factory)
}

export function creteVitePlugin<UserOptions, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return getVitePlugin(factory)
}

export function creteWebpackPlugin<UserOptions, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return getWebpackPlugin(factory)
}

export function creteRspackPlugin<UserOptions, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return getRspackPlugin(factory)
}