mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 01:11:55 +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" />
|
||||
declare const __APP_VERSION__: string;
|
||||
|
@ -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<Buffer>;
|
||||
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",
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user