Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Building a Minimalist Docker Image with Node, TypeScript

Posted on Sep 6 In this article we are going to have a look at creating a production grade docker image with Node.JS, TypeScript.We are also going to use the speedy web compiler to compile the source code blazing fast. Lets dive right in.Now break the steps and optimise the build image one by one.We're enabling pnpm using corepack. Your package.json should have "packageManager": "[email protected]". You can refer the complete package.json in the document below.--mount=type=cache: Tells Docker to mount a cache during the build process. This cache will store data across builds, improving build speed by reusing data.id=pnpm: This is an identifier for the cache. If multiple projects use the same identifier, they will share the same cache, although this could be risky due to possible data contamination between unrelated projects.target=/pnpm/store: Specifies where in the Docker image the cache should be stored.The image size is 160mb Comparing against my old simple docker setup. Old setup was based on a alpine image. The build image size was round 650mbA "distroless" image is a stripped-down container image that contains only the application and its runtime dependencies. Just your application dependencies and nothing else. No build tools, shell, package managers or anything. You can check that on the 4th stage. Thanks Google !SWC is a super-fast TypeScript / JavaScript compiler written in Rust. We can use SWC for both development and production environments as well. In this setup we are using swc to speed up the compilation time of both development and production. In development environment swc is used along with ts-node and in production we're using tswc, which compiles the files using swc Here is the complete DockerfileHere is the tsconfigHere is the package.jsonHere is the source code for this setup : https://github.com/JacobSamro/docker-typescript-pnpmTemplates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Ajeet Singh Raina - Jun 13 Vincent A. Cicirello - May 31 Maxime - Jun 3 Learn2Skills - Jun 10 Once suspended, jacobsamro will not be able to comment or publish posts until their suspension is removed. Once unsuspended, jacobsamro will be able to comment and publish posts again. Once unpublished, all posts by jacobsamro will become hidden and only accessible to themselves. If jacobsamro is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Jake. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag jacobsamro: jacobsamro consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging jacobsamro will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Building a Minimalist Docker Image with Node, TypeScript

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×