Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 986
Paz Lazar Avatar asked May 04 '26 10:05

Paz Lazar


2 Answers

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

like image 188
Hemant Kumar Avatar answered May 07 '26 18:05

Hemant Kumar


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

like image 40
Bertrand Avatar answered May 07 '26 19:05

Bertrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!