// @ts-check
import { defineConfig } from "astro/config";
import tailwindcss from "@tailwindcss/vite";

// https://astro.build/config
export default defineConfig({
  site: 'https://justin.deal',
  
  // Performance optimizations
  compressHTML: true,
  
  // Build optimizations
  build: {
    inlineStylesheets: 'auto', // Inline small stylesheets for better performance
  },
  
  // Image optimizations
  image: {
    service: {
      entrypoint: 'astro/assets/services/sharp',
      config: {
        quality: 80, // Default image quality
        formats: ['webp', 'avif', 'png', 'jpg'], // Supported formats in order of preference
      },
    },
  },
  
  // Vite configuration
  vite: {
    plugins: [tailwindcss()],
    
    // Build optimizations
    build: {
      // Enable chunk splitting
      cssCodeSplit: true,
      
      // Optimize chunks
      rollupOptions: {
        output: {
          // Customize chunk naming
          manualChunks: {
            // Group Alpine.js and related code
            alpine: ['alpinejs'],
          },
        },
      },
    },
    
    // Optimize dependencies
    optimizeDeps: {
      include: ['alpinejs'],
    },
    
    // CSS optimization
    css: {
      devSourcemap: true,
    },
    
    // Enable server-side rendering optimizations
    ssr: {
      noExternal: ['@astrojs/tailwind'],
    },
  },
});
