This commit is contained in:
aaron 2025-03-06 19:26:55 +08:00
parent 3bb2b29b5d
commit a4acc4752d

View File

@ -1,5 +1,5 @@
# 构建阶段
FROM node:16 AS builder
FROM node:16-alpine as build-stage
WORKDIR /app
@ -10,14 +10,16 @@ ENV NODE_ENV=${NODE_ENV}
# 复制 package.json 和 package-lock.json
COPY package*.json ./
# 安装依赖
RUN npm install
# 安装 yarn 并使用 yarn 安装依赖
RUN npm install -g yarn && \
yarn config set registry https://registry.npmmirror.com && \
yarn install
# 复制源代码
# 复制项目文件
COPY . .
# 构建应用
RUN npm run build
RUN yarn build
# 生产阶段
FROM nginx:stable-alpine
@ -38,7 +40,7 @@ RUN mkdir -p /var/cache/nginx/client_temp \
COPY nginx.conf /etc/nginx/nginx.conf
# 从构建阶段复制构建结果
COPY --from=builder /app/dist /usr/share/nginx/html
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 修改目录权限
RUN chown -R nginx:nginx /usr/share/nginx/html \