Files
P2Pix-Front-End/vite.config.ts

59 lines
1.4 KiB
TypeScript

import { fileURLToPath, URL } from "node:url";
import { execSync } from "node:child_process";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import svgLoader from "vite-svg-loader";
function sh(cmd: string): string {
try {
return execSync(cmd, { stdio: ["ignore", "pipe", "ignore"] })
.toString()
.trim();
} catch {
return "";
}
}
function getAppVersion(): string {
const tag = sh("git tag --sort=-version:refname").split("\n")[0] || "";
const shortSha = sh("git rev-parse --short HEAD");
const tagSha = tag ? sh(`git rev-list -n 1 ${tag}`) : "";
const headSha = sh("git rev-parse HEAD");
if (tag && tagSha === headSha) return tag;
if (tag && shortSha) return `${tag}+${shortSha}`;
return shortSha || "dev";
}
// https://vitejs.dev/config/
export default defineConfig({
base: "./",
build: {
target: "esnext",
},
define: {
__APP_VERSION__: JSON.stringify(getAppVersion()),
},
optimizeDeps: {
esbuildOptions: {
target: "esnext",
define: {
global: "globalThis",
},
supported: {
bigint: true,
},
},
},
plugins: [vue(), vueJsx(), svgLoader()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
"viem/errors": fileURLToPath(
new URL("./node_modules/viem/errors", import.meta.url),
),
},
},
});