#!/bin/bash # Build script bertahap untuk menghindari memory overload # Tetap membangun SEMUA file yang diperlukan tapi secara bertahap echo "๐Ÿ”จ Starting chunked production build..." # Set memory limit export NODE_OPTIONS="--max-old-space-size=1536" export NODE_ENV=production # Clean previous build echo "๐Ÿงน Cleaning previous build..." rm -rf public/build/* # Fungsi untuk build dengan retry build_with_retry() { local config_file=$1 local attempt=1 local max_attempts=3 while [ $attempt -le $max_attempts ]; do echo "๐Ÿ”„ Build attempt $attempt of $max_attempts..." if vite build --config $config_file; then echo "โœ… Build successful on attempt $attempt" return 0 else echo "โŒ Build failed on attempt $attempt" if [ $attempt -lt $max_attempts ]; then echo "โณ Waiting 5 seconds before retry..." sleep 5 # Clear memory caches sync && echo 3 > /proc/sys/vm/drop_caches 2>/dev/null || true fi attempt=$((attempt + 1)) fi done return 1 } echo "๐Ÿ“ฆ Building all assets with memory optimization..." # Try building with production config first if build_with_retry "vite.config.production.js"; then echo "๐ŸŽ‰ Build completed successfully!" echo "๐Ÿ“Š Build summary:" du -sh public/build/* 2>/dev/null || echo "Build files created" # Count generated files echo "๐Ÿ“ Generated files:" find public/build -type f | wc -l | xargs echo "Total files:" else echo "โŒ Build failed after all attempts!" echo "" echo "๐Ÿ’ก Alternative solutions:" echo " 1. โœจ Build locally: npm run build:local" echo " 2. ๐Ÿ”ง Increase server memory/swap" echo " 3. โ˜๏ธ Use GitHub Actions CI/CD" echo " 4. ๐Ÿš€ Use deployment services (Vercel, Netlify)" echo "" echo "๐Ÿ  For local build and deploy:" echo " npm run build:local" echo " ./deploy.sh your-username your-server.com /path/to/project" exit 1 fi echo "" echo "๐Ÿ” Verifying all essential files are built..." # Check for essential files essential_files=( "public/build/manifest.json" "public/build/assets" ) missing_files=() for file in "${essential_files[@]}"; do if [ ! -e "$file" ]; then missing_files+=("$file") fi done if [ ${#missing_files[@]} -eq 0 ]; then echo "โœ… All essential files are present!" else echo "โš ๏ธ Missing files:" printf ' %s\n' "${missing_files[@]}" fi