Files
WooNooW/build-production.sh
Dwindi Ramadhana 0609c6e3d8 fix: Customer SPA loading and optimize production build size
Problem 1: Customer SPA not loading (stuck on 'Loading...')
Root Cause: Missing type='module' attribute on customer SPA script tag
Solution: Added script_loader_tag filter to inject type='module' for ES modules

Problem 2: Production zip too large (21-41MB)
Root Cause: Build script included unnecessary files (dist folder, fonts, .vite, test files, archives)
Solution:
- Exclude entire customer-spa and admin-spa directories from rsync
- Manually copy only app.js and app.css for both SPAs
- Exclude dist/, archive/, test-*.php, check-*.php files
- Simplified Frontend/Assets.php to always load app.js/app.css directly (no manifest needed)

Changes:
- includes/Frontend/Assets.php:
  * Added type='module' to customer SPA script (both manifest and fallback paths)
  * Removed manifest logic, always load app.js and app.css directly
- build-production.sh:
  * Exclude customer-spa and admin-spa directories completely
  * Manually copy only dist/app.js and dist/app.css
  * Exclude dist/, archive/, test files

Result:
 Customer SPA loads with type='module' support
 Production zip reduced from 21-41MB to 1.6MB
 Only essential files included (app.js + app.css for both SPAs)
 Clean production package without dev artifacts

Package contents:
- Customer SPA: 480K (app.js) + 52K (app.css) = 532K
- Admin SPA: 2.6M (app.js) + 76K (app.css) = 2.7M
- PHP Backend: ~500K
- Total: 1.6M (compressed)
2025-12-30 17:48:09 +07:00

103 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# WooNooW Plugin - Production Build Script
# This script creates a production-ready zip file of the plugin
set -e # Exit on error
PLUGIN_NAME="woonoow"
VERSION=$(grep "Version:" woonoow.php | awk '{print $3}')
BUILD_DIR="build"
DIST_DIR="dist"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
ZIP_NAME="${PLUGIN_NAME}-${VERSION}-${TIMESTAMP}.zip"
echo "=========================================="
echo "WooNooW Production Build"
echo "=========================================="
echo "Plugin: ${PLUGIN_NAME}"
echo "Version: ${VERSION}"
echo "Timestamp: ${TIMESTAMP}"
echo "=========================================="
# Clean previous builds
echo "Cleaning previous builds..."
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}/${PLUGIN_NAME}
mkdir -p ${DIST_DIR}
# Copy plugin files
echo "Copying plugin files..."
rsync -av --progress \
--exclude='node_modules' \
--exclude='.git' \
--exclude='.gitignore' \
--exclude='build' \
--exclude='dist' \
--exclude='*.log' \
--exclude='.DS_Store' \
--exclude='customer-spa' \
--exclude='admin-spa' \
--exclude='examples' \
--exclude='*.sh' \
--exclude='*.md' \
--exclude='archive' \
--exclude='test-*.php' \
--exclude='check-*.php' \
./ ${BUILD_DIR}/${PLUGIN_NAME}/
# Verify production builds exist in source before copying
echo "Verifying production builds..."
if [ ! -f "customer-spa/dist/app.js" ]; then
echo "ERROR: Customer SPA production build not found!"
echo "Please run: cd customer-spa && npm run build"
exit 1
fi
if [ ! -f "admin-spa/dist/app.js" ]; then
echo "ERROR: Admin SPA production build not found!"
echo "Please run: cd admin-spa && npm run build"
exit 1
fi
echo "✓ Customer SPA build verified ($(du -h customer-spa/dist/app.js | cut -f1))"
echo "✓ Admin SPA build verified ($(du -h admin-spa/dist/app.js | cut -f1))"
# Copy only essential SPA build files
echo "Copying SPA build files..."
mkdir -p ${BUILD_DIR}/${PLUGIN_NAME}/customer-spa/dist
mkdir -p ${BUILD_DIR}/${PLUGIN_NAME}/admin-spa/dist
# Customer SPA - only app.js and app.css
cp customer-spa/dist/app.js ${BUILD_DIR}/${PLUGIN_NAME}/customer-spa/dist/
cp customer-spa/dist/app.css ${BUILD_DIR}/${PLUGIN_NAME}/customer-spa/dist/
# Admin SPA - only app.js and app.css (no dynamic imports for now)
cp admin-spa/dist/app.js ${BUILD_DIR}/${PLUGIN_NAME}/admin-spa/dist/
cp admin-spa/dist/app.css ${BUILD_DIR}/${PLUGIN_NAME}/admin-spa/dist/
echo "✓ Copied customer-spa: app.js ($(du -h customer-spa/dist/app.js | cut -f1)), app.css ($(du -h customer-spa/dist/app.css | cut -f1))"
echo "✓ Copied admin-spa: app.js ($(du -h admin-spa/dist/app.js | cut -f1)), app.css ($(du -h admin-spa/dist/app.css | cut -f1))"
# Create zip file
echo "Creating zip file..."
cd ${BUILD_DIR}
zip -r ../${DIST_DIR}/${ZIP_NAME} ${PLUGIN_NAME} -q
cd ..
# Calculate file size
FILE_SIZE=$(du -h ${DIST_DIR}/${ZIP_NAME} | cut -f1)
echo "=========================================="
echo "✓ Production build complete!"
echo "=========================================="
echo "File: ${DIST_DIR}/${ZIP_NAME}"
echo "Size: ${FILE_SIZE}"
echo "=========================================="
# Clean up build directory
echo "Cleaning up..."
rm -rf ${BUILD_DIR}
echo "Done! 🚀"