import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueDevTools from 'vite-plugin-vue-devtools';
import mkcert from 'vite-plugin-mkcert';

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
    const plugins = [vue(), vueDevTools()];

    // dev: https, mine: http
    if (mode === 'dev') {
        plugins.push(
            mkcert({
                // SSL 키 등록
                keyFile: '/localhost-key.pem',
                certFile: '/localhost.pem',
            }),
        );
    }

    return {
        plugins,
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url)),
                '@a': fileURLToPath(new URL('./src/assets/', import.meta.url)),
                '@c': fileURLToPath(new URL('./src/components/', import.meta.url)),
                '@v': fileURLToPath(new URL('./src/views/', import.meta.url)),
                '@l': fileURLToPath(new URL('./src/layout/', import.meta.url)),
                '@s': fileURLToPath(new URL('./src/stores/', import.meta.url)),
                '@p': fileURLToPath(new URL('./src/common/plugin/', import.meta.url)),
                '@api': fileURLToPath(new URL('./src/common/axios-interceptor.js', import.meta.url)),
            },
        },
    };
});
