55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const versionFilePath = path.resolve(__dirname, "../VERSION");
|
|
let versionFromFile = "0.0.0";
|
|
|
|
try {
|
|
const raw = fs.readFileSync(versionFilePath, "utf8").trim();
|
|
if (raw) {
|
|
versionFromFile = raw;
|
|
}
|
|
} catch (error) {
|
|
console.warn("Unable to read VERSION file:", error);
|
|
}
|
|
|
|
const appVersion = process.env.VITE_APP_VERSION?.trim() || versionFromFile;
|
|
const buildLabel =
|
|
process.env.VITE_APP_BUILD_LABEL?.trim() || "local development build";
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ command }) => {
|
|
const nodeEnv =
|
|
process.env.NODE_ENV ||
|
|
(command === "build" ? "production" : "development");
|
|
const processEnvDefines = {
|
|
"process.env.IS_PREACT": JSON.stringify("false"),
|
|
"process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
};
|
|
|
|
return {
|
|
plugins: [react()],
|
|
define: {
|
|
...processEnvDefines,
|
|
"import.meta.env.VITE_APP_VERSION": JSON.stringify(appVersion),
|
|
"import.meta.env.VITE_APP_BUILD_LABEL": JSON.stringify(buildLabel),
|
|
},
|
|
optimizeDeps: {
|
|
esbuildOptions: {
|
|
define: processEnvDefines,
|
|
},
|
|
},
|
|
server: {
|
|
proxy: {
|
|
"/api": {
|
|
target: "http://localhost:8000",
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, ""),
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|