Skip to content

Commit 4ec01c2

Browse files
committed
feat(build): update Vercel build process and bundle API function
1 parent 3098747 commit 4ec01c2

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Build script for Vercel deployment of @objectstack/studio.
5+
#
6+
# Without outputDirectory, Vercel serves static files from public/.
7+
# Serverless functions are detected from api/ at the project root.
8+
#
9+
# Steps:
10+
# 1. Turbo build (Vite SPA → dist/)
11+
# 2. Bundle the API serverless function (→ api/index.js)
12+
# 3. Copy Vite output to public/ for Vercel CDN serving
13+
14+
echo "[build-vercel] Starting studio build..."
15+
16+
# 1. Build the studio SPA with turbo (from monorepo root)
17+
cd ../..
18+
pnpm turbo run build --filter=@objectstack/studio
19+
cd apps/studio
20+
21+
# 2. Bundle API serverless function
22+
node scripts/bundle-api.mjs
23+
24+
# 3. Copy Vite build output to public/ for static file serving
25+
rm -rf public
26+
mkdir -p public
27+
cp -r dist/* public/
28+
29+
echo "[build-vercel] Done. Static files in public/, serverless function in api/index.js"

apps/studio/scripts/bundle-api.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ await build({
3535
entryPoints: ['server/index.ts'],
3636
bundle: true,
3737
platform: 'node',
38-
format: 'esm',
38+
format: 'cjs',
3939
target: 'es2020',
40-
outfile: 'dist/api/index.js',
40+
outfile: 'api/index.js',
4141
sourcemap: true,
4242
external: EXTERNAL,
4343
// Silence warnings about optional/unused require() calls in knex drivers
4444
logOverride: { 'require-resolve-not-external': 'silent' },
4545
});
4646

47-
console.log('[bundle-api] Bundled server/index.ts → dist/api/index.js');
47+
console.log('[bundle-api] Bundled server/index.ts → api/index.js');

apps/studio/vercel.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@
22
"$schema": "https://openapi.vercel.sh/vercel.json",
33
"framework": null,
44
"installCommand": "cd ../.. && pnpm install",
5-
"buildCommand": "cd ../.. && pnpm turbo run build --filter=@objectstack/studio && cd apps/studio && node scripts/bundle-api.mjs",
6-
"outputDirectory": "dist",
5+
"buildCommand": "bash scripts/build-vercel.sh",
76
"build": {
87
"env": {
98
"VITE_RUNTIME_MODE": "server",
109
"VITE_SERVER_URL": "https://play.objectstack.ai"
1110
}
1211
},
12+
"functions": {
13+
"api/index.js": {
14+
"memory": 1024,
15+
"maxDuration": 60,
16+
"includeFiles": "node_modules/{@libsql,better-sqlite3}/**"
17+
}
18+
},
19+
"headers": [
20+
{
21+
"source": "/assets/(.*)",
22+
"headers": [
23+
{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
24+
]
25+
}
26+
],
1327
"rewrites": [
1428
{ "source": "/api/(.*)", "destination": "/api" },
1529
{ "source": "/((?!api/).*)", "destination": "/index.html" }

0 commit comments

Comments
 (0)