Files
aiot-uniapp/Dockerfile
feige996 ebd4694aa6 build: 更新构建配置和Dockerfile
- 将Node.js最低版本要求从22降至20以兼容更多环境
- 在vite配置中添加外部依赖解决构建问题
- 重构Dockerfile,优化构建流程并修复依赖安装问题
- 更新nginx配置和容器启动命令
2025-09-17 12:12:50 +08:00

40 lines
1.0 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用官方 Node.js 作为基础镜像;不适用 alpine 版本这样可以自带git
FROM node:latest AS builder
# 在容器中创建目录
WORKDIR /app
# 安装pnpm
RUN npm install -g pnpm@10.10.0
# 设置pnpm镜像源
RUN pnpm config set registry https://registry.npmmirror.com
# 复制依赖文件
COPY package.json pnpm-lock.yaml ./
# 先复制scripts目录因为prepare脚本需要用到其中的文件
COPY scripts ./scripts
# 创建src目录确保create-base-files.js脚本能正常写入文件
RUN mkdir -p src
# 安装依赖
RUN pnpm install
# 复制其余源代码
COPY . .
# 构建项目
RUN pnpm run build
# 使用nginx作为服务
FROM nginx:1.29.1-alpine3.22 AS production-stage
# 将构建好的项目复制到nginx下
COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
# 将默认的nginx配置文件替换为我们自定义的nginx配置文件
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80
EXPOSE 443
# 启动nginx
CMD ["nginx", "-g", "daemon off;"]