Skip to content

Commit 14b5ced

Browse files
authored
feat: add an option to not start a websocket server (#16219)
1 parent e861168 commit 14b5ced

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎packages/vite/src/node/server/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ export interface ServerOptions extends CommonServerOptions {
101101
* Configure HMR-specific options (port, host, path & protocol)
102102
*/
103103
hmr?: HmrOptions|boolean
104+
/**
105+
* Do not start the websocket connection.
106+
* @experimental
107+
*/
108+
ws?: false
104109
/**
105110
* Warm-up files to transform and cache the results in advance. This improves the
106111
* initial page load during server starts and prevents transform waterfalls.

‎packages/vite/src/node/server/ws.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,31 @@ const wsServerEvents = [
8585
'message',
8686
]
8787

88+
functionnoop(){
89+
// noop
90+
}
91+
8892
exportfunctioncreateWebSocketServer(
8993
server: HttpServer|null,
9094
config: ResolvedConfig,
9195
httpsOptions?: HttpsServerOptions,
9296
): WebSocketServer{
97+
if(config.server.ws===false){
98+
return{
99+
name: 'ws',
100+
getclients(){
101+
returnnewSet<WebSocketClient>()
102+
},
103+
asyncclose(){
104+
// noop
105+
},
106+
on: noopasanyasWebSocketServer['on'],
107+
off: noopasanyasWebSocketServer['off'],
108+
listen: noop,
109+
send: noop,
110+
}
111+
}
112+
93113
letwss: WebSocketServerRaw_
94114
letwsHttpServer: Server|undefined=undefined
95115

0 commit comments

Comments
 (0)