generated from Sikessem/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
81 lines (76 loc) · 2.1 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
81
import fs from "node:fs";
import { homedir } from "node:os";
import { resolve } from "node:path";
import laravel, { refreshPaths } from "laravel-vite-plugin";
import { type ConfigEnv, ServerOptions, defineConfig, loadEnv } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(({ mode }: ConfigEnv) => {
const env = loadEnv(mode, process.cwd(), "");
const host = env.VITE_CONFIG_SERVER_HOST ?? "localhost";
const base = env.VITE_CONFIG_SERVER_BASE ?? "/";
const port = Number(env.VITE_CONFIG_SERVER_PORT ?? 4000);
const root = env.VITE_CONFIG_SERVER_ROOT;
const buildDirectory = env.VITE_CONFIG_BUILD_DIRECTORY ?? "static";
return {
server: detectServerConfig({ host, port, base }),
base,
root,
build: {
manifest: "manifest.json",
},
plugins: [
laravel({
input: [
"resources/designs/styles/app.css",
"resources/designs/scripts/app.ts",
],
refresh: [...refreshPaths, "templates/**", "app/Views/**"],
buildDirectory,
}),
tsconfigPaths(),
],
preview: {
headers: {
"Cache-Control": "public, max-age=600",
},
},
resolve: {
alias: {
"@assets": "resources/assets",
"@designs": "resources/designs",
"@images": "resources/assets/images",
"@scripts": "resources/designs/scripts",
"@styles": "resources/designs/styles",
"@types": "resources/designs/types",
},
},
};
});
function detectServerConfig(opts: {
host: string | undefined;
port: number | undefined;
base: string | undefined;
}): ServerOptions {
const keyPath = resolve(
homedir(),
`.config/valet/Certificates/${opts.host}.key`,
);
const certificatePath = resolve(
homedir(),
`.config/valet/Certificates/${opts.host}.crt`,
);
if (!fs.existsSync(keyPath) || !fs.existsSync(certificatePath)) {
return opts;
}
return {
hmr: {
host: opts.host,
port: opts.port,
},
https: {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certificatePath),
},
...opts,
};
}