import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

const inputs = [
  './vue/dashboard.js',
  './vue/authentication.js',
];

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  base: '',
  build: {
    manifest: 'manifest.json',
    rollupOptions: {
      input: inputs,
      output: {
        dir: 'assets/vue',
        assetFileNames( assetInfo ) {
          let images = [
            '.png',
            '.jpg',
            '.jpeg',
            '.gif',
            '.svg',
          ];

          if (images.includes(path.extname(assetInfo.name))) {
            return 'img/[name][extname]';
          }

          let fonts = [
            '.woff',
            '.woff2',
            '.ttf',
            '.otf'
          ];

          if (fonts.includes(path.extname(assetInfo.name))) {
            return 'fonts/[name][extname]';
          }

          return '[ext]/[name][extname]';
        },
        chunkFileNames: 'js/chunks/[name]-[hash].min.js',
        entryFileNames: 'js/[name]-[hash].min.js',
      },
    },
    modulePreload: { polyfill: false },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './vue'),
    }
  },
  server: {
    origin: process.env.VITE_SERVER_ORIGIN || 'http://localhost:5173',
  },
});
