# 构建阶段
FROM node:18-alpine AS builder

WORKDIR /app

# 安装依赖（利用层缓存）
COPY package*.json ./
RUN npm ci

# 复制源代码
COPY . .

# 使用 package.json 中定义的构建命令
ARG BUILD_ENV=production
RUN npm run build:${BUILD_ENV}

# 使用Nginx作为运行环境
FROM nginx:alpine

# 复制打包结果到Nginx默认目录
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html

# 配置Nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf

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