Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

package.json files字段 & .npmignore

$
0
0

package.json files & .npmignore

https://docs.npmjs.com/files/package.json#files

The “files” field is an array of files to include in your project. If you name a folder in the array, then it will also include the files inside that folder. (Unless they would be ignored by another rule.) You can also provide a “.npmignore” file in the root of your package or in subdirectories, which will keep files from being included, even if they would be picked up by the files array. The .npmignore file works just like a .gitignore.

  • package.json files 就是白名单, 不写这个字段就默认是所有文件
  • .npmignore则是黑名单, 排除掉, 即使在 files 里写了, 还是会排除掉. 该文件还可以写在子文件夹中

例外

不管怎么配置 package.json / README.md / CHANGELOG.md / LICENSE / LICENCE 都会包含在 publish 的 package 中

不管怎么配置, 下面这些都不会被包含

.git
CVS
.svn
.hg
.lock-wscript
.wafpickle-N
*.swp
.DS_Store
._*
npm-debug.log

以前造的小轮子都把 package.json / README.md / CHANGELOG.md / LICENSE写在 files 里, 今天再查发现它们会自动包含… 为宇宙的熵增着想, 我们应该忽略它, let npm take care of it…


Viewing all articles
Browse latest Browse all 14821

Trending Articles