Commit 834b943e by zhangxingmin

push

parent 08456d6a
node_modules/
unpackage/
.git/
.hbuilderx/
Dockerfile
Jenkinsfile
*.md
# 构建阶段
FROM node:16.20.2-alpine3.18 AS builder
# 第一阶段:构建环境
FROM node:16.20.2-bullseye-slim AS builder
# 设置环境变量
ENV NODE_ENV=production
ENV H5_BASE=/
# 解决时区问题
RUN apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 安装基础依赖
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libgtk-3-0 \
libnotify4 \
libnss3 \
libxss1 \
libxtst6 \
xdg-utils \
libatspi2.0-0 \
libuuid1 \
libsecret-1-0 \
curl \
tar \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app
# 复制依赖文件并安装
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com && \
npm install --legacy-peer-deps --no-optional
# 复制源代码
# 复制项目文件
COPY . .
# 构建项目
RUN npm run build
# 安装 HBuilderX CLI
RUN npm run hb-setup
ENV PATH="/opt/HBuilderX:${PATH}"
# 生产运行阶段
FROM nginx:1.25.2-alpine
# 设置构建参数
ARG BUILD_PLATFORM=h5
ENV UNI_PLATFORM=$BUILD_PLATFORM
# 删除默认配置
RUN rm -rf /etc/nginx/conf.d/default.conf
# 执行构建
RUN hbuilderx build --project /app --platform $BUILD_PLATFORM
# 复制自定义Nginx配置
COPY nginx.conf /etc/nginx/conf.d
# ===================================================
# 第二阶段:运行环境(按平台分发)
# ===================================================
# 从构建阶段复制产物
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
# H5 运行环境
FROM nginx:1.25.2-alpine AS h5-runtime
COPY --from=builder /app/unpackage/dist/build/h5 /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# 暴露端口
EXPOSE 8333
## Android 运行环境(仅用于保存 APK)
#FROM alpine:3.18 AS android-runtime
#COPY --from=builder /app/unpackage/dist/build/android /app
#VOLUME /output
#CMD ["sh", "-c", "cp /app/*.apk /output"]
#
## iOS 运行环境(仅用于保存 IPA)
#FROM alpine:3.18 AS ios-runtime
#COPY --from=builder /app/unpackage/dist/build/ios /app
#VOLUME /output
#CMD ["sh", "-c", "cp /app/*.ipa /output"]
# 启动Nginx
CMD ["nginx", "-g", "daemon off;"]
# ===================================================
# 最终阶段:根据构建参数选择目标平台
# ===================================================
ARG TARGET_PLATFORM=h5
FROM ${TARGET_PLATFORM}-runtime AS final
......@@ -16,40 +16,19 @@
]
},
"scripts": {
"build": "uni build -p h5",
"analyze": "uni build -p h5 --analyze",
"lint": "eslint --ext .js,.vue src",
"test": "jest"
"hb-setup": "mkdir -p /opt/HBuilderX && curl -L https://download.dcloud.net.cn/HBuilderX/cli/hbuilderx-linux.tar.gz | tar -xz -C /opt/HBuilderX --strip-components=1",
"build:h5": "/opt/HBuilderX/cli build --project . --platform h5",
"build:android": "/opt/HBuilderX/cli build --project . --platform android",
"build:ios": "/opt/HBuilderX/cli build --project . --platform ios"
},
"dependencies": {
"@dcloudio/uni-app": "^3.0.0-30720220613001",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.13",
"echarts": "^5.4.1",
"js-sha256": "^0.11.1",
"nanoid": "^4.0.0",
"vue": "^2.6.14"
"nanoid": "^4.0.0"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@dcloudio/uni-h5": "^3.0.0-30720220613001",
"@dcloudio/vue-cli-plugin-uni": "^3.0.0-30720220613001",
"@vue/cli-plugin-babel": "^4.5.19",
"@vue/cli-plugin-eslint": "^4.5.19",
"@vue/eslint-config-standard": "^6.1.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^7.20.0",
"jest": "^29.6.2",
"less": "^4.3.0",
"less-loader": "^10.0.1",
"postcss-pxtorem": "^6.0.0",
"vue-jest": "^5.0.0",
"webpack": "^4.46.0",
"webpack-bundle-analyzer": "^4.8.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
"less": "^4.3.0"
}
}
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