Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
71 lines (62 loc) · 1.72 KB
/
Copy pathvite.config.js
File metadata and controls
71 lines (62 loc) · 1.72 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
import fs from 'fs';
import { defineConfig, loadEnv } from "vite";
import { homedir } from "os";
import { resolve } from "path";
import laravel from "laravel-vite-plugin";
export default ({ mode }) => defineConfig({
plugins: [
laravel([
'resources/css/app.css',
'resources/js/app.js',
'resources/js/chart-tooltip.js',
'resources/js/webhooks.js',
]),
],
resolve: {
alias: {
"@ui": resolve(
__dirname,
"vendor/arkecosystem/foundation/resources/assets/"
),
},
},
server: detectServerConfig(mode) || {
host: loadEnv(mode, process.cwd()).VITE_HOST ?? 'localhost',
port: 3000,
},
});
function getValetHome() {
let valetPath = resolve(homedir(), '.config/valet');
if (fs.existsSync(valetPath)) {
return valetPath;
}
valetPath = resolve(homedir(), '.valet');
if (fs.existsSync(valetPath)) {
return valetPath;
}
return null;
}
// Variation of https://freek.dev/2276-making-vite-and-valet-play-nice-together
function detectServerConfig(mode) {
const valetPath = getValetHome();
if (!valetPath) {
return;
}
const host = loadEnv(mode, process.cwd()).VITE_HOST ?? 'localhost';
let keyPath = resolve(valetPath, `Certificates/${host}.key`);
let certificatePath = resolve(valetPath, `Certificates/${host}.crt`);
if (!fs.existsSync(keyPath)) {
return;
}
if (!fs.existsSync(certificatePath)) {
return;
}
return {
host,
port: 3000,
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certificatePath),
},
};
}