# ====== 构建阶段 ====== FROM node:20-alpine AS builder WORKDIR /app # 安装依赖(利用 Docker 缓存层) COPY package.json package-lock.json ./ RUN npm ci --registry=https://registry.npmmirror.com # 复制源代码并构建 COPY . . RUN npm run build # ====== 生产阶段 ====== FROM nginx:alpine # 复制构建产物 COPY --from=builder /app/dist /usr/share/nginx/html # 复制 Nginx 配置 COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]