Skip to content

Commit

Permalink
feat: added clientPort to HmrOptions (#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnysprinkles committed May 29, 2021
1 parent 472ba5d commit 7db69a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/config/index.md
Expand Up @@ -427,12 +427,14 @@ export default async ({ command, mode }) => {

### server.hmr

- **Type:** `boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean }`
- **Type:** `boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean, clientPort?: number }`

Disable or configure HMR connection (in cases where the HMR websocket must use a different address from the http server).

Set `server.hmr.overlay` to `false` to disable the server error overlay.

`clientPort` is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on. Useful if you're using an SSL proxy in front of your dev server.

### server.watch

- **Type:** `object`
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/node/plugins/clientInjections.ts
Expand Up @@ -25,10 +25,10 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {
const overlay = options.overlay !== false
let port
if (config.server.middlewareMode) {
port = String(
(typeof config.server.hmr === 'object' && config.server.hmr.port) ||
24678
)
if (typeof config.server.hmr === 'object') {
port = config.server.hmr.clientPort || config.server.hmr.port
}
port = String(port || 24678)
} else {
port = String(options.port || config.server.port!)
}
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/hmr.ts
Expand Up @@ -19,6 +19,7 @@ export interface HmrOptions {
protocol?: string
host?: string
port?: number
clientPort?: number
path?: string
timeout?: number
overlay?: boolean
Expand Down

0 comments on commit 7db69a3

Please sign in to comment.