import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import VitePluginHtmlEnv from 'vite-plugin-html-env';
import { resolve } from 'path';
import WindiCSS from 'vite-plugin-windicss';
// import consola from 'consola';
import mkcert from 'vite-plugin-mkcert';
// import eslintPlugin from 'vite-plugin-eslint'
// import requireTransform from 'vite-plugin-require-transform'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir);
}

// https://vitejs.dev/config/
export default ({ mode }) =>
  defineConfig({
    plugins: [
      // eslintPlugin({
      //   include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
      // }),
      mkcert(),
      vue(),
      WindiCSS(),
      VitePluginHtmlEnv({
        prefix: '<{',
        suffix: '}>',
        envPrefixes: ['VITE_', 'VUE_'],
      }),
    ],
    resolve: {
      alias: [
        {
          find: /\/@\//,
          replacement: pathResolve('src') + '/',
        },
      ],
    },
    server: {
      https: Number(loadEnv(mode, process.cwd()).VITE_USE_HTTPS) == 1,
      host: true,
      headers: {
        'Cache-Control': 'no-store',
      },
      proxy: {
        '/service': {
          target: loadEnv(mode, process.cwd()).VITE_APP_APIS_URL,
          changeOrigin: true,
        },
        '/takelook': {
          target: 'https://v4-test.4dkankan.com',
          changeOrigin: true,
        },
      },
    },
  });
