Files
XCTerminal/vite.config.ts

50 lines
1.0 KiB
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import fs from 'node:fs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const PORT_FILE = '.terminal-server-port'
function getTerminalApiUrl() {
if (process.env.TERMINAL_API_URL) {
return process.env.TERMINAL_API_URL
}
try {
if (fs.existsSync(PORT_FILE)) {
const port = fs.readFileSync(PORT_FILE, 'utf-8').trim()
return `http://localhost:${port}`
}
} catch {}
return 'http://localhost:3002'
}
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
base: './',
build: {
outDir: 'dist',
emptyOutDir: true,
},
define: {
'process.env': {},
global: 'globalThis',
},
server: {
proxy: {
'/api': {
target: getTerminalApiUrl(),
changeOrigin: true,
ws: true,
rewrite: (path) => path,
},
},
},
})