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

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

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

export default defineConfig({
  root: './src',
  base: '/',
  resolve: {
    alias: {
      '@': paths.src,
      '@assets': paths.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: normalizePath(resolve(__dirname, 'src/assets/img/jobs/**/*')),
          dest: '',
        }
      ],
      structured: true
    })
  ],
});