微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于生产的 Docker/React 构建:我的构建文件夹始终为空

如何解决用于生产的 Docker/React 构建:我的构建文件夹始终为空

我有一个多阶段 Dockerfile,它在开发中效果很好,但是当我尝试为生产部署时,构建文件夹保持为空。我看不出哪里出了问题,应该对我有用。这是 Dockerfile:

ARG NODE_VERSION=13
ARG Nginx_VERSION=1.17


# "development" stage
FROM node:${NODE_VERSION}-alpine AS api_platform_client_common

EXPOSE 3000

workdir /usr/src/client

RUN yarn global add @api-platform/client-generator

RUN apk --no-cache --virtual build-dependencies add \
  python \
  make \
  build-base

# prevent the reinstallation of node modules at every changes in the source code
copY package.json yarn.lock ./
RUN set -eux; \
  yarn install

copY . ./

VOLUME /usr/src/client/node_modules

#ENV HTTPS true

FROM api_platform_client_common AS api_platform_client_development

CMD ["yarn","dev"]


# "build" stage
# depends on the "development" stage above
FROM api_platform_client_common AS api_platform_client_build

workdir /usr/src/client

ARG REACT_APP_API_ENTRYPOINT

ENV NODE_ENV production

RUN set -eux; \
  npm run build
  #yarn build

RUN npm install -g serve

CMD serve -s build -l 3000

是更复杂的 docker-compose 设置的一部分,但我认为其余文件无关紧要。当构建步骤发生时,我有日志说它已经生成

File sizes after gzip:

  914.33 KB  build/static/js/2.fb074eef.chunk.js
  25.57 KB   build/static/js/main.2c9c53c7.chunk.js
  23.82 KB   build/static/css/main.581e45d5.chunk.css
  12.56 KB   build/static/css/2.5dd93f16.chunk.css
  773 B      build/static/js/runtime-main.09b85ec0.js

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

但是当我访问 npm serve 提供的内容时,我只会看到带有空白窗口的“构建中的文件/”。当我在我的 docker 容器中运行“ls /usr/src/client/build”时,它实际上是空的...

有人能看到有什么问题吗?

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。