When NPM publishes, all files in the project directory are published to the NPM repository, but some directories and files are not published, such as the project source code, compiled scripts, etc.
Method one:
Use.gitignore to set which files to ignore
Ignore files set to.gitignore are ignored in git code management and NPM publish
Method 2:
Use.npmignore to set which files to ignore
.npmignore is written exactly the same as.gitignore. If both. Npmignore and. Gitignore are used, only. Npmignore takes effect and has a higher priority.
Method 3:
Use the files field of package.json to select which files to publish
Set which files or directories to publish directly in the package.json files field. This priority is higher than.npmignore and.gitignore.