2

I am trying to create an image using a multi-stage build for a node project. I am using NestJs for the project since it uses TypeScript, and if I install only production dependency in the production stage it will not install NestJs CLI. Now, NestJs CLI is required to compile all the TypeScipt code to JavaScript. Most of the people or the blogs I have read, what they do is copy the output folder (compiled code from TypeScript to JavaScript) in the production stage which I don't want to do and really don't like the idea of copying the output folder because if I run only production stage via compose or a container it will fail.

Now, I have two options, either I can move the NestJs CLI as dependencies required for production in my package.json file, or I can add NestJs CLI via a RUN command in my Dockerfile, I want to know what would be right or the best way to do it.

1 Answer 1

1

I would do this in the Dockerfile, as the NextJs CLI will be a hard dependency for the application. It should be exclusively defined in the Dockerfile. This way we can pin a version of NextJs CLI. Another bright side to this is that all similar application can now end up having the same Dockerfile and any changes to the NextJs version will now be an image change instead of an application change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.