Repository navigation
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
62 lines (59 loc) · 1.67 KB
/
Copy pathelectron.vite.config.ts
File metadata and controls
62 lines (59 loc) · 1.67 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
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import type { Plugin } from 'vite'
/**
* Content-Security-Policy for the packaged renderer. Injected at build time
* only: the Vite dev server needs inline scripts (React refresh preamble) and
* a websocket for HMR, which this policy would block.
*
* - The renderer talks to the main process over IPC only; it fetches nothing
* remote (sentry-ipc: is @sentry/electron's renderer → main transport).
* - style-src needs 'unsafe-inline' for xterm.js and React style attributes.
* - Fonts are bundled via @fontsource (url() or inlined data: URIs).
*/
const RENDERER_CSP = [
"default-src 'self'",
"script-src 'self'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob:",
"font-src 'self' data:",
"connect-src 'self' sentry-ipc:",
"worker-src 'self' blob:",
"object-src 'none'",
"base-uri 'none'",
"form-action 'none'",
"frame-src 'none'",
].join('; ')
function cspPlugin(): Plugin {
return {
name: 'netcopilot-csp',
apply: 'build',
transformIndexHtml(html) {
return html.replace(
'<head>',
`<head>\n <meta http-equiv="Content-Security-Policy" content="${RENDERER_CSP}" />`
)
}
}
}
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
'@': resolve('src/renderer/src')
}
},
plugins: [react(), cspPlugin()],
css: {
postcss: './postcss.config.js'
}
}
})