FROM node:14-alpine AS builder

WORKDIR /app

# 系统依赖配置
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add --no-cache python3 make g++

# 只复制package.json（避免lockfile冲突）
COPY package.json ./

# 关键：强制使用npm官方源（确保能找到2.x版本）+ 清理缓存
RUN npm config set registry https://registry.npmjs.org \
    && npm cache clean --force \
    && npm install --legacy-peer-deps

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

# 生产环境
FROM nginx:1.21-alpine
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8333
CMD ["nginx", "-g", "daemon off;"]
