# Stage 1: Build the React app
FROM node:24-alpine AS builder

WORKDIR /app

# Copy package files first for better caching
COPY package.json package-lock.json* ./

# Install dependencies (prefers yarn if available)
RUN npm ci 

# Copy all files and build
COPY . .

RUN npm run build 

FROM nginx:alpine

# Remove default nginx static files
RUN rm -rf /usr/share/nginx/html/*

WORKDIR /app

# Copy only necessary files from the builder stage
COPY --from=builder /app/dist /usr/share/nginx/html  
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf  

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
