-
Notifications
You must be signed in to change notification settings - Fork 8
/
vite.config.ts
61 lines (56 loc) · 1.37 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
import path from "node:path";
import { defineConfig, type HtmlTagDescriptor, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
const csp: Record<string, string> = {
"default-src": "'self'",
"script-src": "'self'",
"img-src": "'self'",
"style-src": "'self'",
"connect-src": "'self' api:",
"object-src": "'none'",
"frame-src": "'none'",
};
const cspContent = Object.entries(csp)
.map(([k, v]) => `${k} ${v}`)
.join("; ");
const htmlCspPlugin: Plugin = {
name: "html-csp",
transformIndexHtml: {
order: "post",
handler: (_html, ctx): HtmlTagDescriptor[] => {
if (ctx.server?.config?.mode === "development") {
return [];
}
return [
{
injectTo: "head",
tag: "meta",
attrs: {
"http-equiv": "Content-Security-Policy",
content: cspContent,
},
},
];
},
},
};
// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
plugins: [react(), htmlCspPlugin],
server: {
port: 3433,
},
build: {
target: command === "build" ? "es2017" : "esnext",
sourcemap: command !== "build",
},
esbuild: {
target: command === "build" ? ["es2017", "safari11"] : undefined,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@assets": path.resolve(__dirname, "./assets"),
},
},
}));