What exactly should I put in .npmignore?
Tests? Stuff like .travis.yml, .jshintrc? Anything that isn't needed when running the module (except the readme)?
I can't find any guidance on this.
As you probably found, NPM doesn't really state specifically what should go in there, rather they have a list of ignored-by-default files. Many people don't even use it as everything in your .gitignore is ignored in npm by default if .npmignore doesn't exist. Additionally, many files are already ignored by default regardless of settings and some files are always excluded from being ignored, as outlined in the link above.
There is not much official on what always should be there because it is basically a subset of .gitignore, but from what I gather from using node for 5-ish years, here's what I've come up with.
Note: By production I mean any time where your module is used by someone and not to develop on the module itself.
.coffee files in your package but keep tracking them in your git repository.node-gyp might have object files that get generated during a build that never should go into the package..gitignore anyway. You must place these things inside here if you are using a .npmignore file already as it overrides .gitignore from npm's point of view..travis.yml are not required for using, testing, or viewing the code.CNAME files or placeholder index.htmls if you use your module serves double-duty as a gh-pages repository as well.npm install, I should only be relying on npm and no other external sources.Basically, you should ever use it if there is something you wish to keep out of your npm package but checked-in to your module's repo. It's not a long list of items, but npm would rather build in the functionality than having people stuck with irrelevant objects in their package.
I agree with lante's short and syntetic answer and SamT's big answer:
My contribution to those answers:
.npmignore is the blacklist way to achieve package file selection. But in a more practical way, you can whitelist files you need to include in your package using the files field in your package.json:
{
"files": [
"lib/",
"index.js"
]
}
I think that's simpler, future proof and have better semantics ;)
npm test across all node_modules can give you a hint if something works different in a certain environment..npmignore. files: ["lib", "!lib/**/*.test.js"]. :)Just to clarify, anytime someone do npm install your-library, npm will download all source files that the package includes. Those files that were included in the .npmignore file in the source code of the package your-library will be excluded when publishing the lib, so users of your-library won't download them.
Know that people installing your library will need just your library running, anything else will be not necessary.
For example, when someone installs a library, its probably that he/she doesn't care about your .travis.yml or your .jshintrc files, or even some images, Grunt files, documentation, etc.
.npmignore could let your npm package to have less files, and faster to be downloaded
.npmignore doesn't directly affect what's downloaded, it affects what goes into your package when you npm publish and upload. This indirectly does create smaller files to download.Don't include your tests. Oftentimes tests are like 5x the size of the actual codebase. As long as your tests are on Github, etc, that's good enough.
But what you absolutely should do is test your NPM package in its published format. Create some smoke tests that reside in the actual codebase, but are not part of the test suite.
You can read about testing your package after tarballing it, here: https://github.com/ORESoftware/r2g
How to test an `npm publish` result, without actually publishing to NPM?
If you want your package to score high on quality on npmjs.com, you should include everything that npm thinks is important:
Quality includes considerations such as the presence of a README file, stability, tests, up-to-date dependencies, custom website, and code complexity. (Source)
So you want to include your README to the package. And after some experimenting: including the tests (and with these the sources) also increases your quality score.
npm install yourlibrary, for example.travis.ymland.jshintrc.npmignoreor"files"(docs.npmjs.com/files/package.json#files).