Files
ogame-vue-ts/Dockerfile
coolxitech 469c5a0170 feat(docker): 优化Docker构建流程并支持生产环境部署
- 引入多阶段构建,分离构建与运行时环境
- 使用node:20-alpine作为构建基础镜像,减小体积
- 添加pnpm包管理器并优化依赖安装流程
- 利用缓存机制提升构建效率
- 新增nginx.conf配置文件解决Vue Router历史模式404问题
- 设置静态资源缓存策略提升性能
- 更改默认启动命令为Nginx服务方式运行应用
- 移除开发服务器相关指令,适配生产部署需求
2025-12-13 10:19:58 +08:00

33 lines
729 B
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.
# ========= 阶段1构建 =========
FROM node:20-alpine AS builder
# 使用国内镜像加速(可选)
RUN npm config set registry https://registry.npmmirror.com
WORKDIR /app
# 先复制依赖文件,利用缓存
COPY package.json pnpm-lock.yaml* ./
# 安装 pnpm 并安装依赖
RUN corepack enable && corepack prepare pnpm@latest --activate \
&& pnpm install --frozen-lockfile
# 复制源码
COPY . .
# 生产构建
RUN pnpm run build
# ========= 阶段2运行时 =========
FROM nginx:alpine
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 解决 Vue Router history 模式 404 问题
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]