How to change default Composer installation folder?

Asked

Viewed 317 times

4

Is there any way to change where Composer installs the dependencies?

Composer always installs in the folder vendor, but would have to change to another folder?

1 answer

4


Within the composer.json of the project adjust the config -> vendor-dir, example:

"config": {
    "vendor-dir": "system/vendor"
},

In my case I used system/vendor

PS: I believe that for the global packages you can set the environment variable COMPOSER_VENDOR_DIR:

Note that it is possible to change the vendor via line command using:

COMPOSER_VENDOR_DIR=outro_diretorio
composer require pacote

In Windows:

set COMPOSER_VENDOR_DIR=outro_diretorio
composer require pacote

Remembering that this only changes at runtime and if you have other packages they will be installed again in the new directory, so I do not see many advantages in using the variable COMPOSER_VENDOR_DIR would be more interesting if the vendor is controlled by another environment or program to generate the name or location as some rule is required to describe this.

A hypothetical example would be if you created a project generator (in CLI perhaps) based on a "template" project on your machine, then the installed packages should always go to that template and your "CLI" would always copy from the template when sending to production, but for development all projects would use the template as a basis, it would be one of the many likely ideas that this could be useful, where another program/environment would control Composer with COMPOSER_VENDOR_DIR.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.