TIL: Creating Tarballs With tar for Deployment Packages
Deploying a project means sending files to a server. tar bundles them into a single archive with permissions, structure, and metadata intact.
tar -czf deploy.tar.gz dist/ node_modules/ package.json
-c creates the archive, -z compresses with gzip, -f specifies the output filename. List which directories and files to include at the end.
tar -xzf deploy.tar.gz
On the server, extract with -x. The directory structure reconstructs exactly as it was.
tar -tf deploy.tar.gz
List the contents of a tarball without extracting it. Handy for checking what a build artifact actually contains before shipping it somewhere.
Should I include node_modules in the tarball?
Do a fresh npm install on the server instead. Most deployment platforms handle this automatically. tar is for the code you wrote, not the dependencies you installed.