forked from RetroAchievements/RAWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
80 lines (72 loc) · 1.92 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import { existsSync, readFileSync } from 'fs';
import { homedir } from 'os';
import { resolve } from 'path';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
if (!env.VITE_BUILD_PATH) {
throw Error('VITE_BUILD_PATH not set');
}
if (!env.APP_URL) {
throw Error('APP_URL not set');
}
return {
// https://vitejs.dev/config/#build-options
build: {
outDir: `public/${env.VITE_BUILD_PATH}`,
assetsDir: '',
assetsInlineLimit: 4096
},
// https://vitejs.dev/config/#plugins
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.ts',
],
refresh: [
'resources/views/**'
]
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './resources/js'),
},
},
// @ see https://vitejs.dev/config/#server-options
server: detectServerConfig(env),
};
});
function detectServerConfig(env) {
const watch = {
// Explicitly ignore large volume directories to prevent running into system-level limits
// See https://vitejs.dev/config/server-options.html#server-watch
ignored: [
'**/public/**',
'**/storage/**',
'**/vendor/**',
],
};
const { host } = new URL(env.APP_URL);
const keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`);
const certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`);
if (!existsSync(keyPath) || !existsSync(certificatePath)) {
// NOTE do not set host, it defaults to either localhost or 0.0.0.0 for Docker
return {
port: env.VITE_PORT,
watch,
};
}
return {
hmr: { host },
host,
port: env.VITE_PORT,
watch,
https: {
key: readFileSync(keyPath),
cert: readFileSync(certificatePath),
},
};
}