/// <reference types="vitest/config" />
import { fileURLToPath } from "node:url";
import stylex from "@stylexjs/unplugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig(({ mode }) => ({
	plugins: [
		// StyleX resolves the `.stylex.ts` theme file itself, so it needs the `@`
		// alias too — `resolve.alias` below is Vite's and the plugin cannot see it.
		stylex.vite({
			useCSSLayers: true,
			dev: mode === "development",
			runtimeInjection: false,
			aliases: { "@/*": [fileURLToPath(new URL("./src/*", import.meta.url))] },
		}),
		react(),
	],
	resolve: {
		alias: {
			"@": fileURLToPath(new URL("./src", import.meta.url)),
		},
	},
	server: {
		proxy: {
			"/api": "http://127.0.0.1:8080",
			"/metrics": "http://127.0.0.1:8080",
		},
	},
	test: {
		environment: "jsdom",
		globals: true,
		setupFiles: ["./vitest.setup.ts"],
	},
}));
