2021-03-09 21:44:09 +01:00
|
|
|
import { defineConfig } from "vite";
|
|
|
|
import analyze from "rollup-plugin-analyzer";
|
|
|
|
import reactRefresh from "@vitejs/plugin-react-refresh";
|
|
|
|
import dotenv from "dotenv";
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
const useProxy = process.env.VITE_USE_PROXY;
|
|
|
|
const server = process.env.VITE_API_ENDPOINT;
|
|
|
|
const socketServer = process.env.VITE_SOCKET_URL;
|
2021-04-13 22:02:03 +02:00
|
|
|
const siteId = process.env.VITE_RICOCHET_SITEID;
|
2021-03-09 21:44:09 +01:00
|
|
|
|
|
|
|
const checkDeprecatedVars = () => {
|
|
|
|
const deprecatedVars = [
|
|
|
|
"API_ENDPOINT",
|
|
|
|
"SOCKET_URL",
|
|
|
|
"SOCKET_PATH",
|
|
|
|
"NO_WELCOME",
|
|
|
|
];
|
|
|
|
const toBeFixed = deprecatedVars.map((variable) => {
|
|
|
|
if (
|
|
|
|
process.env[`REACT_APP_${variable}`] &&
|
|
|
|
!process.env[`VITE_${variable}`]
|
|
|
|
) {
|
|
|
|
console.log(
|
|
|
|
`ERR! you have to migrate env variable REACT_APP_${variable} -> VITE_${variable}`
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
if (toBeFixed.some((v) => v)) {
|
|
|
|
console.log(
|
|
|
|
"ERR! Please fix error above to be able to start the server!\n\n"
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
checkDeprecatedVars();
|
|
|
|
|
|
|
|
let proxy = {};
|
|
|
|
|
|
|
|
if (useProxy) {
|
|
|
|
console.log("Proxy backend...");
|
|
|
|
proxy = {
|
|
|
|
server: {
|
|
|
|
proxy: {
|
|
|
|
"/socket.io": socketServer
|
|
|
|
.replace("https", "wss")
|
|
|
|
.replace("http", "ws"),
|
|
|
|
"/file": server,
|
2021-04-13 22:02:03 +02:00
|
|
|
[`/${siteId}`]: server,
|
2021-03-09 21:44:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [
|
|
|
|
reactRefresh(),
|
|
|
|
analyze({ summaryOnly: true, hideDeps: true, limit: 20 }),
|
|
|
|
],
|
|
|
|
...proxy,
|
|
|
|
});
|