FROM node:14-alpine AS js-builder
WORKDIR /app
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories
RUN apk --no-cache add make g++ git python3
RUN npm config set registry https://registry.npm.taobao.org
RUN npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ && \
    npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/ && \
    npm config set nodejieba_binary_host_mirror https://npm.taobao.org/mirrors/nodejieba
COPY package.json ./
RUN npm install
COPY . .

FROM js-builder AS dev
CMD ["npm", "run", "staging"]

FROM js-builder AS prod-builder
RUN npm run build

FROM nginx:stable-alpine AS prod
COPY --from=prod-builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
