What good is the dist/ folder?

System Information
  • Strapi Version: 4.7
  • Operating System: *nix
  • Database: PostgreSQL
  • Node Version: 18
  • NPM Version: 9.5

So I was tasked with improving our build process and making the deployed artifact smaller. The obvious first thing was to stop copying all the source code (including node_modules) and instead only include the transpiled code from dist/ in the Docker image. But then I discovered that Strapi just doesn’t work like this - it has checks to make sure package.json is present and tries to load stuff from node_modules.

This leaves me rather perplexed - why would I include raw source code (and dependencies) in a production image? Isn’t (one of) the point of the whole build pipeline to be able to deliver a small, streamlined and optimized artifact? What good is running strapi build ahead of time, if we have to add everything including the kitchen sink in our deployments?