-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathvite.config.tauri.ts
More file actions
83 lines (74 loc) · 2.33 KB
/
Copy pathvite.config.tauri.ts
File metadata and controls
83 lines (74 loc) · 2.33 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
78
79
80
81
82
83
import { createRequire } from 'node:module'
import path from 'node:path'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'
import pkg from './package.json' with { type: 'json' }
// Resolve the material-icon-theme icons directory via Node module resolution
// instead of a hardcoded node_modules path, so it works under hoisted,
// monorepo, or custom-resolve setups.
const require = createRequire(import.meta.url)
const materialIconsDir = path.join(
path.dirname(require.resolve('material-icon-theme/package.json')),
'icons'
)
const host = process.env.TAURI_DEV_HOST
// Dev server port. Override with TAURI_DEV_PORT (must match devUrl in
// src-tauri/tauri.conf.json, or pass a matching --config override to tauri).
// Validate the env value: must be an integer in the valid TCP port range,
// else fall back to the default and warn.
function resolveDevPort(): number {
const fallback = 5180
const raw = process.env.TAURI_DEV_PORT
if (raw === undefined || raw === '') return fallback
const parsed = Number(raw)
if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
console.warn(`[vite] Invalid TAURI_DEV_PORT="${raw}"; falling back to ${fallback}.`)
return fallback
}
return parsed
}
const devPort = resolveDevPort()
// Keep the HMR port within range even at the boundary.
const hmrPort = devPort < 65535 ? devPort + 1 : devPort - 1
export default defineConfig({
root: './',
base: '/',
plugins: [react()],
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'src/renderer')}/`,
'@renderer/': `${path.resolve(__dirname, 'src/renderer')}/`,
'@shared/': `${path.resolve(__dirname, 'src/shared')}/`,
'@material-icons/': `${materialIconsDir}/`
}
},
define: {
'import.meta.env.PACKAGE_VERSION': JSON.stringify(pkg.version)
},
// Vite dev server config for Tauri
server: {
port: devPort,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: 'ws',
host,
port: hmrPort
}
: undefined,
watch: {
ignored: ['**/src-tauri/**']
}
},
build: {
outDir: 'dist-tauri',
emptyOutDir: true,
rolldownOptions: {
input: path.resolve(__dirname, 'tauri-index.html')
},
target: 'esnext'
},
// Env prefix for Tauri
envPrefix: ['VITE_', 'TAURI_ENV_*']
})