Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
61 lines (57 loc) · 1.6 KB
/
Copy pathvite.config.js
File metadata and controls
61 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import tailwindcss from '@tailwindcss/vite';
import { execSync } from 'child_process';
import { readFileSync } from 'fs';
// Detect if building for Tauri (TAURI_ENV_PLATFORM is set during tauri build/dev)
const isTauri = process.env.TAURI_ENV_PLATFORM !== undefined;
// Get version from git tag or package.json
function getVersion() {
try {
return execSync('git describe --tags --always 2>/dev/null').toString().trim();
} catch {
// Fallback to package.json version
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
return pkg.version || 'dev';
}
}
const version = getVersion();
export default defineConfig({
root: '.',
// Use root path for Tauri, /msg-reader/ for GitHub Pages
base: isTauri ? '/' : '/msg-reader/',
publicDir: 'res',
plugins: [
tailwindcss(),
nodePolyfills({
include: ['buffer', 'stream', 'util', 'events', 'process'],
globals: {
Buffer: true,
process: true,
},
}),
{
name: 'html-version-replace',
transformIndexHtml(html) {
return html.replace(/__VERSION__/g, version);
},
},
],
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: 'index.html',
},
// Tauri needs ES modules, web build uses default
target: isTauri ? 'esnext' : 'es2020',
},
server: {
port: 8080,
// Don't auto-open browser for Tauri dev
open: !isTauri,
strictPort: true,
},
// Tauri needs to know about env variables
envPrefix: ['VITE_', 'TAURI_'],
});