One weird trick to minimize Docker image size for Node apps
One way to reduce the size of your Docker images for Node apps is to remove dev dependencies from the node_modules folder.
You can do this with npm prune
npm prune --omit dev
This works great in many situations. But sometimes it’s trickier, such as in a monorepo1.
One simple alternative is to bundle an app’s dependencies together with your app, and not include node_modules in the image at all 😲2.
I know, weird, right? You end up with one giant file, instead of many small ones in node_modules. In a Remix app I’m working it’s 7mb and 200K lines of code.
While it might feel wrong at first, it’s not so different from bundling client builds. Bundling is a valid option to keep in your utility belt.