Files
hzhub/hzhub-portal-company/Dockerfile.frontend

45 lines
979 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.
# 构建阶段
FROM node:22-alpine AS builder
# 接收构建参数
ARG VITE_API_URL
ARG VITE_APP_ENV=production
# 设置环境变量
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_APP_ENV=${VITE_APP_ENV}
# 设置工作目录
WORKDIR /app
# 复制 package 文件
COPY package.json pnpm-lock.yaml ./
# 安装 pnpm 并安装依赖
RUN npm install -g pnpm && \
pnpm install --frozen-lockfile
# 复制源代码
COPY . .
# 构建生产版本(使用 production 模式)
RUN pnpm build
# 生产阶段
FROM nginx:alpine
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 设置后端地址环境变量(默认指向本机 6039 端口)
ENV UPSTREAM_URL=http://127.0.0.1:6039
# 复制 Nginx 配置并使用 envsubst 替换环境变量
COPY nginx.conf /etc/nginx/templates/default.conf.template
# 暴露端口
EXPOSE 5137
# 启动 Nginxdocker-compose 中可通过环境变量 UPSTREAM_URL 覆盖后端地址)
CMD ["nginx", "-g", "daemon off;"]