-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
75 lines (73 loc) · 2.16 KB
/
vite.config.ts
File metadata and controls
75 lines (73 loc) · 2.16 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
import path from 'path'
import { readFileSync } from 'fs'
const { version } = JSON.parse(readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8'))
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(version),
// VITE_SERVER_URL: only set when frontend and API are on different origins (e.g. remote deploy).
// Leave unset in dev — vite proxies /api and /terminal to the Express server.
...(process.env.VITE_SERVER_URL
? { 'import.meta.env.VITE_SERVER_URL': JSON.stringify(process.env.VITE_SERVER_URL) }
: {}),
},
plugins: [
react(),
...(process.env.NODE_ENV === 'production'
? [
obfuscatorPlugin({
options: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.5,
deadCodeInjection: false,
stringArray: true,
stringArrayEncoding: ['rc4'],
stringArrayThreshold: 0.75,
renameGlobals: false,
selfDefending: true,
debugProtection: false,
disableConsoleOutput: false,
},
}),
]
: []),
],
root: 'src',
base: './',
publicDir: path.resolve(__dirname, 'public'),
build: {
outDir: '../build',
emptyOutDir: true,
rollupOptions: {
input: path.resolve(__dirname, 'src/index.html'),
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
server: {
port: 5173,
strictPort: true,
proxy: {
'/api': {
target: `http://localhost:${process.env.SERVER_PORT ?? '3001'}`,
changeOrigin: true,
bypass(req) {
// Don't proxy Vite HMR source files like /api/index.ts, /api/web.ts
if (req.url && /\.(ts|tsx|js|jsx|css|html|json|map)(\?|$)/.test(req.url)) {
return req.url
}
},
},
'/terminal': {
target: `ws://localhost:${process.env.SERVER_PORT ?? '3001'}`,
ws: true,
},
},
},
})