About .npmignore generator
A .npmignore file controls which files are left out when you publish a package, keeping it small and avoiding accidental leaks.
Usually excluded
- Tests, examples and source maps if not needed.
- Config files for tools and CI.
- Environment files and keys.
Check before publishing
Run npm pack --dry-run to see exactly which files will be included. The files field in package.json is an alternative that lists what to include.
A worked example
For a library, ignore src/ if you publish only dist/, plus tests, .github/, tsconfig.json and example folders. Run npm pack --dry-run to list exactly what will go into the package, and check that it holds no .env or private notes.
Alternative
- The files field in package.json lists what to include, which is safer than listing what to exclude.
- If both exist, the files field wins for the root, though .npmignore still affects subfolders.
