// vite.config.js
import { defineConfig, loadEnv } from "vite";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import checker from "vite-plugin-checker";

export default ({ mode }) => {
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

  return defineConfig({
    plugins: [
      checker({
        typescript: true,
      }),
      cssInjectedByJsPlugin(),
    ],
    build: {
      cssCodeSplit: false,
      rollupOptions: {
        input: "src/index.ts", // entry file
        output: {
          entryFileNames: "alc_runtime.js",
          // assetFileNames:'alc_kintone_style.css'
        },
      },
      sourcemap: process.env.VITE_SOURCE_MAP,
    },
    server: {
      port: process.env.VITE_PORT,
      // open: "/dist/alc_runtime.js",
    },
  });
};
