// vite.config.mjs
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { visualizer } from "rollup-plugin-visualizer";
import env from "vite-plugin-env-compatible";
import { VitePWA } from "vite-plugin-pwa";

export default defineConfig(() => ({
  build: {
    outDir: "build",
    rollupOptions: {
      output: {
        entryFileNames: "[name].[hash].js",
        chunkFileNames: "[name].[hash].js",
        assetFileNames: "[name].[hash][extname]",
      },
    },
  },
  envPrefix: "VITE_",
  css: { preprocessorOptions: { scss: {} } },
  plugins: [
    react(),
    env(),
    VitePWA({
      injectRegister: "auto",      
      registerType: "autoUpdate",  
      workbox: { clientsClaim: true, skipWaiting: true },
    }),
    visualizer({ filename: "./bundle-analysis.html", open: true }),
  ],
}));
