Publishing and consuming npm packages via GitHub Releases
Sometimes I build a project in public, but as a personal project, I don't want to publish the package to the npm registry. However, a valid tarball generated by npm pack or pnpm pack is installable as an npm package as well.
Here's how I publish and consume npm packages via GitHub Releases:
Publishing
- I use
pnpm packto generate a tarball. - I use
gh release createto create a release, uploading the built package file as an asset.
See notes-frontend build workflow for an example of a GitHub Actions workflow that does that.
Consuming
To consume the package, I just pass the download URL to pnpm add, e.g.:
pnpm add https://github.com/user/repo/releases/download/v1.0.0/package-1.0.0.tgz