Publishing to npm and Semantic Versioning
Automate releases with changesets or semantic-release and publish scoped packages to the npm registry.
npm publish --dry-run
Before publishing, always run npm publish --dry-run. This simulates the publish without actually uploading anything, showing you exactly which files would be included, their sizes, and the package tarball contents. It catches common mistakes like accidentally including source files or missing the dist directory.
Controlling Published Files
Control what gets published using the files field in package.json: "files": ["dist", "README.md"]. This whitelist approach is safer than .npmignore (which is a blacklist and can leak sensitive files if you forget to add them). Always include dist, type declarations, and documentation. Never include src, tests, or node_modules.
All lessons in this course
- Bundling with Rollup and tsup for Libraries
- ESM and CJS Dual Package Output
- Peer Dependencies and Tree Shaking
- Publishing to npm and Semantic Versioning