import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { svgBuilder } from '/@/components/icon/svg/index'

const nodeResolve = (dir: string) => path.resolve(__dirname, '.', dir)
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        svgBuilder('./src/assets/icons/'),
        vueJsx(),
        AutoImport({
            //自动引入
            imports: ['vue', 'vue-router', 'pinia']
        })
    ],
    server: {
        host: '0.0.0.0',
        open: true,
        proxy: {
            '/api': {
                // target: 'http://192.168.1.81:10215', //数据中心
                // target: 'http://192.168.1.24:10215', //
                // target: 'http://192.168.1.122:10215', //gfh
                // target: 'http://192.168.1.127:10215', //cdf
                // target: 'http://192.168.1.125:10215',
                target: 'http://192.168.1.103:10215',
                // target: 'https://pqmcn.com:8092/api', //治理
                // target:'http://www.zhilitest.com:8089/api',
                changeOrigin: true,
                rewrite: path => path.replace(/^\/api/, '') //路径重写，把'/api'替换为''
            }
        }
        // port:'3000'
    },

    resolve: {
        alias: {
            '/@': nodeResolve('./src'),
            '@': nodeResolve('src'),
            '~': nodeResolve('public')
        }
    },
    build: {
        outDir: 'dist',
        emptyOutDir: true // 构建前清空 dist
    }
})
