import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vite.dev/config/
export default defineConfig(({ command }) => {
    const sharedConfig = {
        plugins: [react()],
    };

    if (command === "serve") {
        // vite dev server
        return {
            // dev specific config
            ...sharedConfig,
            clearScreen: false,
        };
    } else {
        // vite build
        return {
            ...sharedConfig,
            build: {
                rollupOptions: {
                    output: {
                        manualChunks(id) {
                            if (id.includes("node_modules")) {
                                return id
                                    .toString()
                                    .split("node_modules/")[1]
                                    .split("/")[0]
                                    .toString();
                            }
                        },
                    },
                },
            },
        };
    }
});
