diff --git a/ui/src/domain/version.ts b/ui/src/domain/version.ts
index 52668c80..a46438d0 100644
--- a/ui/src/domain/version.ts
+++ b/ui/src/domain/version.ts
@@ -1 +1,3 @@
-export const version = "v0.3.18";
+// .env > git tag > v0.0.0-beta
+// https://vite.dev/guide/env-and-mode.html#env-variables
+export const version = import.meta.env.VITE_APP_VERSION || __APP_VERSION__ || "v0.0.0-dev";
diff --git a/ui/types/vite-env.d.ts b/ui/types/vite-env.d.ts
index 11f02fe2..d5337f4c 100644
--- a/ui/types/vite-env.d.ts
+++ b/ui/types/vite-env.d.ts
@@ -1 +1,2 @@
///
+declare const __APP_VERSION__: string;
diff --git a/ui/vite.config.ts b/ui/vite.config.ts
index ce8b37d8..9ca80758 100644
--- a/ui/vite.config.ts
+++ b/ui/vite.config.ts
@@ -1,9 +1,10 @@
+import { type SpawnSyncReturns, execFileSync } from "node:child_process";
import path from "node:path";
import legacyPlugin from "@vitejs/plugin-legacy";
import reactPlugin from "@vitejs/plugin-react";
import fs from "fs-extra";
-import { type Plugin, defineConfig } from "vite";
+import { type Plugin, defineConfig, loadEnv } from "vite";
const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
return {
@@ -32,22 +33,40 @@ const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
};
};
-export default defineConfig({
- plugins: [
- reactPlugin({}),
- legacyPlugin({
- targets: ["defaults", "not IE 11"],
- }),
- preserveFilesPlugin(["dist/.gitkeep"]),
- ],
- resolve: {
- alias: {
- "@": path.resolve(__dirname, "./src"),
+export default defineConfig(({ mode }) => {
+ const envs = loadEnv(mode, process.cwd());
+ let appVersion = undefined;
+ if (!envs?.VITE_APP_VERSION) {
+ try {
+ appVersion = execFileSync("git", ["describe", "--match", "v[0-9]*", "--tags", "--abbrev=8"], {
+ stdio: [],
+ })?.toString();
+ } catch (error) {
+ const err = error as SpawnSyncReturns;
+ console.warn("[Warn] failed to get version number through git", err?.stderr?.toString());
+ }
+ }
+
+ return {
+ define: {
+ __APP_VERSION__: JSON.stringify(appVersion),
},
- },
- server: {
- proxy: {
- "/api": "http://127.0.0.1:8090",
+ plugins: [
+ reactPlugin({}),
+ legacyPlugin({
+ targets: ["defaults", "not IE 11"],
+ }),
+ preserveFilesPlugin(["dist/.gitkeep"]),
+ ],
+ resolve: {
+ alias: {
+ "@": path.resolve(__dirname, "./src"),
+ },
},
- },
+ server: {
+ proxy: {
+ "/api": "http://127.0.0.1:8090",
+ },
+ },
+ };
});