Type support for plugins
Is your feature request related to a problem? Please describe. Plugin install functions are missing types.
import { createServer } from 'vite'
// Hacky, bad idea
type PluginOptions = {
root: string,
app: any,
server: any,
watcher: any
}
const myPlugin = ({
root,
app,
server,
watcher
}: PluginOptions) => {
// do plugin-y things here
}
createServer({
plugins: [myPlugin],
}).listen(3000)
I first ended up writing a hacky shim like the above and then eventually figured out koa's type situation (they have a few fragmented @types packages)
Describe the solution you'd like A better DX. Can we ship some types for the plugin install function?
Additional context
I'm unsure how 3rd party type interop is supposed to work. Is it even Vite's job to provide a PluginOptions
type that contains Koa and Chokidar types? 🤔
Use the ServerPlugin type
Oh I found it. It's ServerPluginContext.
Thank you!