bundle-artifact.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. set -e
  3. echo "📦 Bundling React app to single HTML artifact..."
  4. # Check if we're in a project directory
  5. if [ ! -f "package.json" ]; then
  6. echo "❌ Error: No package.json found. Run this script from your project root."
  7. exit 1
  8. fi
  9. # Check if index.html exists
  10. if [ ! -f "index.html" ]; then
  11. echo "❌ Error: No index.html found in project root."
  12. echo " This script requires an index.html entry point."
  13. exit 1
  14. fi
  15. # Install bundling dependencies
  16. echo "📦 Installing bundling dependencies..."
  17. pnpm add -D parcel @parcel/config-default parcel-resolver-tspaths html-inline
  18. # Create Parcel config with tspaths resolver
  19. if [ ! -f ".parcelrc" ]; then
  20. echo "🔧 Creating Parcel configuration with path alias support..."
  21. cat > .parcelrc << 'EOF'
  22. {
  23. "extends": "@parcel/config-default",
  24. "resolvers": ["parcel-resolver-tspaths", "..."]
  25. }
  26. EOF
  27. fi
  28. # Clean previous build
  29. echo "🧹 Cleaning previous build..."
  30. rm -rf dist bundle.html
  31. # Build with Parcel
  32. echo "🔨 Building with Parcel..."
  33. pnpm exec parcel build index.html --dist-dir dist --no-source-maps
  34. # Inline everything into single HTML
  35. echo "🎯 Inlining all assets into single HTML file..."
  36. pnpm exec html-inline dist/index.html > bundle.html
  37. # Get file size
  38. FILE_SIZE=$(du -h bundle.html | cut -f1)
  39. echo ""
  40. echo "✅ Bundle complete!"
  41. echo "📄 Output: bundle.html ($FILE_SIZE)"
  42. echo ""
  43. echo "You can now use this single HTML file as an artifact in Claude conversations."
  44. echo "To test locally: open bundle.html in your browser"