php 如何从作曲家中删除未使用的依赖项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26930816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:06:29  来源:igfitidea点击:

How to remove unused dependencies from composer?

phpcomposer-php

提问by Lorenz Meyer

I installed a package with composer, and it installed many other packages as dependencies.

我用 composer 安装了一个包,它安装了许多其他包作为依赖项。

Now I uninstalled the main package with composer remove packageauthor/packagename, but all the old dependencies were not removed. I expected composer to clean up and only keep packages that are required according to composer.jsonand their dependencies.

现在我用 卸载了主包composer remove packageauthor/packagename,但没有删除所有旧的依赖项。我希望作曲家清理并仅保留根据composer.json及其依赖项所需的包。

How can I force composer to clean up and remove all unused packages ?

如何强制 composer 清理并删除所有未使用的包?

回答by Denis Pshenov

The right way to do this is:

正确的做法是:

composer remove jenssegers/mongodb --update-with-dependencies

I must admit the flag here is not quite obvious as to what it will do.

我必须承认这里的标志对于它将做什么不是很明显。

Update

更新

composer remove jenssegers/mongodb

As of v1.0.0-beta2--update-with-dependenciesis the default and is no longer required.

v1.0.0-beta2 开始--update-with-dependencies是默认值,不再需要。

回答by Lorenz Meyer

In fact, it is very easy.

事实上,这很容易。

composer update

will do all this for you, but it will also update the other packages.

将为您完成所有这些,但它也会更新其他软件包。

To remove a package without updating the others, specifiy that package in the command, for instance:

要删除一个包而不更新其他包,请在命令中指定该包,例如:

composer update monolog/monolog

will remove the monolog/monologpackage.

将删除monolog/monolog包。

Nevertheless, there may remain some empty folders or files that cannot be removed automatically, and that have to be removed manually.

尽管如此,仍可能存在一些无法自动删除的空文件夹或文件,必须手动删除。

回答by Max Wen

following commands will do the same perfectly

以下命令将完美地做同样的事情

rm -rf vendor

composer install 

回答by Valentas

Just run composer install- it will make your vendordirectory reflect dependencies in composer.lockfile.

只需运行composer install- 它将使您的vendor目录反映composer.lock文件中的依赖项。

In other words - it will delete any vendor which is missing in composer.lock.

换句话说 - 它会删除任何在composer.lock.

Please update the composer itself before running this.

请在运行之前更新作曲家本身。