import path from "node:path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
import mkcert from "vite-plugin-mkcert";
import pkg from "./package.json";

const isCI = process.env.CI === "true";

export default defineConfig({
  plugins: [react(), vanillaExtractPlugin(), ...(!isCI ? [mkcert()] : [])],
  build: {
    lib: {
      entry: path.resolve(__dirname, "src/index.ts"),
      name: "max",
      fileName: "index",
      cssFileName: "style",
    },
    outDir: path.resolve(__dirname, "./lib"),
    emptyOutDir: false,
    rollupOptions: {
      external: pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
    },
  },
});
