File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
packages/vite/src/node/server Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff line change @@ -85,11 +85,31 @@ const wsServerEvents = [
8585 'message' ,
8686]
8787
88+ function noop ( ) {
89+ // noop
90+ }
91+
8892export function createWebSocketServer (
8993 server : HttpServer | null ,
9094 config : ResolvedConfig ,
9195 httpsOptions ?: HttpsServerOptions ,
9296) : WebSocketServer {
97+ if ( config . server . ws === false ) {
98+ return {
99+ name : 'ws' ,
100+ get clients ( ) {
101+ return new Set < WebSocketClient > ( )
102+ } ,
103+ async close ( ) {
104+ // noop
105+ } ,
106+ on : noop as any as WebSocketServer [ 'on' ] ,
107+ off : noop as any as WebSocketServer [ 'off' ] ,
108+ listen : noop ,
109+ send : noop ,
110+ }
111+ }
112+
93113 let wss : WebSocketServerRaw_
94114 let wsHttpServer : Server | undefined = undefined
95115
You can’t perform that action at this time.
0 commit comments