Generated files during build time are not updating between builds

Hello

My project has a /src directory which gets compiled into a /dist directory with a RUN command in the Dockerfile (should it be done in runtime actually?). In development, I use a volume from all my project directory to the container directory to update code between both sides, and this was causing the generated /dist directory to be overshadowed by the volume and not seen in the container which made it fail as the file was not found.

My solution was to create another volume on the /dist directory which made the bundled file visible at runtime and it ran correctly. That was on the first try, after that I changed a file, rebuilt the image and ran it again but the bundled file remained the same.

Is this normal behavior or a bug?

What I’m trying to achieve at the very end is that, at development, when I make a change in the host directory /src the /dist is rebuilt if needed and runs after that.

Thanks in advance for any help

docker-compose.yml

version: "3.3"
services:
  server:
    build: .
    image: selina-server
    volumes:
      - ./:/usr/app/selina-server
      - /usr/app/selina-server/node_modules
      - /usr/app/selina-server/dist
    ports:
      - 3000:3000

Dockerfile

FROM node:latest

LABEL version="1.0"
LABEL description="This is the Selina server Docker image."
LABEL maintainer="AJ alvaroo@selina.com"

WORKDIR "/tmp"

COPY ["package.json", "yarn.lock*", "./"]

RUN ["yarn"]

WORKDIR "/usr/app/selina-server"

RUN ["ln", "-s", "/tmp/node_modules"]

COPY [".", "./"]

RUN ["yarn", "run", "build"]

EXPOSE 3000

CMD ["yarn", "start"]

.dockerignore

.git
.gitignore

node_modules
npm-debug.log

dist

package.json

{
  "scripts": {
    "build": "webpack",
    "start": "node dist/bundle.js"
  }
}