How to remove unused dependencies from composer?
Removing unused Dependencies from Composer is very easy. Following are the two approaches:
1. Using Composer Remove:This is the simplest command to remove unused Dependencies from Composer.
composer remove dependency_name
Firstly decide which dependency you want to remove from the composer. Here we will be removing stripe/stripe-php dependency as shown below in the composer and the stripe folder is also present in the directory.
Now just go to the directory in which your composer.json file is there and then type the below command:
composer remove stripe/stripe-php
Output: This command removed the stripe/stripe-php dependency from the composer as shown below:
Thus, the composer remove is a very easy command and will remove the unused dependencies from the composer.
2. Using Composer Update:It’s another way of removing unused Dependencies from Composer.
The above command will update the complete directory and will add all the dependencies and folders shown below:
Now just open the composer.json file and delete the dependency which you want to remove.
Now just delete the phpunit/phpunit:4.6.1 dependency and the updated composer.json is shown below:
Now we just need to run the composer update command once more and it will remove all the phpunit dependencies which we don’t want as shown below:
“composer update” will do the task, but it will also update the other packages.
Now if you just want to remove a specific package without updating others then just specify that package name.
composer update packageauthor/package_name
It will remove the “package_name” package.