import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { resolve } from 'path';
import alias from '@rollup/plugin-alias';
import topLevelAwait from "vite-plugin-top-level-await";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const isProduction = mode === 'production';

  const isSlashEnv = mode === 'slash';

  const outDir = isSlashEnv ? '../build/m' : './dist';

  return {
    base: '/m/',
    server: {
      host: '0.0.0.0'
    },
    plugins: [
      alias(),
      vue(),
      Components({
        resolvers: [VantResolver()],
      }),
      topLevelAwait({
        promiseExportName: "__tla",
        promiseImportName: i => `__tla_${i}`
      })
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    css: {},
    build: {
      emptyOutDir: true,
      outDir
    }
  };
});
