# ---- Stage 1: Build ----
FROM node:20-alpine AS build

# 启用 pnpm
RUN corepack enable

# 使用国内镜像源
RUN pnpm config set registry https://registry.npmmirror.com

WORKDIR /app

# 先复制依赖文件，利用 Docker 层缓存
COPY package.json pnpm-lock.yaml ./

# 安装依赖
RUN pnpm install --frozen-lockfile

# 复制项目源码
COPY . .

# 构建（跳过 vue-tsc 类型检查，只跑 vite build）
RUN npx vite build

# ---- Stage 2: Serve ----
FROM nginx:alpine

# 复制 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 复制构建产物
COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80

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