I read that if you use install / update / require with the --prefer-source flag (or write it in the config section in the config - preferred-install section), then the composer pulls all the project files, including documentation, tests, examples, etc. Therefore on production it is better to use --prefer-dist (for example, https://phptoday.ru/post/5-sovetov-dlya-raboty-s-composer write about it here)

But wherever I put this flag, with any command or in the config file - the whole package is always downloaded. For example, I tried chillerlan / php-database . Total:

enter image description here

With other libraries the same. Am I doing something wrong? Or did I understand everything wrong? Or maybe some libraries are downloaded absolutely always in one piece?

What should I do to download / or install files without unnecessary garbage?

    1 answer 1

    When using the --prefer-dist parameter (the default option for stable versions), Composer installs a package from the repository of ready-made distributions of packages. This mode is recommended for a production environment in which no editing is done in packages and the speed of their installation is important.

    When using the --prefer-source parameter, Composer clones the source (if any) of the package from the VCS repository. This is the mode for active development when the package is scheduled to be modified.


    In short, when using the --prefer-dist option, you:

    • save disk space, because The package does not contain a version index (.git folder) VCS. And also CAN (but not necessarily, because it depends on the package build) there are no folders / files that do not affect the correct operation of the package (docks, tests, examples, ...)
    • installation is faster, especially when the package contains a large number of dependencies

    Example

    composer.json

     { "require": { "yiisoft/yii2-composer": "*" } } 

    Run composer install for it with different flags --prefer-dist and --prefer-source . After that, check the contents of the vendor/yiisoft/yii2-composer folders - they will be very different.

    For this particular package, the difference in the contents of the folder with its installation is significant, and for the other - the only difference is the absence of the folder with the VCS index.

    • Thanks for copying information from the manual, but the question was not about that. It is just about why, despite the fact that the --prefer-dist flag is on, all the folders are still being pulled up, incl. with tests and examples. Those. in the end, there is no - the installation does not go faster and there is no I do not save disk space - Sergey Mishin
    • @ Sergey Mishin I added my answer. See an example in it - Jigius