mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 09:21:56 +08:00
build(ui): define version constant
This commit is contained in:
parent
2aac79af54
commit
14a3f055ee
@ -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";
|
||||||
|
1
ui/types/vite-env.d.ts
vendored
1
ui/types/vite-env.d.ts
vendored
@ -1 +1,2 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
declare const __APP_VERSION__: string;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
import { type SpawnSyncReturns, execFileSync } from "node:child_process";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
import legacyPlugin from "@vitejs/plugin-legacy";
|
import legacyPlugin from "@vitejs/plugin-legacy";
|
||||||
import reactPlugin from "@vitejs/plugin-react";
|
import reactPlugin from "@vitejs/plugin-react";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { type Plugin, defineConfig } from "vite";
|
import { type Plugin, defineConfig, loadEnv } from "vite";
|
||||||
|
|
||||||
const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
||||||
return {
|
return {
|
||||||
@ -32,22 +33,40 @@ const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
plugins: [
|
const envs = loadEnv(mode, process.cwd());
|
||||||
reactPlugin({}),
|
let appVersion = undefined;
|
||||||
legacyPlugin({
|
if (!envs?.VITE_APP_VERSION) {
|
||||||
targets: ["defaults", "not IE 11"],
|
try {
|
||||||
}),
|
appVersion = execFileSync("git", ["describe", "--match", "v[0-9]*", "--tags", "--abbrev=8"], {
|
||||||
preserveFilesPlugin(["dist/.gitkeep"]),
|
stdio: [],
|
||||||
],
|
})?.toString();
|
||||||
resolve: {
|
} catch (error) {
|
||||||
alias: {
|
const err = error as SpawnSyncReturns<Buffer>;
|
||||||
"@": path.resolve(__dirname, "./src"),
|
console.warn("[Warn] failed to get version number through git", err?.stderr?.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
define: {
|
||||||
|
__APP_VERSION__: JSON.stringify(appVersion),
|
||||||
},
|
},
|
||||||
},
|
plugins: [
|
||||||
server: {
|
reactPlugin({}),
|
||||||
proxy: {
|
legacyPlugin({
|
||||||
"/api": "http://127.0.0.1:8090",
|
targets: ["defaults", "not IE 11"],
|
||||||
|
}),
|
||||||
|
preserveFilesPlugin(["dist/.gitkeep"]),
|
||||||
|
],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
|
proxy: {
|
||||||
|
"/api": "http://127.0.0.1:8090",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user