Files
shengsuan-homepage/Dockerfile
T
2026-08-06 02:28:42 +00:00

28 lines
864 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:20-alpine AS build
WORKDIR /app
# 构建阶段必须是开发环境,否则 npm 会跳过 devDependenciestsc/vite 缺失 → 127
ENV NODE_ENV=development
# 先只拷贝依赖清单,利用 Docker 层缓存加速重复构建
COPY package.json package-lock.json* ./
# 国内网络环境可取消下一行注释使用镜像源
# RUN npm config set registry https://registry.npmmirror.com
RUN npm install --include=dev
# 拷贝源码并构建(产物输出到 /app/dist)
COPY . .
RUN npm run build
# ---------- 第二阶段:运行 ----------
FROM nginx:1.27-alpine
# 单页应用 Nginx 配置(SPA 回退 + 静态资源缓存)
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 拷贝构建产物
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]