97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'path';
|
|
import { readFileSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const frontendRoot = path.resolve(__dirname, '../frontend/src');
|
|
const sharedRoot = path.resolve(__dirname, '../packages/shared/src');
|
|
|
|
const host = process.env.TAURI_DEV_HOST;
|
|
|
|
function readDesktopAppVersion(): string {
|
|
try {
|
|
const confPath = path.resolve(__dirname, 'src-tauri/tauri.conf.json');
|
|
const conf = JSON.parse(readFileSync(confPath, 'utf8')) as { version?: string };
|
|
return String(conf.version ?? '0.0.0');
|
|
} catch {
|
|
return '0.0.0';
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
/** Tauri 패키지 앱 — 절대 경로(/assets) 사용 시 빈 화면 */
|
|
base: './',
|
|
/** sockjs-client 등 Node 전역 참조 — Tauri WebView에는 global 없음 */
|
|
define: {
|
|
global: 'globalThis',
|
|
/** desktop은 항상 exdev 서버 (localhost 금지) */
|
|
'import.meta.env.VITE_API_BASE_URL': JSON.stringify('http://exdev.co.kr/api'),
|
|
__DESKTOP_CLIENT__: 'true',
|
|
__DESKTOP_APP_VERSION__: JSON.stringify(readDesktopAppVersion()),
|
|
},
|
|
envDir: __dirname,
|
|
plugins: [react()],
|
|
resolve: {
|
|
dedupe: ['react', 'react-dom', 'lightweight-charts'],
|
|
alias: {
|
|
'@goldenchart/shared': sharedRoot,
|
|
'@frontend': frontendRoot,
|
|
'@frontend/utils/backendApi': path.resolve(sharedRoot, 'api/backendApi.ts'),
|
|
[path.resolve(frontendRoot, 'utils/backendApi.ts')]: path.resolve(
|
|
sharedRoot,
|
|
'api/backendApi.ts',
|
|
),
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
include: ['react', 'react-dom', '@stomp/stompjs', 'sockjs-client'],
|
|
esbuildOptions: {
|
|
define: {
|
|
global: 'globalThis',
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
sourcemap: true,
|
|
rollupOptions: {
|
|
input: {
|
|
main: path.resolve(__dirname, 'index.html'),
|
|
widget: path.resolve(__dirname, 'widget.html'),
|
|
},
|
|
},
|
|
},
|
|
clearScreen: false,
|
|
server: {
|
|
port: 5175,
|
|
strictPort: true,
|
|
host: host || false,
|
|
hmr: host
|
|
? { protocol: 'ws', host, port: 5176 }
|
|
: undefined,
|
|
watch: {
|
|
ignored: ['**/src-tauri/**'],
|
|
},
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8080',
|
|
changeOrigin: true,
|
|
ws: true,
|
|
},
|
|
'/upbit-api': {
|
|
target: 'https://api.upbit.com',
|
|
changeOrigin: true,
|
|
rewrite: p => p.replace(/^\/upbit-api/, ''),
|
|
},
|
|
'/upbit-ws': {
|
|
target: 'wss://api.upbit.com',
|
|
changeOrigin: true,
|
|
ws: true,
|
|
rewrite: () => '/websocket/v1',
|
|
},
|
|
},
|
|
},
|
|
});
|