22 lines
563 B
Docker
22 lines
563 B
Docker
# 多阶段构建:hash 路由不需要 nginx 回退,最终镜像只保留 nginx + dist
|
|
FROM node:24 AS build
|
|
|
|
# 由 magic-docker 传入:--build-arg VERSION=<tag>
|
|
ARG VERSION=0.0.0
|
|
WORKDIR /app
|
|
|
|
# 构建上下文就是 context 目录
|
|
COPY . .
|
|
RUN npm ci
|
|
RUN npm pkg set version="$VERSION"
|
|
|
|
# 有 build-only 脚本就用它(兼容老项目),否则用 build
|
|
RUN if npm run 2>/dev/null | grep -q "build-only"; then \
|
|
npm run build-only; \
|
|
else \
|
|
npm run build; \
|
|
fi
|
|
|
|
FROM nginx:alpine
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|