Skip to content

Commit 6ba293d

Browse files
committed
add copy page button
1 parent e039248 commit 6ba293d

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"astro": "astro",
1111
"dev": "astro dev",
1212
"start": "astro dev",
13-
"build": "astro build && npm run pin-sol-version",
13+
"build": "astro build && npm run pin-sol-version && node scripts/cleanup-vercel-function.mjs",
1414
"preview": "astro preview",
1515
"pin-sol-version": "tsx --require tsconfig-paths/register src/scripts/helper/pin-solver-dist.ts",
1616
"linkcheckWrapper": "tsx --require tsconfig-paths/register src/scripts/link-check/linkcheckWrapper.ts",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Post-build script to remove unnecessary files from Vercel serverless function
4+
* Reduces function size from 364MB to under 250MB limit
5+
*/
6+
7+
import { rm } from "fs/promises"
8+
import { existsSync } from "fs"
9+
import { execSync } from "child_process"
10+
11+
const FUNCTION_DIR = ".vercel/output/functions/_render.func"
12+
13+
async function cleanup() {
14+
if (!existsSync(FUNCTION_DIR)) {
15+
console.error(`❌ Function directory not found: ${FUNCTION_DIR}`)
16+
process.exit(1)
17+
}
18+
19+
console.log("🧹 Cleaning up serverless function bundle...")
20+
21+
const sizeBefore = execSync(`du -sh ${FUNCTION_DIR}`, { encoding: "utf-8" }).trim()
22+
console.log(`📦 Size before: ${sizeBefore}`)
23+
24+
// Remove large files/directories that are served statically by CDN
25+
const itemsToRemove = [
26+
`${FUNCTION_DIR}/public/images`,
27+
`${FUNCTION_DIR}/public/search-index.json`,
28+
`${FUNCTION_DIR}/public/files`,
29+
`${FUNCTION_DIR}/public/default-og-image.png`,
30+
`${FUNCTION_DIR}/public/samples`,
31+
`${FUNCTION_DIR}/public/changelog.json`,
32+
]
33+
34+
for (const item of itemsToRemove) {
35+
if (existsSync(item)) {
36+
await rm(item, { recursive: true, force: true })
37+
console.log(` ✓ Removed: ${item.replace(FUNCTION_DIR + "/", "")}`)
38+
}
39+
}
40+
41+
const sizeAfter = execSync(`du -sh ${FUNCTION_DIR}`, { encoding: "utf-8" }).trim()
42+
console.log(`📦 Size after: ${sizeAfter}`)
43+
console.log("✨ Cleanup complete!")
44+
}
45+
46+
cleanup().catch((error) => {
47+
console.error("❌ Cleanup failed:", error)
48+
process.exit(1)
49+
})

0 commit comments

Comments
 (0)