BretFisher/node-docker-good-defaults

Typescript integration

diegolaciar opened this issue · 5 comments

Hi Bret,

I'm using typescript with node.

the command 'npm run build' generate the compiled sources on 'dist' folder.

I want to ask you how would you update the Dockerfile to use a prepiler as typescript or babel with node? What is best practice on this case?

Thanks,
Diego

  1. add that command to the Dockerfile in a RUN line after code is copied in
  2. add that to nodemon config so it runs on every node restart for local development

Good question, so this would be a good example for this repo so I'll add it as a feature request.

focux commented

I'm also using Typescript but I'm having a problem with my IDE (VSCode). For types to work, it needs to load @types files but when VSCode try to find the types inside node_modules folder, it can't find it because that folder is inside the container. Is there any work around to make this work?

@focux Compare with Microsoft recipe, which installs in host:

https://github.com/Microsoft/vscode-recipes/tree/master/Docker-TypeScript

@focux in cases where you need host tools to see node_modules, then you could:

  1. Just run npm install on host purely for tools like VSCode. If you’re keeping container node_modules in container like this repo example shows, they shouldn’t conflict.
  2. Move to a node_modules model where you are bind-mounting the app directory and using the node_modules below it. This means you’d change compose yaml to not hide host node_modules and you’d need to then “initialize” the host node_modules dir from inside the container with something like docker-compose run node npm i before doing a docker-compose up. This way you simplify the node_modules config on both host and container and VSCode will work, but you loose the advantage of having node_modules in container on a different path, which means you have to be careful not to ever do a npm install from host.