使用 Composer 下载依赖项时删除文件

2022-01-21 00:00:00 php composer-php

我确定我曾经在某个地方读过它,但我再也找不到它了,该死!

I am sure I once read it somewhere but I cannot find it anymore anywhere, DAMN!

所以基本上我要做的是在我的 composer.json 文件中为我的某个库指定一些排除标准,以便在用作项目的依赖项时,导入项目不会获取测试文件,.git 文件夹、READ.md 文件和所有这些东西(当你只想要一个库作为依赖而不是用于开发时完全没用).

So basically what I am trying to do is to specify some exclusion criteria in my composer.json file for a certain library of mine so that, when used as a dependency of a project, the importing project does not get test files, .git folders, READ.md files and all that stuff (totally useless when you only want a library as a dependency and not for development).

所以基本上,当我的库作为依赖项下载时,我试图减轻它们的负担.有人说吗?

So basically I am trying to lighten up my libs when they are downloaded as dependencies. Anyone on that?

推荐答案

您可以将 .gitattributes 文件添加到项目根目录,如下所示:

You can add a .gitattributes file to your project root, looking something like this:

/Tests export-ignore
READ.md export-ignore

当有人安装您的依赖项时,此文件将从分发 zip 中排除.作曲家将您的库下载为 zip 有一些先决条件

When someone installs your dependency this files will be excluded from the distribution zip. There are some prerequisites for your lib to be downloaded as a zip by composer

  • 您需要有一个稳定的标记版本.dev-master 将始终被 composer 克隆.
  • 如果用户使用 composer install --prefer-source 进行安装,composer 也会从您的 git 存储库中克隆.
  • You need to have a stable tagged version. dev-master will always be cloned by composer.
  • If the user installs with composer install --prefer-source composer will also clone from your git repo.

在所有其他情况下,composer 将下载 zip,并且 .gitattributes 中的所有文件都将被排除在外.

In all other cases composer will download the zip and all the files in .gitattributes will be excluded from it.

希望这会有所帮助.

相关文章