# Multi-stage build for Svelte monorepo
# Builder stage
FROM node:20-slim AS builder
WORKDIR /workspace
# Install minimal system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
git \
&& rm -rf /var/lib/apt/lists/*
# Install the preferred PNPM version globally
RUN npm install -g pnpm@10.4.0
# Copy manifests first for caching purposes
COPY package.json pnpm-workspace.yaml ./
# Copy the rest of the repository
COPY . .
# Install dependencies (respect workspace layout)
RUN if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; else pnpm install; fi
# Build the monorepo
RUN pnpm build
# Runtime stage
FROM node:20-slim AS runtime
WORKDIR /app
# Copy built artifacts to lean runtime image
COPY --from=builder /workspace/packages/svelte/compiler /app/compiler
# Run the built compiler at container start
CMD ["node", "/app/compiler/index.js"]