|
8 | 8 | # 1. Build the core package first (other packages depend on it) |
9 | 9 | # 2. Patch the console plugin (dereference pnpm symlinks) |
10 | 10 | # 3. Build all business packages in parallel |
| 11 | +# 4. Copy SPA static assets to public/ for direct serving by Vercel's CDN |
11 | 12 | # |
12 | 13 | # Usage (called automatically by Vercel via vercel.json): |
13 | 14 | # bash scripts/build-vercel.sh |
@@ -37,4 +38,49 @@ pnpm --filter @hotcrm/ai \ |
37 | 38 | --filter @hotcrm/financial-services \ |
38 | 39 | build |
39 | 40 |
|
| 41 | +# --------------------------------------------------------------------------- |
| 42 | +# Copy SPA static assets to public/ so Vercel serves them directly from CDN |
| 43 | +# instead of routing through the serverless function. |
| 44 | +# |
| 45 | +# Vercel's routing order: redirects → headers → filesystem → rewrites |
| 46 | +# Files in public/ (the outputDirectory) are matched at the "filesystem" |
| 47 | +# step, BEFORE rewrites, so they bypass the API handler entirely. |
| 48 | +# |
| 49 | +# Only asset files (JS, CSS, fonts, images) are copied — NOT index.html. |
| 50 | +# SPA entry points must still go through the API handler for proper |
| 51 | +# client-side routing fallback. |
| 52 | +# --------------------------------------------------------------------------- |
| 53 | + |
| 54 | +echo "▸ Copying SPA static assets to public/ for direct CDN serving..." |
| 55 | + |
| 56 | +# Console SPA (@object-ui/console) |
| 57 | +CONSOLE_DIST="node_modules/@object-ui/console/dist" |
| 58 | +if [ -d "$CONSOLE_DIST/assets" ]; then |
| 59 | + mkdir -p public/console/assets |
| 60 | + cp -r "$CONSOLE_DIST/assets/"* public/console/assets/ |
| 61 | + echo " ✓ Console assets copied to public/console/assets/" |
| 62 | + # Copy manifest.json if present (referenced by <link rel="manifest">) |
| 63 | + if [ -f "$CONSOLE_DIST/manifest.json" ]; then |
| 64 | + cp "$CONSOLE_DIST/manifest.json" public/console/manifest.json |
| 65 | + echo " ✓ Console manifest.json copied" |
| 66 | + fi |
| 67 | +else |
| 68 | + echo " ⚠ Console dist/assets not found — skipping" |
| 69 | +fi |
| 70 | + |
| 71 | +# Studio SPA (@objectstack/studio) |
| 72 | +STUDIO_DIST="node_modules/@objectstack/studio/dist" |
| 73 | +if [ -d "$STUDIO_DIST/assets" ]; then |
| 74 | + mkdir -p public/_studio/assets |
| 75 | + cp -r "$STUDIO_DIST/assets/"* public/_studio/assets/ |
| 76 | + echo " ✓ Studio assets copied to public/_studio/assets/" |
| 77 | + # Copy vite.svg favicon if present |
| 78 | + if [ -f "$STUDIO_DIST/vite.svg" ]; then |
| 79 | + cp "$STUDIO_DIST/vite.svg" public/_studio/vite.svg |
| 80 | + echo " ✓ Studio vite.svg copied" |
| 81 | + fi |
| 82 | +else |
| 83 | + echo " ⚠ Studio dist/assets not found — skipping" |
| 84 | +fi |
| 85 | + |
40 | 86 | echo "✓ Vercel build complete." |
0 commit comments