# ── Stage 1: 构建 ──────────────────────────────────────
FROM node:20-alpine AS builder

WORKDIR /app

# 安装 cnpm（淘宝镜像源）
RUN npm install -g cnpm --registry=https://registry.npmmirror.com

# 先单独复制 package.json，利用 Docker 层缓存
COPY package.json .
RUN cnpm install

# 复制源码并构建
COPY . .
RUN npm run build

# ── Stage 2: 运行 ──────────────────────────────────────
FROM nginx:alpine

COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

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