如何使用Composer忽略目录? [英] How to ignore directories with Composer?
问题描述
我想发布一个PHP库,并在 Packagist 上提交,以便通过合作伙伴。
I'd like to release a PHP library and submit it on Packagist to have it installable via Composer.
我的图书馆具有以下结构:
My library has the following structure:
lib/
tests/
composer.json
README.md
基本上,当我将这个库包含在项目的 composer.json
中时,我想要复制所有内容, code> tests 目录,这是麻烦的,只需要开发库本身。这是浪费空间否则(特别是当包装项目为生产)。
Basically, whenever I include this library in a project's composer.json
, I'd like everything to be copied with the exception of the tests
directory, which is cumbersome and is only needed when developing the library itself. It's just a waste of space otherwise (especially when packaging the project for production).
可以从库的作曲家排除此目录。 json
?
推荐答案
这在Composer中是不可能的。但是,有一些方法可以做到:
This is not possible in Composer. However, there are some ways to do it:
-
当您使用
--prefer-dist
,Composer尝试在github上下载归档文件。您可以通过将它放在项目根目录中的.gitattributes
文件中,从归档中删除测试目录:
When you run the update or install command with
--prefer-dist
, Composer tries to download the archive on github. You can remove the test directory from the archives by putting this in a.gitattributes
file in the root directory of your project:
Tests/ export-ignore
Composer将只使用github上的标签。
Composer will only use the tags on github. Just temporary remove the tests directory when creating a tag will also do the trick.
这篇关于如何使用Composer忽略目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!