npm 运行yarn安装--生产,但我仍然看到所有的开发依赖

ohfgkhjo  于 12个月前  发布在  Yarn
关注(0)|答案(1)|浏览(238)

我正在构建我的Dockerfile,我在我的容器中,我不想看到所有的dev依赖项。我使用RUN yarn install --production,但仍然看到所有的dev依赖项。我需要更改所有的prod构建,使用RUN yarn install --production从锁文件构建依赖项,而不包括dev依赖项。

FROM node:12 as dev
ARG SVC_NAME
ARG SVC_TYPE
ENV srcpath=/usr/src/app
ENV svcpath=services/${SVC_TYPE}/${SVC_NAME}

# Create app directory
WORKDIR ${srcpath}

COPY . .

# install depdendencies
RUN yarn install  

# build the app
WORKDIR ${srcpath}/${svcpath}

RUN mkdir /tmp/configs

RUN yarn build

EXPOSE 3000
CMD [ "yarn", "start" ]

FROM node:12-alpine as prod
ARG SVC_NAME
ARG SVC_TYPE
ENV srcpath=/usr/src/app
ENV svcpath=services/${SVC_TYPE}/${SVC_NAME}

RUN apk add --update
RUN apk add openssl openssl-libs-static openssl-dev

COPY --from=dev /${srcpath}/packages/ /${srcpath}/packages
COPY --from=dev /${srcpath}/node_modules/ /${srcpath}/node_modules/
COPY --from=dev /${srcpath}/yarn.lock /${srcpath}/yarn.lock
COPY --from=dev /${srcpath}/${svcpath} /${srcpath}/${svcpath}
RUN yarn install --production

 
COPY --from=dev /tmp/configs /tmp/configs

# # set the workdir to the compiled artifact path
# WORKDIR ${srcpath}/${svcpath}/dist/src

WORKDIR ${srcpath}

# set the workdir to the compiled artifact path
WORKDIR ${srcpath}/${svcpath}/dist/src

COPY --from=dev /${srcpath}//yarn.lock /${srcpath}/${svcpath}/dist/src  

EXPOSE 3000
CMD [ "node", "index.js" ]

字符串

xv8emn3q

xv8emn3q1#

你正在从dev中复制node_modules,删除那一行,你就没事了。

相关问题