import { resolve } from "node:path";
import { lingui } from "@lingui/vite-plugin";
import react from "@vitejs/plugin-react";
import postcss from "postcss";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";

export default defineConfig({
	plugins: [
		react({
			babel: {
				plugins: ["macros"],
			},
		}),
		postcss(),
		lingui(),
		dts(),
	],
	build: {
		lib: {
			entry: {
				index: resolve(__dirname, "index.ts"),
				components: resolve(__dirname, "src/exports/components.ts"),
				utils: resolve(__dirname, "src/exports/utils.ts"),
				styles: resolve(__dirname, "styles/index.css"),
				fonts: resolve(__dirname, "styles/default-fonts.css"),
			},
			name: "@socket.tech/bungee",
			formats: ["es"],
			fileName: (format, entryName) => {
				// biome-ignore format:
				return `${entryName}.js`;
			},
		},
		rollupOptions: {
			external: [
				"react",
				"react-dom",
				"wagmi",
				"viem",
				"viem/ens",
				"@tanstack/react-query",
				"@solana/wallet-adapter-react",
				"react/jsx-runtime",
			],
			output: {
				banner: '"use client";',
			},
		},
		cssCodeSplit: true,
		cssMinify: true,
		sourcemap: true,
	},
	resolve: {
		alias: {
			"@components": resolve(__dirname, "src/components"),
			"@components/common": resolve(__dirname, "src/components/common"),
			"@hooks": resolve(__dirname, "src/hooks"),
			"@utils": resolve(__dirname, "src/utils"),
			"@store": resolve(__dirname, "src/store"),
			"@providers": resolve(__dirname, "src/Providers"),
			"@assets": resolve(__dirname, "./assets"),
			"@/types": resolve(__dirname, "src/types"),
			"@analytics": resolve(__dirname, "src/analytics"),
		},
	},
});
