Npm build in Dockerfile won't generate 'dist' folder

I’m trying to write a Dockerfile for a Node.js application that is already running in production. I believe the dist folder is generated after running npm run build, but after running this command in my Dockerfile, the dist folder isn’t being generated.

My Dockerfile is as follows:

FROM node:10-alpine as BUILD
WORKDIR /src
COPY package*.json /src
RUN apk add --update --no cache \
    python \
    make \
    g++
RUN npm install
COPY . /src
RUN npm run build

How can I generate the dist folder?

Add a line to copy the dist folder from the build environment to the final environment in your Dockerfile. Here is the updated Dockerfile:

FROM node:10-alpine as BUILD
WORKDIR /src
COPY package*.json /src
RUN apk add --update --no cache \
    python \
    make \
    g++
RUN npm install
COPY . /src
RUN npm run build

FROM node:10-alpine
WORKDIR /app
COPY --from=BUILD /src/dist /app/dist  # Add this line
COPY package*.json /app
RUN npm install --only=production
COPY . /app
CMD ["npm", "start"]

This line will copy the dist folder from the build environment to the final environment:

COPY --from=BUILD /src/dist /app/dist

Make sure to place this line after the first FROM statement to ensure that it is executed in the correct environment.