Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: vercel deploy #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/react-dom": "18.2.25",
"@vercel/git-hooks": "1.0.0",
"autoprefixer": "10.4.19",
"esbuild": "0.21.5",
"eslint": "9.0.0",
"eslint-config-next": "14.2.2",
"lint-staged": "15.2.2",
Expand Down
38 changes: 9 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"version": 2,
"buildCommand": "pnpm build && node vercel.mjs"
}
92 changes: 92 additions & 0 deletions vercel.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
based on
https://github.com/hi-ogawa/vite-plugins/blob/9e2cfc8770344c322f78523237d4b6e9266b9da0/packages/react-server/examples/basic/misc/vercel/build.js#L50-L58

// initial setup
vercel projects add app-router-vite
vercel link -p app-router-vite

// deploy
pnpm build && node vercel.mjs
vercel deploy --prebuilt --prod
*/

import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import * as esbuild from 'esbuild';

const buildDir = join(import.meta.dirname, 'dist');
const outDir = join(import.meta.dirname, '.vercel/output');

const configJson = {
version: 3,
trailingSlash: false,
routes: [
{
src: '^/assets/(.*)$',
headers: {
'cache-control': 'public, immutable, max-age=31536000',
},
},
{
handle: 'filesystem',
},
{
src: '.*',
dest: '/',
},
],
};

const vcConfigJson = {
runtime: 'nodejs20.x',
handler: 'index.mjs',
};

async function main() {
// clean
await rm(outDir, { recursive: true, force: true });
await mkdir(outDir, { recursive: true });

// config
await writeFile(
join(outDir, 'config.json'),
JSON.stringify(configJson, null, 2),
);

// static
await mkdir(join(outDir, 'static'), { recursive: true });
await cp(join(buildDir, 'client'), join(outDir, 'static'), {
recursive: true,
});

// function
await mkdir(join(outDir, 'functions/index.func'), { recursive: true });
await writeFile(
join(outDir, 'functions/index.func/.vc-config.json'),
JSON.stringify(vcConfigJson, null, 2),
);

// bundle function
const result = await esbuild.build({
entryPoints: [join(buildDir, 'server/index.js')],
outfile: join(outDir, 'functions/index.func/index.mjs'),
metafile: true,
bundle: true,
minify: true,
format: 'esm',
platform: 'node',
define: {
'process.env.NODE_ENV': `"production"`,
},
logOverride: {
'ignored-bare-import': 'silent',
},
});
await writeFile(
join(outDir, 'esbuild-metafile.json'),
JSON.stringify(result.metafile),
);
}

main();