FROM node:14-alpine AS builder

# 设置工作目录
WORKDIR /app

# 安装系统依赖（uni-app编译可能需要）
RUN apk add --no-cache python3 make g++

# 复制包文件并设置镜像源
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com && \
    npm config set disturl https://npmmirror.com/dist && \
    npm config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ && \
    rm -rf node_modules package-lock.json && \
    npm cache clean --force

# 安装依赖
RUN 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;"]
