import path from "node:path";
import tailwindcss from "@tailwindcss/vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import { imagetools } from "vite-imagetools";

// https://vite.dev/config/
export default defineConfig({
	plugins: [
		tailwindcss(),
		tanstackRouter({
			target: "react",
			autoCodeSplitting: true,
		}),
		react(),
		imagetools(),
	],
	resolve: {
		alias: {
			"@": path.resolve(__dirname, "./src"),
		},
	},
	base: "/lst/app",
	build: {
		//outDir: "../backend/frontend",
		//assetsDir: "assets",
		emptyOutDir: true,
	},
	server: {
		port: 5500,
		host: true,
		allowedHosts: true,
		proxy: {
			"/lst/api": {
				target: `http://localhost:${Number(process.env.VITE_PORT || 3000)}`,
				changeOrigin: true,
				secure: false,
			},
			"/lst/ws": {
				target: `ws://localhost:${Number(process.env.VITE_PORT || 3000)}`, // Your Go WebSocket endpoint
				ws: true,
				changeOrigin: true,
				secure: false,
				rewrite: (path) => path.replace(/^\/ws/, ""),
			},
		},
	},
});
