# 前端构建：Vite 静态产物 → nginx 提供
FROM node:20-alpine AS builder
WORKDIR /src
COPY package.json package-lock.json* ./
RUN npm ci || npm install
COPY . ./
# 后端在 docker 网络中通过服务名 server 访问（compose 里）
ARG VITE_API_TARGET=http://server:4001
ENV VITE_API_TARGET=$VITE_API_TARGET
RUN npm run build

FROM nginx:alpine
COPY --from=builder /src/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
