import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from "path";
import config from "./src/config";

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@import "./src/styles/app/_var.scss";`
            }
        }
    },
    resolve: {
        alias: {
            '~src': `${resolve(__dirname, './src')}`,
            '~ass': resolve(__dirname, './src/assets'),
            '~com': `${resolve(__dirname, './src/components')}`,
            '~api': resolve(__dirname, './src/api/modules'),
            '~sto': resolve(__dirname, './src/store/modules'),
            '~uti': resolve(__dirname, './src/utils')
        }
    },
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    server: {
        port: '3001',
        host: '0.0.0.0',
        proxy: {
            '/api': {
                ws: true,
                changeOrigin: true,
                target: config.host,
                rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
            }
        }
    },
})
