# 使用官方的Node.js镜像作为基础镜像
FROM node:14-alpine as build-stage

# 设置工作目录
WORKDIR /app

# 将package.json和package-lock.json添加到工作目录中
COPY package*.json ./

# 安装依赖
RUN npm install

# 将源代码添加到工作目录中
COPY . .

ARG ONLINE=no
RUN if [ "$ONLINE" = "yes" ]; then \
        cp config_jx.json config.json; \
    fi

# 构建应用
RUN npm run build:prod

# 使用nginx作为生产环境
FROM nginx:stable-alpine as production-stage

# 将构建阶段的文件复制到nginx的html目录
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 将nginx配置文件复制到容器中
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
