import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import fs from 'node:fs';
import path from 'node:path';

const key = fs.readFileSync(path.resolve(__dirname, '.cert/woonoow.local-key.pem'));
const cert = fs.readFileSync(path.resolve(__dirname, '.cert/woonoow.local-cert.pem'));

export default defineConfig({
  plugins: [react()],
  resolve: { 
    alias: { '@': path.resolve(__dirname, './src') },
    dedupe: ['react', 'react-dom', 'react-router', 'react-router-dom', 'lucide-react', '@tanstack/react-query']
  },
  server: {
    host: 'woonoow.local',
    port: 5173,
    strictPort: true,
    https: { key, cert },
    cors: true,
    origin: 'https://woonoow.local:5173',
    hmr: { protocol: 'wss', host: 'woonoow.local', port: 5173 }
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true,
    manifest: true,
    rollupOptions: {
      input: { app: 'src/main.tsx' },
      output: { entryFileNames: 'app.js', assetFileNames: 'app.[ext]' }
    }
  }
});