package.json files字段 & .npmignore
发布于 1 年前 作者 magicdawn 1128 次浏览 来自 分享

package.json files & .npmignore

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 / / / LICENSE / LICENCE 都会包含在 publish 的 package 中

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


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

1 回复