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

// https://vitejs.dev/config/
export default defineConfig({
    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(),
        chunkSplitPlugin({
            strategy: 'unbundle'
        })
    ],
    server: {
        ...config.vite,
        proxy: {
            '/api': {
                ws: true,
                changeOrigin: true,
                target: config.target,
                rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
            }
        }
    },
})
