Skip to content

Commit

Permalink
docs: update configurePreviewServer hook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erxclau authored and sapphi-red committed Mar 24, 2023
1 parent b68a3a9 commit 5cc04df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
32 changes: 32 additions & 0 deletions docs/guide/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,38 @@ import { preview } from 'vite'
})()
```

## `PreviewServer`

```ts
interface PreviewServer {
/**
* The resolved vite config object
*/
config: ResolvedConfig
/**
* A connect app instance.
* - Can be used to attach custom middlewares to the preview server.
* - Can also be used as the handler function of a custom http server
* or as a middleware in any connect-style Node.js frameworks
*
* https://github.com/senchalabs/connect#use-middleware
*/
middlewares: Connect.Server
/**
* native Node http server instance
*/
httpServer: http.Server
/**
* The resolved urls Vite prints on the CLI
*/
resolvedUrls: ResolvedServerUrls
/**
* Print server urls
*/
printUrls(): void
}
```

## `resolveConfig`

**Type Signature:**
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo

### `configurePreviewServer`

- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>`
- **Type:** `(server: PreviewServer) => (() => void) | void | Promise<(() => void) | void>`
- **Kind:** `async`, `sequential`
- **See also:** [PreviewServer](./api-javascript#previewserver)

Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. It provides the [connect](https://github.com/senchalabs/connect) server and its underlying [http server](https://nodejs.org/api/http.html). Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed:
Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed:

```js
const myPlugin = () => ({
Expand Down

0 comments on commit 5cc04df

Please sign in to comment.