如何使用 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
中时,我都希望复制所有内容,除了很麻烦的 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).
是否可以从库的 composer.json
中排除该目录?
Is it possible to exclude this directory from the library's composer.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屋!