Subscribe on changes!

Type support for plugins

avatar
May 14th 2020

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? 🤔

avatar
May 14th 2020

Use the ServerPlugin type

avatar
May 14th 2020

Oh I found it. It's ServerPluginContext.

Thank you!