import { defineConfig } from "vite";
import { ViteMinifyPlugin } from 'vite-plugin-minify'
import { dirname } from 'path'
import { viteStaticCopy } from 'vite-plugin-static-copy';

const projectRoot = dirname(import.meta.filename);

const paths = {
  src: `${projectRoot}/src`,
  assets: `${projectRoot}/public/assets`
}

export default defineConfig({
  root: './src',
  base: '/',
  resolve: {
    alias: {
      '@': paths.src, // Alias para acceder a la carpeta src
      '@assets': paths.assets, // Alias para acceder a los assets
    },
  },
  build: {
    outDir: '../dist',
    minify: "esbuild",
    emptyOutDir: true,
    build: {
      rollupOptions: {
        output: {
          assetFileNames: (assetInfo) => {
            if (assetInfo.name.endsWith('.css')) return 'assets/[name][extname]';
          },
        },
      },
    }
  },
  plugins: [
    ViteMinifyPlugin({}),
    viteStaticCopy({
      targets: [
        {
          src: `${paths.src}/assets/img/jobs/**/`, // Ruta de origen
          dest: 'assets/img/jobs'        // Carpeta de destino dentro de dist
        }
      ]
    })
  ],
});