-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvite.renderer.config.ts
More file actions
70 lines (66 loc) · 1.95 KB
/
Copy pathvite.renderer.config.ts
File metadata and controls
70 lines (66 loc) · 1.95 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
import type { ConfigEnv, Plugin, UserConfig } from "vite";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { pluginExposeRenderer } from "./vite.base.config";
const getContentSecurityPolicy = (isDevelopment: boolean) =>
[
"default-src 'self'",
`script-src 'self'${isDevelopment ? " 'unsafe-inline'" : ""}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: screenshot:",
"font-src 'self' data:",
"media-src 'self' http://localhost:* http://127.0.0.1:* recording:",
"connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:*",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
].join("; ");
const contentSecurityPolicyPlugin = (
contentSecurityPolicy: string,
injectMetaTag: boolean,
): Plugin => ({
name: "pensieve-content-security-policy",
transformIndexHtml: () =>
injectMetaTag
? [
{
tag: "meta",
attrs: {
"http-equiv": "Content-Security-Policy",
content: contentSecurityPolicy,
},
injectTo: "head-prepend",
},
]
: [],
});
// https://vitejs.dev/config
export default defineConfig((env) => {
const forgeEnv = env as ConfigEnv<"renderer">;
const { root, mode, command, forgeConfigSelf } = forgeEnv;
const name = forgeConfigSelf.name ?? "";
const isDevelopment = command === "serve";
const contentSecurityPolicy = getContentSecurityPolicy(command === "serve");
return {
root,
mode,
base: "./",
build: {
outDir: `.vite/renderer/${name}`,
},
plugins: [
contentSecurityPolicyPlugin(contentSecurityPolicy, !isDevelopment),
pluginExposeRenderer(name),
react(),
],
resolve: {
preserveSymlinks: true,
},
server: {
headers: {
"Content-Security-Policy": contentSecurityPolicy,
},
},
clearScreen: false,
} as UserConfig;
});