Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
41 lines (38 loc) · 1.58 KB
/
Copy pathvite.config.ts
File metadata and controls
41 lines (38 loc) · 1.58 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
import { readFileSync } from 'node:fs'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { adminAuthPlugin } from './server/vite-plugin'
// Version shown in the UI. CI passes APP_VERSION from the git tag (e.g. "1.0.1")
// via `--build-arg APP_VERSION=...` so Docker builds always match the release.
// Falls back to package.json for local dev builds.
const pkgVersion = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
).version as string
const appVersion = process.env.APP_VERSION || pkgVersion
export default defineConfig(({ mode }) => {
// The admin auth + proxy handlers read server-only env vars
// (ADMIN_PASSWORD, ADMIN_SESSION_SECRET, ADMIN_AUTH_DISABLED,
// STATEWAVE_API_URL, STATEWAVE_API_KEY, …) via process.env. Vite's
// built-in .env loading only exposes VITE_* to the client bundle and
// does NOT populate process.env for non-prefixed names. Explicitly
// load every non-prefixed key from .env / .env.local / .env.<mode>
// so `npm run dev` honors the same files the standalone Node server
// honors when launched via `node --env-file=.env.local`.
const fileEnv = loadEnv(mode, process.cwd(), '')
for (const [k, v] of Object.entries(fileEnv)) {
if (k.startsWith('VITE_')) continue
if (process.env[k] === undefined) process.env[k] = v
}
return {
plugins: [react(), tailwindcss(), adminAuthPlugin()],
define: {
__ADMIN_VERSION__: JSON.stringify(appVersion),
},
resolve: {
alias: {
'@': '/src',
},
},
}
})