While looking at the axios source code recently, I saw a file named.npmignore in the project root directory. A search of the documentation revealed that it is a blacklisting mechanism used to exclude certain files or directories when the package is released.
Content syntactic format
It’s basically the same thing as.gitignore. Here is the configuration from the AXIos source code:
**/.*
*.iml
coverage/
examples/
node_modules/
typings/
sandbox/
test/
bower.json
CODE_OF_CONDUCT.md
COLLABORATOR_GUIDE.md
CONTRIBUTING.md
COOKBOOK.md
ECOSYSTEM.md
Gruntfile.js
karma.conf.js
webpack.*.js
sauce_connect.log
Copy the code
You can see that any in the secondary directory is ignored. Examples, sandbox, test, webpack, Grunt, Karma configuration files. There must also be a node_modules directory.
In addition, if this file is not specified, NPM treats.gitignore as.npmignore by default
Compare the project directory with the published package directory
Again, take Axios.
Project Contents:
Package directory for final publication to NPM:
Setting a Whitelist
For example, if I have a very complete.nPMIgnore list and I don’t want to touch it, but I want to release some files from the list and upload them to NPM, what can I do?
The answer is: by configuring the files field in package.json. For example, my.npmignore listing ignores examples entire directories:
examples
Copy the code
Configure the files field in package.json to release the examples white-label. TXT file:
{
"files": [
"examples/white-label.txt"],}Copy the code
Priority problem
If the project exists. Gitignore,.npmignore and files field is configured, the priority is as follows: files>.npmignore>.gitignore.