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({
  plugins: [
    vue(),
    vueDevTools(),
    mkcert({ certFileName: 'bsm-lab.dev.pem', keyFileName: 'bsm-lab.dev-key.pem' }),
  ],
  server: {
    port: 443,
    host: 'bsm-lab.dev',
    proxy: {
      '/app-api/': {
        target: 'https://bsm-lab.dev:9443/app-api/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/app-api/, ''),
        secure: false,
        ws: true,
      },
    },
  },
  base: '/',
  build: {
    outDir: '../resources/static',
    rollupOptions: {
      output: {
        entryFileNames: '[name]-[hash].js',
        chunkFileNames: '[name]-[hash].js',
        assetFileNames: '[name]-[hash][extname]',
      },
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
