# ------------- 依赖缓存阶段 -------------
FROM node:22-alpine AS base

# 国内镜像
RUN npm config set registry https://registry.npmmirror.com

WORKDIR /app

# 拷贝所有源码 - Nuxt 4在pnpm i阶段需要完整的项目结构
COPY . .

# 安装依赖
RUN corepack enable && pnpm install --frozen-lockfile

# 执行补丁脚本
RUN chmod +x patch-ui-pro.zsh && ./patch-ui-pro.zsh

# ------------- 构建阶段 -------------
FROM base AS builder
RUN pnpm build

# ------------- 运行阶段 -------------
FROM node:22-alpine AS production

WORKDIR /app

# 拷贝构建产物 - Nuxt的output目录已经包含了所有运行时需要的文件
COPY --from=builder /app/.output ./.output

EXPOSE 3000
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000
CMD ["node", ".output/server/index.mjs"]