Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
81 lines (77 loc) · 1.99 KB
/
Copy pathvite.config.ts
File metadata and controls
81 lines (77 loc) · 1.99 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
72
73
74
75
76
77
78
79
80
81
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { rm } from "node:fs/promises";
import { resolve } from "node:path";
import { fileURLToPath, URL } from "node:url";
import { defineConfig, type Plugin } from "vite";
function excludeBackendSource(): Plugin {
let output = "";
return {
name: "exclude-backend-source",
configResolved(config) {
output = resolve(config.root, config.build.outDir, "worker");
},
async closeBundle() {
await rm(output, { recursive: true, force: true });
},
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (/^\/worker(?:\/|\?|$)/.test(req.url ?? "")) {
res.statusCode = 404;
res.end("Not found");
return;
}
next();
});
},
};
}
const headers = {
"Content-Security-Policy": "frame-ancestors 'none'",
"X-Frame-Options": "DENY",
};
export default defineConfig(() => {
// Evaluated by Vite at build time, not when a visitor opens the page.
const buildTime = new Date().toISOString();
return {
plugins: [
react(),
tailwindcss(),
excludeBackendSource(),
{
name: "app-build-version",
generateBundle() {
this.emitFile({
type: "asset",
fileName: "app-version.json",
source: JSON.stringify({ build: buildTime }),
});
},
},
],
optimizeDeps: {
include: ["vaul", "@fingerprintjs/fingerprintjs"],
},
resolve: {
alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) },
},
define: {
"import.meta.env.VITE_BUILD_TIME": JSON.stringify(buildTime),
},
server: {
host: "127.0.0.1",
port: 5137,
hmr: { clientPort: 8787 },
strictPort: true,
open: false,
headers,
proxy: {
"/api": {
target: "http://127.0.0.1:8787",
changeOrigin: false,
},
},
},
preview: { headers },
};
});