'How does Typescript references interact with builds and Docker?
I have a projectA that references a common package that my other Nodejs services will reference as well. The issue is how do I pack this up in a Docker file? Ideally, the tsc build
would build both the project and the dependent common package into the /dist
but that's not the case. (Tried using the prepend but it has to be used on AMD or SYSTEM and cannot be used with node). What are my options to have a shared package in Typescript for multiple Nodejs services and to pack it into a Docker (each service seperately)? I got it working with the project reference (I can use the imports from the shared package) but I dont know how to use the Docker file with this setup.
My docker will look something like this
FROM node:10-alpine
# update packages
RUN apk update
# create root application folder
WORKDIR /app
# copy configs to /app folder
COPY package*.json ./
COPY tsconfig.json ./
# copy source code to /app/src folder
COPY src /app/src
# check files list
RUN ls -a
RUN npm install
RUN npm run build
EXPOSE 7777
CMD [ "node", "./dist/main.js" ]
But with this setup I'll be missing the shared package (project)
root |-serviceA (has docker file) |-serviceB (has docker file) |-shared ( some Mongodb models)
Both depend on shared via references, all three have tconfig
Solution 1:[1]
Did you ever find a clean way to do this? My current approach is to run the docker build from the parent directory and copy the common project as well, but that feels messy
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |