import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

export default defineConfig(({ command }) => {
	const isDev = command === "serve"; // 'serve' = npm run dev

	return {
		plugins: [vue()],

		resolve: {
			alias: {
				'@': resolve(__dirname, 'src')
			}
		},

		base: isDev ? "/" : "/assets/custom_ui/dist/",

		build: {
			outDir: isDev
				? resolve(__dirname, "dist-dev") // optional, Vite dev server serves in memory
				: resolve(__dirname, "../custom_ui/public/dist"),
			emptyOutDir: true,
			manifest: true,
			rollupOptions: {
				input: resolve(__dirname, "src/main.js"),
			},
		},

		server: {
			proxy: {
    			'/zippopotam': {
      				target: 'https://api.zippopotam.us',
      				changeOrigin: true,
     				 rewrite: (path) => path.replace(/^\/zippopotam/, ''),
    				},
  		},
			port: 5173,
			strictPort: true,
		},
	};
});
