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 RUN apt-get update && \
ENV H5_BASE=/ apt-get install -y --no-install-recommends \
libgtk-3-0 \
# 解决时区问题 libnotify4 \
RUN apk add --no-cache tzdata && \ libnss3 \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ libxss1 \
echo "Asia/Shanghai" > /etc/timezone libxtst6 \
xdg-utils \
libatspi2.0-0 \
libuuid1 \
libsecret-1-0 \
curl \
tar \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app WORKDIR /app
# 复制依赖文件并安装 # 复制项目文件
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com && \
npm install --legacy-peer-deps --no-optional
# 复制源代码
COPY . . COPY . .
# 构建项目 # 安装 HBuilderX CLI
RUN npm run build 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 # 第二阶段:运行环境(按平台分发)
# ===================================================
# 从构建阶段复制产物 # H5 运行环境
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html 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;"]
# 暴露端口 ## Android 运行环境(仅用于保存 APK)
EXPOSE 8333 #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 @@ ...@@ -16,40 +16,19 @@
] ]
}, },
"scripts": { "scripts": {
"build": "uni build -p h5", "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",
"analyze": "uni build -p h5 --analyze", "build:h5": "/opt/HBuilderX/cli build --project . --platform h5",
"lint": "eslint --ext .js,.vue src", "build:android": "/opt/HBuilderX/cli build --project . --platform android",
"test": "jest" "build:ios": "/opt/HBuilderX/cli build --project . --platform ios"
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-app": "^3.0.0-30720220613001",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.13", "dayjs": "^1.11.13",
"echarts": "^5.4.1", "echarts": "^5.4.1",
"js-sha256": "^0.11.1", "js-sha256": "^0.11.1",
"nanoid": "^4.0.0", "nanoid": "^4.0.0"
"vue": "^2.6.14"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.22.5", "less": "^4.3.0"
"@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"
]
} }
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