import path from "path";
import { defineConfig, loadConfigFromFile, loadEnv, mergeConfig } from "vite";
import vue from "@vitejs/plugin-vue2";
import WindiCSS from "vite-plugin-windicss";


import AutoImport from "unplugin-auto-import/vite";

const config = defineConfig(async ({ command, mode, ssrBuild }) => {

  const subConfigModule = await loadConfigFromFile({ command, mode, ssrBuild }, path.join(process.cwd(), `./vite.config.${mode}.ts`))





  const baseConfig = {
    resolve: {
      alias: { "@pc": path.join(process.cwd(), './src/pc'), "@h5": path.join(process.cwd(), './src/h5') }
    },
    build: {
      minify: true,
      rollupOptions: {
        input: {
          pc: path.join(process.cwd(), 'index.html'),
          h5: path.join(__dirname, 'index_h5.html')
        }
      }
    },

    plugins: [
      vue(),
      WindiCSS(),

      AutoImport({
        imports: ["@vueuse/core"],
        dts: "src/auto-imports.d.ts",
      }),
    ],

    server: {
      port: 3333,
    },
  }

  return mergeConfig(baseConfig, subConfigModule?.config as any, false)
});


export default config;
