From 20b67e1402b9680e2d39abfa0ae20f6982e693df Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 10 Aug 2025 18:34:16 +0800 Subject: [PATCH] chore: add Vercel build configuration - Introduced a new build script for Vercel in package.json. - Created a new tsdown configuration file for Vercel deployment. - Updated tsconfig.json to remove the deprecated vercel.ts file from the include path. - Added a new server entry point for compatibility with Vercel's deployment. --- lib/server.ts | 5 +++++ package.json | 1 + tsconfig.json | 2 +- tsdown-vercel.config.ts | 10 ++++++++++ vercel.json | 8 ++++++-- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 lib/server.ts create mode 100644 tsdown-vercel.config.ts diff --git a/lib/server.ts b/lib/server.ts new file mode 100644 index 000000000..77fb222cc --- /dev/null +++ b/lib/server.ts @@ -0,0 +1,5 @@ +// This file is for compatibility with Vercel's deployment. + +import '@/utils/request-rewriter'; + +export default (await import('./app-bootstrap')).default; diff --git a/package.json b/package.json index 9d85bf3a3..5e901d0b8 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ ], "scripts": { "build": "tsx scripts/workflow/build-routes.ts && tsdown", + "build:vercel": "tsx scripts/workflow/build-routes.ts && tsdown --config ./tsdown-vercel.config.ts", "build:docs": "tsx scripts/workflow/build-docs.ts", "dev": "cross-env NODE_ENV=dev tsx watch --inspect --clear-screen=false lib/index.ts", "dev:cache": "cross-env NODE_ENV=production tsx watch --clear-screen=false lib/index.ts", diff --git a/tsconfig.json b/tsconfig.json index 5ce6ad958..2d13c65ab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,6 @@ "resolveJsonModule": true, "isolatedModules": true }, - "include": ["./lib/**/*", "./api/vercel.ts"], + "include": ["./lib/**/*"], "exclude": ["node_modules", "*.test.*"] } diff --git a/tsdown-vercel.config.ts b/tsdown-vercel.config.ts new file mode 100644 index 000000000..3edf022c1 --- /dev/null +++ b/tsdown-vercel.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'tsdown'; +import artTemplatesPlugin from './plugins/rollup-plugin-art-templates.ts'; + +export default defineConfig({ + entry: ['./lib/server.ts'], + minify: true, + shims: true, + clean: true, + plugins: [artTemplatesPlugin()], +}); diff --git a/vercel.json b/vercel.json index 32a8e1531..0202ea8e8 100644 --- a/vercel.json +++ b/vercel.json @@ -1,5 +1,9 @@ { + "$schema": "https://openapi.vercel.sh/vercel.json", "framework": "hono", - "github": { "silent": true }, - "routes": [{ "src": "/.*", "dest": "/api/vercel.ts" }] + "buildCommand": "pnpm run build:vercel", + "outputDirectory": "dist", + "github": { + "silent": true + } }