# ============================================================
# Stage 1: Build — 基于 Node 18 Alpine 构建 Vue3 前端产物
# ============================================================
FROM node:18-alpine AS builder

WORKDIR /build

# 先拷贝依赖清单，利用 Docker 层缓存
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install

# 拷贝全部前端源码并执行生产构建
COPY frontend/ .
RUN npm install -D @types/node && npm run build

# ============================================================
# Stage 2: Run — 极致轻量的 Nginx 运行时
# ============================================================
FROM nginx:alpine

# 拷贝构建产物
COPY --from=builder /build/dist /usr/share/nginx/html

# 拷贝 Nginx 网关配置（覆盖默认）
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

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