forked from RetroAchievements/RAWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
94 lines (82 loc) · 2.25 KB
/
vite.config.js
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
84
85
86
87
88
89
90
91
92
93
94
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import livewire from '@defstudio/vite-livewire-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.js',
],
// https://laravel.com/docs/vite#working-with-blade-and-routes
// refresh: [{
// paths: [
// 'public/css/**',
// 'public/js/**',
// ],
// config: { delay: 300 }
// }],
refresh: false
}),
// livewire({
// refresh: ['resources/css/app.css'],
// }),
// https://vitejs.dev/guide/build.html#chunking-strategy
// splitVendorChunkPlugin(),
],
resolve: {
alias: {
'@': resolve(__dirname, './resources/js'),
},
},
// @ see https://vitejs.dev/config/#server-options
server: detectServerConfig(env),
};
});
// https://freek.dev/2276-making-vite-and-valet-play-nice-together
function detectServerConfig(env) {
const appUrl = new URL(env.APP_URL);
let { host } = appUrl;
// remove port - vite uses its own
if (host.startsWith('localhost')) {
host = 'localhost';
return {
hmr: { host },
host,
// port: env.VITE_PORT
};
}
const keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`);
const certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`);
const config = {
hmr: { host },
host,
port: env.VITE_PORT
};
if (!existsSync(keyPath) || !existsSync(certificatePath)) {
return config;
}
config.https = {
key: readFileSync(keyPath),
cert: readFileSync(certificatePath),
};
return config;
}