-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathvite.config.ts
More file actions
77 lines (72 loc) · 1.76 KB
/
vite.config.ts
File metadata and controls
77 lines (72 loc) · 1.76 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { viteSingleFile } from 'vite-plugin-singlefile';
import path from 'path';
import { execSync } from 'child_process';
import fs from 'fs';
// Get version from environment, git tag, or package.json
function getVersion(): string {
// 1. Environment variable (set by GitHub Actions)
if (process.env.VERSION) {
return process.env.VERSION;
}
// 2. Try git tag
try {
const gitTag = execSync('git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo ""', { encoding: 'utf8' }).trim();
if (gitTag) {
return gitTag;
}
} catch {
// Git not available or no tags
}
// 3. Fall back to package.json version
try {
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8'));
if (pkg.version && pkg.version !== '0.0.0') {
return pkg.version;
}
} catch {
// package.json not readable
}
return 'dev';
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
viteSingleFile({
removeViteModuleLoader: true
})
],
define: {
__APP_VERSION__: JSON.stringify(getVersion())
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
css: {
modules: {
localsConvention: 'camelCase',
generateScopedName: '[name]__[local]___[hash:base64:5]'
},
preprocessorOptions: {
scss: {
additionalData: `@use "@/styles/variables.scss" as *;`
}
}
},
build: {
target: 'es2020',
outDir: 'dist',
assetsInlineLimit: 100000000,
chunkSizeWarningLimit: 100000000,
cssCodeSplit: false,
rolldownOptions: {
output: {
codeSplitting: false
}
}
}
});