Commit f81f011a by zhangxingmin

push

parent 3c2c44f0
# 替换基础镜像为Node.js 16 # 注意:此方案需要在Docker中安装HBuilderX CLI,步骤较特殊
FROM node:16-alpine AS builder FROM node:16-alpine AS builder
WORKDIR /app WORKDIR /app
# 系统依赖配置 # 安装HBuilderX CLI(关键:使用官方提供的CLI工具,而非npm包)
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ RUN apk add --no-cache wget unzip \
&& apk add --no-cache python3 make g++ && wget https://download.dcloud.net.cn/hbuilderx/alpha/HBuilderX.3.99.20231011.full.zip -O hbx.zip \
&& unzip hbx.zip -d /opt/hbuilderx \
&& chmod +x /opt/hbuilderx/cli
# 复制修正后的package.json # 复制项目文件(假设项目是HBuilderX创建的标准结构)
COPY package.json ./
# 重新安装依赖(使用官方源+适配Node.js 16)
RUN npm config set registry https://registry.npmjs.org \
&& npm cache clean --force \
&& npm install --legacy-peer-deps
# 复制源代码并构建
COPY . . COPY . .
RUN npm run build:h5
# 使用HBuilderX CLI构建H5项目(避开npm依赖)
RUN /opt/hbuilderx/cli publish --platform h5 --project . --outDir dist
# 生产环境 # 生产环境
FROM nginx:1.21-alpine FROM nginx:1.21-alpine
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8333 EXPOSE 8333
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment