Move env vars to vite config

This commit is contained in:
Evan Simkowitz 2024-09-19 12:37:16 -07:00
parent 839889ba63
commit 708af7efde
No known key found for this signature in database
2 changed files with 10 additions and 7 deletions

View File

@ -26,6 +26,10 @@ export default defineConfig({
"@": "frontend",
},
},
define: {
"process.env.WS_NO_BUFFER_UTIL": "true",
"process.env.WS_NO_UTF_8_VALIDATE": "true",
},
},
preload: {
root: ".",

View File

@ -3,13 +3,12 @@ import type { WebSocket as NodeWebSocketType } from "ws";
let NodeWebSocket: typeof NodeWebSocketType = null;
if (typeof window === "undefined") {
try {
// Necessary to avoid issues with Rollup: https://github.com/websockets/ws/issues/2057
process.env.WS_NO_BUFFER_UTIL = "1";
import("ws").then((ws) => (NodeWebSocket = ws.default));
} catch (error) {
console.log("Error importing 'ws':", error);
}
// Necessary to avoid issues with Rollup: https://github.com/websockets/ws/issues/2057
import("ws")
.then((ws) => (NodeWebSocket = ws.default))
.catch((e) => {
console.log("Error importing 'ws':", e);
});
}
type ComboWebSocket = NodeWebSocketType | WebSocket;