// vite.config.js
import { defineConfig, loadEnv } from "vite";
import checker from "vite-plugin-checker";
// import { libInjectCss } from 'vite-plugin-lib-inject-css';

export default ({ mode }) => {
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  const sourcemap = process.env.VITE_SOURCE_MAP=== 'false'?false:process.env.VITE_SOURCE_MAP;
  // console.log(process.env);
  return defineConfig({
    plugins: [
      checker({
        typescript: true,
      }),
      // libInjectCss(),
    ],
    build: {
      cssCodeSplit: false,
      rollupOptions: {
        input: "src/index.ts", // entry file
        output: {
          entryFileNames: "alc_runtime.js",
          assetFileNames:'alc_runtime.css'
        },
      },
      sourcemap: sourcemap,
    },
    server: {
      port: process.env.VITE_PORT,
      // open: "/dist/alc_runtime.js",
    },
  });
};
