# https://stackoverflow.com/questions/53681522/share-variable-in-multi-stage-dockerfile-arg-before-from-not-substituted ARG PROJECT_DIR=/huaxin-base-frontend FROM node:20-slim as builder ARG PROJECT_DIR WORKDIR $PROJECT_DIR # 安装pnpm RUN npm install -g pnpm COPY . ./ # 安装依赖 # 若网络不通,可以使用淘宝源 # RUN pnpm config set registry https://registry.npmmirror.com # see https://pnpm.io/docker FROM builder AS prod-deps RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile FROM builder AS build RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN pnpm run build # mirror acceleration # RUN npm config set registry https://registry.npmmirror.com # RUN pnpm config set registry https://registry.npmmirror.com # RUN npm config rm proxy && npm config rm https-proxy FROM builder COPY --from=prod-deps $PROJECT_DIR/node_modules $PROJECT_DIR/node_modules COPY --from=build $PROJECT_DIR/dist $PROJECT_DIR/dist # 构建项目 ENV VITE_BASE_URL=/ RUN pnpm build FROM nginx:alpine as production ARG PROJECT_DIR COPY --from=builder $PROJECT_DIR/dist/ /usr/share/nginx/html COPY --from=builder $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf EXPOSE 80