Skip to content

Commit

Permalink
feat: add top-level functions to create platform-specific plugins (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored May 16, 2023
1 parent 127616d commit efbbba5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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)
}

0 comments on commit efbbba5

Please sign in to comment.