Commit 14b5ced 1 parent e861168 commit 14b5ced Copy full SHA for 14b5ced
File tree 2 files changed +25
-0
lines changed
packages/vite/src/node/server
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 {
101
101
* Configure HMR-specific options (port, host, path & protocol)
102
102
*/
103
103
hmr ?: HmrOptions | boolean
104
+ /**
105
+ * Do not start the websocket connection.
106
+ * @experimental
107
+ */
108
+ ws ?: false
104
109
/**
105
110
* Warm-up files to transform and cache the results in advance. This improves the
106
111
* 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 = [
85
85
'message' ,
86
86
]
87
87
88
+ function noop ( ) {
89
+ // noop
90
+ }
91
+
88
92
export function createWebSocketServer (
89
93
server : HttpServer | null ,
90
94
config : ResolvedConfig ,
91
95
httpsOptions ?: HttpsServerOptions ,
92
96
) : 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
+
93
113
let wss : WebSocketServerRaw_
94
114
let wsHttpServer : Server | undefined = undefined
95
115
You can’t perform that action at this time.
0 commit comments