framework/examples/website/serve.sh
2025-07-21 00:17:46 +02:00

51 lines
1.5 KiB
Bash
Executable File

#!/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