import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import { createHtmlPlugin } from 'vite-plugin-html'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createHtmlPlugin({
      minify: true,
      inject: {
        data: {
          VITE_APP_NAME: process.env.VITE_APP_NAME || '结伴客后台管理系统',
          VITE_APP_VERSION: process.env.VITE_APP_VERSION || '1.0.0',
          VITE_API_BASE_URL: process.env.VITE_API_BASE_URL || 'https://webapi.jiebanke.com/api'
        }
      }
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 3150,
    proxy: {
      '/api': {
        target: 'https://webapi.jiebanke.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api/v1')
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false,
    rollupOptions: {
      output: {
        manualChunks: {
          'vue-vendor': ['vue', 'vue-router', 'pinia'],
          'antd-vendor': ['ant-design-vue', '@ant-design/icons-vue'],
          'utils-vendor': ['axios', 'dayjs', 'lodash-es']
        }
      }
    }
  }
})