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++

# 复制并安装依赖
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com \
    && npm install -g @dcloudio/uni-cli-service@2.0.0-27920200624001 --registry=https://registry.npmjs.org \
    && npm install @dcloudio/vue-cli-plugin-uni@2.0.0-27920200624001 --registry=https://registry.npmjs.org \
    && npm install --legacy-peer-deps

# 构建应用
COPY . .
RUN npm run build

# 生产环境
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;"]
