Commit 5c6d2ab6 by zhangxingmin

push

parent ffc40ee0
# 第一阶段:构建项目
FROM node:16-alpine AS builder FROM node:16-alpine AS builder
# 设置工作目录
WORKDIR /app WORKDIR /app
# 安装HBuilderX(使用最新稳定版链接,避免alpha版过期) # 替换国内镜像源(加速依赖安装)
RUN apk add --no-cache wget unzip \ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& wget https://download.dcloud.net.cn/hbuilderx/latest/HBuilderX.4.0.14.20240425.full.zip -O hbx.zip \
&& unzip hbx.zip -d /opt/hbuilderx \
&& chmod +x /opt/hbuilderx/cli # 确保cli可执行
# 复制项目文件 # 复制依赖文件(优先复制,利用 Docker 缓存)
COPY package.json package-lock.json ./
# 安装依赖(使用淘宝镜像加速)
RUN npm config set registry https://registry.npmmirror.com \
&& npm install --legacy-peer-deps
# 复制源代码
COPY . . COPY . .
# 使用HBuilderX CLI构建H5项目 # 构建生产产物
RUN /opt/hbuilderx/cli publish --platform h5 --project . --outDir dist RUN npm run build
# 生产环境 # 第二阶段:部署到 Nginx
FROM nginx:1.21-alpine FROM nginx:1.21-alpine
# 复制构建产物到 Nginx 静态目录
COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
# 复制自定义 Nginx 配置(解决单页应用路由问题)
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 8333 EXPOSE 8333
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]
...@@ -26,11 +26,13 @@ ...@@ -26,11 +26,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" "vue": "^2.6.14",
"vue-router": "^3.5.4"
}, },
"devDependencies": { "devDependencies": {
"@dcloudio/uni-cli-service": "^3.0.0", "vite": "3.2.7",
"@dcloudio/vue-cli-plugin-uni": "^3.0.0", "vite-plugin-vue2": "^2.0.3",
"vue-template-compiler": "^2.6.14",
"less": "^4.3.0" "less": "^4.3.0"
} }
} }
import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2' // 引入 Vue 2 插件
export default defineConfig({
plugins: [createVuePlugin()], // 启用 Vue 2 插件
build: {
target: 'es2015', // 兼容旧浏览器
outDir: 'dist' // 构建输出目录(与 Docker 同步)
},
server: {
host: '0.0.0.0', // 允许容器内访问开发服务器
port: 5173
}
})
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