Skip to content

Commit

Permalink
chore: Use tsup for building backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mohebifar committed Dec 22, 2024
1 parent 2acd600 commit 6e8204f
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 44 deletions.
27 changes: 1 addition & 26 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ ENV PATH="$PNPM_HOME:$PATH"
RUN npm install -g pnpm@latest
RUN pnpm -g add turbo@^1



FROM base AS builder
FROM base AS runner
WORKDIR /app

RUN apk update
Expand All @@ -31,30 +29,7 @@ COPY packages/auth /app/packages/auth/

RUN turbo prune @codemod-com/backend --docker



FROM base AS installer
WORKDIR /app

RUN apk update
RUN apk add --no-cache libc6-compat

# First install the dependencies (as they change less often)
COPY --from=builder /app/out/json/ .
RUN pnpm install

# Build the project
COPY --from=builder /app/out/full/ .
RUN pnpm build --filter @codemod-com/backend



FROM base AS runner
# Copy stuff for prisma to work
COPY --from=installer /app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/ ./node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/

WORKDIR /app
COPY --from=installer /app/apps/backend ./apps/backend
COPY --from=installer /app/packages/database ./packages/database

CMD cd packages/database && pnpm dlx prisma@latest migrate deploy && cd - && node apps/backend/build/index.js
3 changes: 2 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@codemod-com/backend",
"version": "0.0.163",
"scripts": {
"build": "tsc && node esbuild.config.js",
"build": "tsc && tsup",
"start": "node build/index.js",
"test": "vitest --run"
},
Expand All @@ -27,6 +27,7 @@
"nodemon": "3.0.2",
"supertest": "catalog:",
"ts-node": "10.9.2",
"tsup": "^8.3.5",
"tsx": "^4.7.1",
"vitest": "1.1.0"
},
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "dotenv/config";

import { startCronJobs } from "./cron.js";
import { runServer } from "./server.js";

Expand Down
14 changes: 14 additions & 0 deletions apps/backend/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "tsup";

export default defineConfig({
entryPoints: ["src/index.ts"],
format: ["esm"],
dts: false,
sourcemap: true,
clean: true,
minify: false,
splitting: true,
target: "node20",
bundle: true,
outDir: "build",
});
Loading

0 comments on commit 6e8204f

Please sign in to comment.