gitscope
← marzneshin / v0.5.3 / dashboard/vite.config.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/vite.config.ts · TypeScript
Blame Raw
 1import { defineConfig } from 'vite'
 2import react from '@vitejs/plugin-react-swc'
 3import { TanStackRouterVite } from '@tanstack/router-vite-plugin';
 4import tsconfigPaths from 'vite-tsconfig-paths';
 5import path from 'path';
 6import { execSync } from 'child_process';
 7
 8function checkTagIsHead(): boolean {
 9    try {
10        execSync('/usr/bin/git describe --tags --exact-match HEAD');
11        return true;
12    } catch (e) {
13        return false
14    }
15}
16
17export default defineConfig(({ mode }) => {
18    const dev = mode === "development";
19
20    let latestVersion = process.env.VITE_LATEST_APP_VERSION;
21
22    if (!latestVersion) {
23        try {
24            const isHead = checkTagIsHead()
25            latestVersion = dev || !isHead ?
26                execSync("/usr/bin/git describe --tags").toString().trimEnd() :
27                execSync("/usr/bin/git describe --tags --abbrev=0").toString().trimEnd();
28        } catch (e) {
29            console.error("Git versioning failed:", e);
30            latestVersion = "unknown";
31        }
32        process.env.VITE_LATEST_APP_VERSION = latestVersion;
33    }
34
35    return {
36        plugins: [
37            TanStackRouterVite(),
38            tsconfigPaths(),
39            react()
40        ],
41        root: '.',
42        build: {
43            assetsDir: 'static',
44            outDir: 'dist'
45        },
46        resolve: {
47            alias: [
48                {
49                    find: '@marzneshin',
50                    replacement: path.resolve(__dirname, './src/'),
51                },
52            ],
53        },
54    }
55})