#!/bin/bash # serve.sh - Build optimized WASM and serve with Caddy + Brotli compression set -e echo "🔧 Building optimized WASM bundle..." trunk build --release echo "đŸ“Ļ Checking bundle sizes..." if [ -d "dist" ]; then echo "Bundle sizes:" find dist -name "*.wasm" -exec ls -lh {} \; | awk '{print " WASM: " $5 " - " $9}' find dist -name "*.js" -exec ls -lh {} \; | awk '{print " JS: " $5 " - " $9}' find dist -name "*.css" -exec ls -lh {} \; | awk '{print " CSS: " $5 " - " $9}' echo "" fi echo "đŸ—œī¸ Using Caddyfile with Gzip compression..." if [ ! -f "Caddyfile" ]; then echo "❌ Caddyfile not found!" echo " Make sure Caddyfile exists in the current directory" exit 1 fi echo "🚀 Starting Caddy server with Brotli compression..." echo "📍 Server will be available at: http://localhost:8080" echo "🔍 Monitor compression in DevTools Network tab" echo "" echo "💡 Tips:" echo " - Check 'Content-Encoding: gzip' in response headers" echo " - Compare transfer size vs content size" echo " - WASM files should compress ~60% with gzip" echo "" echo "âšī¸ Press Ctrl+C to stop the server" echo "" # Check if Caddy is installed if ! command -v caddy &> /dev/null; then echo "❌ Caddy is not installed!" echo "" echo "đŸ“Ĩ Install Caddy:" echo " macOS: brew install caddy" echo " Linux: https://caddyserver.com/docs/install" echo " Windows: https://caddyserver.com/docs/install" echo "" exit 1 fi # Start Caddy caddy run --config Caddyfile