-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
57 lines (45 loc) · 1.28 KB
/
vite.config.ts
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
import {defineConfig, loadEnv} from 'vite'
import laravel from 'laravel-vite-plugin'
import vuePlugin from '@vitejs/plugin-vue'
import * as fs from 'fs'
import {SecureServerOptions} from 'node:http2'
export default defineConfig(({mode}) => {
Object.assign(process.env, loadEnv(mode, process.cwd()))
return {
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.ts'],
refresh: true,
}),
vuePlugin(),
],
server: {
hmr: {
host: hmrHost(process.env?.VITE_SERVER_HMR_HOST),
},
host: serverHost(process.env?.VITE_SERVER_HOST),
https: serverHttps(process.env),
port: serverPort(process.env?.VITE_SERVER_PORT),
},
}
})
function hmrHost(host?: string): string {
return !!host ? host : 'localhost'
}
function serverHost(host?: string): string | boolean {
if (host === 'true') return true
if (typeof host === 'string') return host
return 'localhost'
}
function serverHttps(env: NodeJS.ProcessEnv): SecureServerOptions {
const {VITE_CERT, VITE_CERT_KEY, VITE_SERVER_HTTPS} = env
if (!VITE_CERT && !VITE_CERT_KEY) return {}
if (VITE_SERVER_HTTPS !== 'true') return {}
return {
cert: fs.readFileSync(VITE_CERT),
key: fs.readFileSync(VITE_CERT_KEY),
}
}
function serverPort(port?: string): number {
return port ? parseInt(port) : 24690
}