forked from aws/amazon-q-developer-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
99 lines (93 loc) · 2.25 KB
/
vite.config.ts
File metadata and controls
99 lines (93 loc) · 2.25 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {
defineConfig,
loadEnv,
type Plugin,
type HtmlTagDescriptor,
} from "vite";
import react from "@vitejs/plugin-react";
// import legacy from "@vitejs/plugin-legacy";
const csp: Record<string, string> = {
"default-src": "'self'",
// blob: is needed for loading dev specs
"script-src": "'self' spec: blob:",
"style-src": "'self' spec:",
"img-src": "'self' data: fig: icon: https:",
"connect-src": "'self' spec: 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(({ mode, command }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd(), "") };
return {
plugins: [
react(),
htmlCspPlugin,
// legacy({
// targets: [
// "safari >= 11",
// "last 3 Chrome version",
// "last 3 Firefox version",
// ],
// }),
],
css: {
modules: {
localsConvention: "camelCaseOnly",
},
},
server: {
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 3124,
strictPort: true,
},
build: {
target: command === "build" ? "es2017" : "esnext",
// TODO: re-enable prod source maps to upload them to sentry (see build CIs)
sourcemap: command !== "build",
rollupOptions: {
external: [
"?type=option",
"?type=carrot",
"?type=command",
"?type=box",
],
},
},
define: {
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
"process.env": {},
},
esbuild: {
target: command === "build" ? ["es2017", "safari11"] : undefined,
},
resolve: {
alias: {
util: "util",
},
},
};
});