# Multi-stage: `dev` target = Vite dev server (docker-compose.yml),
#              default/`prod` target = static build served by nginx (docker-compose.prod.yml).

FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
COPY . .

# ---- dev: hot-reload server (dev compose bind-mounts the source over /app) ----
FROM deps AS dev
EXPOSE 5173
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"]

# ---- prod: type-check + build, then serve the static bundle with nginx ----
FROM deps AS build
RUN npm run build

FROM nginx:1.27-alpine AS prod
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
