Can I keep a build watcher in docker

Hi, I’m new to rescript.
Now I’m using rescript and webpack on windows. Everything works fine.
But when I try to dockerize the project I got some trouble.

Here is my dockerfile.

FROM node:18

WORKDIR /my-app

COPY package*.json ./
RUN npm install

COPY . .

And here is my docker-compose.yml.

version: '3'
services:
  compiler:
    container_name: compiler
    build: 
      context: .
      dockerfile: dev.dockerfile
    command: npx rescript build -w
    volumes:
      - ./src:/my-app/src
    tty: true

  bundler:
    container_name: bundler
    build: 
      context: .
      dockerfile: dev.dockerfile
    command: bash -c 'npx rescript && npx webpack serve'
    volumes:
      - ./src:/my-app/src
    ports:
      - 4000:4000

Here is the situation.

  1. If I don’t use tty: true, I will quickly get compiler exited with code 0 after >>>> Start compiling.
  2. If I use tty: true, it seems that build watcher can be kept in the container. But it doesn’t compile new file. I have checked the file in the container and it does changed.

Here are my questions.

  1. Is it correct to use tty: true?
  2. Why new file change was not picked up in the container?

Hey there,

It is possible but there are a number of gotchas.

rescript-vite-docker

This is my repo that watches for changes, rebuilds, and builds for production in the docker container. It uses vite instead of webpack and I’ve also separated the generated *.bs.js files from the source. The documentation is lacking and I’ve only run it on linux so far. I use it as a jumping off point for building my work projects.

Thank you so much! I will try it.