File size: 1,758 Bytes
c8ed262 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import path from "path";
import { fileURLToPath } from "url";
import { build as esbuild } from "esbuild";
import { rm, readFile } from "fs/promises";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// server deps to bundle to reduce openat(2) syscalls
// which helps cold start times without risking some
// packages that are not bundle compatible
const allowlist = [
"@google/generative-ai",
"axios",
"connect-pg-simple",
"cors",
"date-fns",
"drizzle-orm",
"drizzle-zod",
"express",
"express-rate-limit",
"express-session",
"jsonwebtoken",
"memorystore",
"multer",
"nanoid",
"nodemailer",
"openai",
"passport",
"passport-local",
"pg",
"stripe",
"uuid",
"ws",
"xlsx",
"zod",
"zod-validation-error",
];
async function buildAll() {
const distDir = path.resolve(__dirname, "dist");
await rm(distDir, { recursive: true, force: true });
console.log("building server...");
const pkgPath = path.resolve(__dirname, "package.json");
const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
const allDeps = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
];
const externals = allDeps.filter(
(dep) =>
!allowlist.includes(dep) &&
!(pkg.dependencies?.[dep]?.startsWith("workspace:")),
);
await esbuild({
entryPoints: [path.resolve(__dirname, "src/index.ts")],
platform: "node",
bundle: true,
format: "cjs",
outfile: path.resolve(distDir, "index.cjs"),
define: {
"process.env.NODE_ENV": '"production"',
},
minify: true,
external: externals,
logLevel: "info",
});
}
buildAll().catch((err) => {
console.error(err);
process.exit(1);
});
|