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

Type support for plugins #138

Closed
JessicaSachs opened this issue May 14, 2020 · 2 comments
Closed

Type support for plugins #138

JessicaSachs opened this issue May 14, 2020 · 2 comments

Comments

@JessicaSachs
Copy link
Contributor

JessicaSachs commented May 14, 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? 🤔

@yyx990803
Copy link
Member

yyx990803 commented May 14, 2020

Use the ServerPlugin type

@JessicaSachs
Copy link
Contributor Author

JessicaSachs commented May 14, 2020

Oh I found it. It's ServerPluginContext.

Thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants