import { defineConfig } from '@easyflow/vite-config';

import ElementPlus from 'unplugin-element-plus/vite';

export default defineConfig(async () => {
  return {
    application: {},
    vite: {
      resolve: {
        alias: {
          // @vueuse/motion expects tslib default export during dev pre-bundling
          // and breaks when Vite resolves to ESM-only modules/index.js.
          tslib: 'tslib/tslib.js',
        },
      },
      plugins: [
        ElementPlus({
          format: 'esm',
        }),
      ],
      server: {
        proxy: {
          '/flow/api': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/flow/, ''),
            target: 'http://127.0.0.1:8111',
            ws: true,
          },
          '/flow/public-api': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/flow/, ''),
            target: 'http://127.0.0.1:8111',
          },
          '/flow/userCenter': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/flow/, ''),
            target: 'http://127.0.0.1:8111',
          },
        },
      },
    },
  };
});
