From bb896803ad9bf51721029c5ebbc05c9895bbd1c9 Mon Sep 17 00:00:00 2001 From: Chilfish Date: Fri, 15 Mar 2024 12:51:52 +0800 Subject: [PATCH] buid: fix deploy on vercel --- .vercelignore | 2 +- api/index.cjs | 0 package.json | 7 +++---- scripts/build.ts | 12 ++++++++++++ tsconfig.json | 2 +- vercel.json | 4 ++-- 6 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 api/index.cjs create mode 100644 scripts/build.ts diff --git a/.vercelignore b/.vercelignore index 3126011..186b14f 100644 --- a/.vercelignore +++ b/.vercelignore @@ -2,9 +2,9 @@ .husky .vscode node_modules -scripts CHANGELOG.md README.md +dist *.log .output diff --git a/api/index.cjs b/api/index.cjs new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 3356780..44690bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "hono-ncm", - "type": "module", "version": "0.0.1", "private": true, "packageManager": "pnpm@8.15.4", @@ -26,10 +25,10 @@ ], "scripts": { "dev": "tsx watch --no-cache src/node.ts", - "build": "unbuild", + "build": "tsx scripts/build.ts", "start": "tsx src/node.ts", - "prepare": "husky", - "lint": "eslint . --fix" + "prepare": "husky || true && pnpm build", + "lint": "eslint ." }, "dependencies": { "hono": "^4.1.0" diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 0000000..bbd4441 --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,12 @@ +import { copyFileSync } from 'node:fs' +import { join, resolve } from 'node:path' +import { execSync } from 'node:child_process' + +const root = resolve() + +execSync('pnpm unbuild', { stdio: 'inherit' }) + +copyFileSync( + join(root, 'dist', 'index.cjs'), + join(root, 'api', 'index.cjs'), +) diff --git a/tsconfig.json b/tsconfig.json index aacd795..c92c011 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "esModuleInterop": true }, "include": [ - "./src/**/*", + "./src/**/*" ], "exclude": [ "node_modules", diff --git a/vercel.json b/vercel.json index 3c895ac..ba33777 100644 --- a/vercel.json +++ b/vercel.json @@ -2,14 +2,14 @@ "version": 2, "builds": [ { - "src": "./dist/index.cjs", + "src": "./api/index.cjs", "use": "@vercel/node" } ], "routes": [ { "src": "/(.*)", - "dest": "/dist/index.cjs" + "dest": "/api/index.cjs" } ] }