Feature: define multiple sub-plugin in one plugin
soc221b opened this issue Β· comments
Hi, thanks for the useful plugins. π
I'm creating an unplugin
library that requires unplugin-auto-import
and other features.
In the current API we have to do this:
import AutoImport from 'unplugin-auto-import/vite'
export default createUnplugin(
(userConfig, meta) => {
const autoImport = AutoImport()
return {
name: 'my-unplugin',
async buildStart() {
await autoImport.buildStart!.call(this)
},
transformInclude(id) {
return autoImport.transformInclude!(id)
},
It would be great if we could write it like this:
import AutoImport from 'unplugin-auto-import/vite'
export default createUnplugin(
(userConfig, meta) => {
return [
AutoImport(),
{
name: 'my-unplugin',
...
}
]
Hey @iendeavor, we have already been discussing a few ways of making these plugins more extensible (in #171). I like your idea of being able to create a new plugin within another (this ensures the plugin always exists). I have combined our past discussion with your suggestion and have created a new proposal for extensible plugins (#174 if you want to check it out). This includes defining a custom API and using it in another plugin, as well as making sure an instance of a plugin always exist for you to be able to use it's API.
While I think this is a nice feature to have. I am not sure if it's possible to support all bundlers (Rollup for example). Maybe we should send requests to upstream repos, to have all bundler support plugins array before moving this in unplugin.
Also linking a community solution for reference: