import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueMacros from 'unplugin-vue-macros/vite'
import glob from 'fast-glob'
// import {
//     epPackage,
//     epRoot,
//     getPackageDependencies,
//     pkgRoot,
//     projRoot,
// } from '@kankan-components/build-utils'

export default defineConfig(async ({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  // let { dependencies } = getPackageDependencies(epPackage)
  // dependencies = dependencies.filter((dep) => !dep.startsWith('@types/')) // exclude dts deps
  // const optimizeDeps = (
  //     await glob(['dayjs/(locale|plugin)/*.js'], {
  //         cwd: path.resolve(projRoot, 'node_modules'),
  //     })
  // ).map((dep) => dep.replace(/\.js$/, ''))
  return {
    server: {
      host: true,
      https: !!env.HTTPS,
      port: 6868,
      proxy: {
        '/demoServer': {
          target: 'https://test.4dkankan.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/demoServer/, ''),
        },
      },
    },
    plugins: [
      //@ts-ignore
      VueMacros({
        setupComponent: false,
        setupSFC: false,
        plugins: {
          vue: vue(),
          vueJsx: vueJsx(),
        },
      }),
    ],
    optimizeDeps: {
      include: ['vue', '@vue/shared'],
    },
  }
})
