vite.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { defineConfig } from "vite";
  2. import analyze from "rollup-plugin-analyzer";
  3. import reactRefresh from "@vitejs/plugin-react-refresh";
  4. import dotenv from "dotenv";
  5. dotenv.config();
  6. const useProxy = process.env.VITE_USE_PROXY;
  7. const server = process.env.VITE_API_ENDPOINT;
  8. const socketServer = process.env.VITE_SOCKET_URL;
  9. const siteId = process.env.VITE_RICOCHET_SITEID;
  10. const checkDeprecatedVars = () => {
  11. const deprecatedVars = [
  12. "API_ENDPOINT",
  13. "SOCKET_URL",
  14. "SOCKET_PATH",
  15. "NO_WELCOME",
  16. ];
  17. const toBeFixed = deprecatedVars.map((variable) => {
  18. if (
  19. process.env[`REACT_APP_${variable}`] &&
  20. !process.env[`VITE_${variable}`]
  21. ) {
  22. console.log(
  23. `ERR! you have to migrate env variable REACT_APP_${variable} -> VITE_${variable}`
  24. );
  25. return true;
  26. }
  27. return false;
  28. });
  29. if (toBeFixed.some((v) => v)) {
  30. console.log(
  31. "ERR! Please fix error above to be able to start the server!\n\n"
  32. );
  33. process.exit(1);
  34. }
  35. };
  36. checkDeprecatedVars();
  37. let proxy = {};
  38. if (useProxy) {
  39. console.log("Proxy backend...");
  40. proxy = {
  41. server: {
  42. proxy: {
  43. "/socket.io": socketServer
  44. .replace("https", "wss")
  45. .replace("http", "ws"),
  46. "/file": server,
  47. [`/${siteId}`]: server,
  48. },
  49. },
  50. };
  51. }
  52. // https://vitejs.dev/config/
  53. export default defineConfig({
  54. plugins: [
  55. reactRefresh(),
  56. analyze({ summaryOnly: true, hideDeps: true, limit: 20 }),
  57. ],
  58. ...proxy,
  59. });