我应该 .npmignore 我的测试吗? [英] Should I .npmignore my tests?

查看:34
本文介绍了我应该 .npmignore 我的测试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到底应该在 .npmignore 中放什么?

What exactly should I put in .npmignore?

测试?诸如 .travis.yml.jshintrc 之类的东西?运行模块时不需要的任何东西(自述文件除外)?

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.

推荐答案

正如您可能发现的,NPM 并没有真正具体说明应该在那里做什么,而是他们有一个 默认忽略文件列表.许多人甚至不使用它,因为如果 .npmignore 不存在,npm 默认会忽略 .gitignore 中的所有内容.此外,默认情况下,无论设置如何,许多文件已经被忽略,并且某些文件总是被排除在忽略之外,如上面的链接所述.

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.

关于什么总是应该在那里的官方没有太多,因为它基本上是 .gitignore 的一个子集,但是从我使用 node 5 年以来收集的信息来看,这就是我所拥有的想出来.

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.

  • 优点:如果您使用交叉编译成 JavaScript 的语言,您可以在发布前进行预编译,并且不将 .coffee 文件包含在您的包中,但要继续跟踪它们在您的 git 存储库中.
  • Pros: If you are using a language that cross-compiles into JavaScript, you can precompile before release and not include .coffee files in your package but keep tracking them in your git repository.
  • 优点:使用 node-gyp 之类的东西的人可能会在构建过程中生成不应该放入包中的对象文件.
  • 缺点:无论如何,这应该总是进入.gitignore.如果你已经在使用 .npmignore 文件,你必须把这些东西放在这里,因为它从 npm 的角度覆盖了 .gitignore.
  • Pros: People using things like node-gyp might have object files that get generated during a build that never should go into the package.
  • Cons: This should always go into the .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.
  • 优点:生产代码中的包袱更少.
  • 缺点:如果出现系统特定的故障(例如导致测试失败的节点运行版本过时),您无法在实时环境中运行测试.莉>
  • Pros: Less baggage in your production code.
  • Cons: You cannot run tests on live environments in the slim chance there is a system-specific failure, such as an out of date version of node running that causes a test to fail.
  • 优点:同样,行李更少.使用、测试或查看代码不需要诸如 .travis.yml 之类的东西.
  • Pros: Again, less baggage. Things such as .travis.yml are not required for using, testing, or viewing the code.
  • 优点:行李少.有些人认为,如果您不能在自述文件中表达至少最小可行的功能,那么您的模块就太大了.
  • 缺点:人们无法在自己的文件系统上看到详尽的文档和代码示例.他们必须访问存储库(这也需要互联网连接).
  • Pros: Less baggage. Some people exist in the school-of-thought where if you cannot express at least minimum viable functionality in your Readme, your module is too big.
  • Cons: People cannot see exhaustive documentation and code examples on their own file system. They would have to visit the repository (which also requires an internet connection).
  • 优点:如果你使用你的模块,你当然不需要用 CNAME 文件或占位符 index.html 乱扔你的版本也作为 gh-pages 存储库提供双重服务.
  • Pros: You certainly don't need to litter your releases with CNAME files or placeholder index.htmls if you use your module serves double-duty as a gh-pages repository as well.
  • 优点:如果您决定在发布之前构建您的依赖项,您不需要最终用户安装 bower 然后安装更多的东西.就个人而言,我会把那些东西放在包里.当我执行 npm install 时,我应该只依赖 npm 而没有其他外部资源.
  • Pros: If you decide to build in your dependencies prior to release, you don't need the end-user to install bower then install more things with that. I would, personally, keep that stuff in the package. When I do an npm install, I should only be relying on npm and no other external sources.

基本上,如果您希望将某些内容排除在 npm 包之外,但又不想排除在 npm 存储库之外,则您应该使用它.这不是一个很长的项目列表,但 npm 宁愿内置功能,也不愿让人们在他们的包中使用不相关的对象.

Basically, you should ever use it if there is something you wish to keep out of your npm package but not out of your npm repository. 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.

这篇关于我应该 .npmignore 我的测试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆