Remove files when downloading a dependency with composer

只愿长相守 提交于 2019-12-21 06:39:09

问题


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

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?

Ta


回答1:


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

/Tests export-ignore
READ.md export-ignore

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

  • 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.

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

Hope this helps.




回答2:


If you're on a unix-like system, you can do this in one cmd, simply cd to vendor dir and :

find . -type d -regextype posix-egrep -regex ".*\/(tests?|docs?|\.git)" -exec rm -rf {} \;

adapt the regex to your needs

find cmd: http://unixhelp.ed.ac.uk/CGI/man-cgi?find

regards



来源:https://stackoverflow.com/questions/15460429/remove-files-when-downloading-a-dependency-with-composer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!