import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import terser from "@rollup/plugin-terser";
import postcss from "rollup-plugin-postcss";
import { PluginPure } from "rollup-plugin-pure";
import cleanup from 'rollup-plugin-cleanup'
import css from "rollup-plugin-css-only";

const packageJson = require("./package.json");

export default [
  {
    input: "./src/index.ts",
    output: [
      {
        file: packageJson.main,
        format: "cjs",
        sourcemap: true,
        assetFileNames: "assets/[name]-[hash][extname]",
      },
      {
        file: packageJson.module,
        format: "esm",
        sourcemap: true,
        assetFileNames: "assets/[name]-[hash][extname]",
      },
    ],
    plugins: [
      peerDepsExternal(),
      commonjs(),
      postcss({
        config: {
          path: "./postcss.config.js",
        },
        extensions: [".css"],
        minimize: true,
        inject: {
          insertAt: "top",
        },
      }),
      PluginPure({
        functions: ["defineComponent"],
        // exclude: [],
        // sourcemap: true,
      }),
      typescript({ tsconfig: "./tsconfig.json", declaration: true }),
      resolve(),
      css(),
      terser(),
      cleanup(),
    ],
    external: [
      "react",
      "react-dom",
      "@radix-ui/react-menu",
      "@radix-ui/react-dialog",
      "@radix-ui/react-select",
      "styled-components",
      "slick-carousel/slick/slick.css",
      "react-router-dom",
      "@remix-run/react",
    ],
  },
  {
    input: "./src/index.ts",
    output: [{ file: "dist/types.d.ts", format: "es" }],
    plugins: [dts.default()],
  },
];
