import vue    from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';

import { fileURLToPath, URL } from 'node:url';

import UnoCSS from 'unocss/vite';
import SVGLoader from 'vite-svg-loader';

import AutoImport               from 'unplugin-auto-import/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components               from 'unplugin-vue-components/vite';

import { VueRouterAutoImports } from 'unplugin-vue-router';
import VueRouter                from 'unplugin-vue-router/vite';

import { defineConfig, loadEnv }   from 'vite';
import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import';
import vueDevTools                 from 'vite-plugin-vue-devtools';


const dts = `./@types/` as const;

// https://vitejs.dev/config/
export default defineConfig((configEnv) => {
  const envDir = './.env';
  const env = loadEnv(configEnv.mode, envDir, 'REQUEST_');

  return {
    envDir,
    envPrefix: 'SIX_',
    define: {
      __APP_VERSION__: JSON.stringify(process.env.npm_package_version),
    },
    plugins: [
      VueRouter({
        routesFolder: [
          'src/pages',
        ],
        dts: `${ dts }typed-router.d.ts`,
      }),
      vue(),
      vueJsx(),
      vueDevTools(),
      UnoCSS(),
      SVGLoader(),
      AutoImport({
        imports: [
          'vue',
          VueRouterAutoImports,
        ],
        dts: `${ dts }auto-imports.d.ts`,

      }),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false,
          }),
        ],
        dts: `${ dts }components.d.ts`,
      }),
      lazyImport({
        resolvers: [
          VxeResolver({
            libraryName: 'vxe-table',
            importStyle: 'scss' as any,
          }),
          VxeResolver({
            libraryName: 'vxe-pc-ui',
            importStyle: 'scss' as any,
          }),
        ],
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    server: {
      host: true,
      open: true,
      proxy: {
        '/manager': {
          target: 'https://wx.hzliuzhi.com:4433',
          // target:"https://test.hzliuzhi.com",
          secure: false,
          changeOrigin: true,
          logLevel: 'debug',
        },
      },
    },
  };
});
