You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disable or configure HMR connection (in cases where the HMR websocket must use a different address from the http server).
186
+
Disable or configure HMR behavior.
187
187
188
188
Set `server.hmr.overlay` to `false` to disable the server error overlay.
189
189
190
-
`protocol` sets the WebSocket protocol used for the HMR connection: `ws` (WebSocket) or `wss` (WebSocket Secure).
190
+
::: warning Deprecated Options
191
191
192
-
`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.
192
+
The WebSocket-related options (`protocol`, `host`, `port`, `path`, `clientPort`, `timeout`, `server`) are deprecated. Use [`server.ws`](#server-ws) instead. These options are automatically synced, so existing configurations will continue to work.
193
193
194
-
When `server.hmr.server` is defined, Vite will process the HMR connection requests through the provided server. If not in middleware mode, Vite will attempt to process HMR connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
Configure WebSocket connection options. Set to `false` to disable the WebSocket connection entirely.
201
+
202
+
-`protocol` - WebSocket protocol (`ws` or `wss`)
203
+
-`host` - WebSocket server host
204
+
-`port` - WebSocket server port
205
+
-`path` - WebSocket path
206
+
-`clientPort` - Override the port on the client side, allowing you to serve the websocket on a different port than the client code looks for it on
207
+
-`timeout` - Connection timeout in milliseconds (default: 30000)
208
+
-`server` - Use a custom HTTP server for WebSocket connections
209
+
210
+
When `server.ws.server` is defined, Vite will process the WebSocket connection requests through the provided server. If not in middleware mode, Vite will attempt to process WebSocket connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
211
+
212
+
```js
213
+
exportdefaultdefineConfig({
214
+
server: {
215
+
ws: {
216
+
protocol:'wss',
217
+
host:'localhost',
218
+
port:3001,
219
+
},
220
+
},
221
+
})
222
+
```
195
223
196
224
Check out [`vite-setup-catalogue`](https://github.com/sapphi-red/vite-setup-catalogue) for some examples.
197
225
@@ -200,14 +228,14 @@ Check out [`vite-setup-catalogue`](https://github.com/sapphi-red/vite-setup-cata
200
228
With the default configuration, reverse proxies in front of Vite are expected to support proxying WebSocket. If the Vite HMR client fails to connect WebSocket, the client will fall back to connecting the WebSocket directly to the Vite HMR server bypassing the reverse proxies:
201
229
202
230
```
203
-
Direct websocket connection fallback. Check out https://vite.dev/config/server-options.html#server-hmr to remove the previous connection error.
231
+
Direct websocket connection fallback. Check out https://vite.dev/config/server-options.html#server-ws to remove the previous connection error.
204
232
```
205
233
206
234
The error that appears in the Browser when the fallback happens can be ignored. To avoid the error by directly bypassing reverse proxies, you could either:
207
235
208
236
- configure the reverse proxy to proxy WebSocket too
209
-
- set [`server.strictPort = true`](#server-strictport) and set `server.hmr.clientPort` to the same value with `server.port`
210
-
- set `server.hmr.port` to a different value from [`server.port`](#server-port)
237
+
- set [`server.strictPort = true`](#server-strictport) and set `server.ws.clientPort` to the same value with `server.port`
238
+
- set `server.ws.port` to a different value from [`server.port`](#server-port)
0 commit comments