Files
sibedas/build-chunked.sh
2025-06-13 13:36:27 +00:00

92 lines
2.5 KiB
Bash

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