Paz Lazar
Paz Lazar

Reputation: 239

babel watch on docker

i set docker instance with node. i want to develop on this instance and use babel to "compile" my node code. i use @docker/cli to compile with watch flag and i use nodemon with -L flag. for some reason, nodemon is watching file changes great but not babel. any idea?

this is my docker-compose.yml

main-app:
build: ./mainApp
user: "root"
command: yarn run start:watch
environment:
    NODE_ENV: production
    PORT: 8080
volumes:
  - ./mainApp:/app
  - /app/node_modules
ports:
  - '8080:8080'

this is package.json:

"scripts": {
"build": "babel src --out-dir public",
"serve": "node public/server.js",

"build:watch": "babel --watch src -d public -s",
"serve:watch": "nodemon -L public/server.js",

"start:watch": "concurrently -k \"npm run build:watch\" \"npm run serve:watch\""
},
"dependencies": {
    "express": "^4.16.1"
  },
"devDependencies": {
    "@babel/cli": "^7.0.0-beta.35",
    "@babel/core": "^7.0.0-beta.35",
    "@babel/preset-env": "^7.0.0-beta.35"
  },

as you can see i use concurrently to run them both. what can be the problem babel is not watching my files?

PS: it works fine on my local machine

Upvotes: 3

Views: 1573

Answers (3)

Bertrand
Bertrand

Reputation: 13570

Babel CLI uses Chokidar to watch file changes, to make it work inside a linux image you need to:



CHOKIDAR_USEPOLLING=true babel --watch



You can read more about this here

Upvotes: 1

Hemant Kumar
Hemant Kumar

Reputation: 161

babel-watch didn't worked out for me. As I was compiling code through babel cli and outputting in some another directory (to be used by second docker container) I ended up using nodemon exec option In my package.json, created new script especially for docker:

"docker-build:watch": nodemon -L --watch src --exec 'npm run build:watch'

and then using npm run docker-build:watch instead of npm run build:watch

Upvotes: 1

Levi Putna
Levi Putna

Reputation: 3073

I was having a similar issue and ended up using 'babel-watch'. IT still required me to use the -L flag to enable poling to get it to work in Docker. I have not tried it, but the same approach may work with babel itself.

Take a look at the babel-watc readme for more details. https://github.com/kmagiera/babel-watch#troubleshooting

You filesystem configuration doesn't trigger filewatch notification (this could happen for example when you have babel-watch running within docker container and have filesystem mirrored). In that case try running babel-watch with -L option which will enable polling for file changes.

Upvotes: 0

Related Questions