35 lines
853 B
Docker
35 lines
853 B
Docker
# ---- 构建阶段 ----
|
||
FROM node:22-alpine AS builder
|
||
|
||
WORKDIR /app
|
||
|
||
# 使用国内 npm 镜像
|
||
RUN npm config set registry https://registry.npmmirror.com
|
||
|
||
# 先复制依赖清单,利用 Docker 缓存层
|
||
COPY package.json package-lock.json ./
|
||
|
||
# --mount=type=cache 复用 npm 缓存,依赖不变时跳过下载
|
||
# --no-audit 跳过安全审计,提速明显
|
||
RUN --mount=type=cache,target=/root/.npm \
|
||
npm ci --no-audit
|
||
|
||
# 复制源码并构建(Vite 构建缓存也复用)
|
||
COPY . .
|
||
RUN --mount=type=cache,target=/root/.npm \
|
||
--mount=type=cache,target=/app/node_modules/.vite \
|
||
npm run build
|
||
|
||
# ---- 运行阶段 ----
|
||
FROM nginx:stable-alpine
|
||
|
||
# 复制 Nginx 配置
|
||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||
|
||
# 复制构建产物
|
||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||
|
||
EXPOSE 80
|
||
|
||
CMD ["nginx", "-g", "daemon off;"]
|