如何在Symfony中检查未使用的库?

3

我在 package.json 中列出了很多库,但我知道其中大多数没有使用。我该如何知道我使用哪些库以及未使用的库是哪些?

我正在使用 Symfony 3.4 和 Yarn 作为依赖管理器。

谢谢!


据我所知,您实际的依赖项应该在项目根目录下的composer.json的“require”部分中。 - john Smith
检查我的库是否被使用的方法是相同的吗?实际上这就是我想要检查的,是否使用了像bootstrap.css之类的库。 - Val
1
你得到的评论和答案比较零散的原因是Symfony使用composer来管理它的依赖,而你代码中的javascript部分使用yarn。人们试图回答你的标题而不是问题的主体。最好编辑并删除Symfony部分,看看yarn的专家能否提供帮助。但我认为这真的取决于你的应用程序最终需要什么,所以很难说。 - Cerad
是的,我不确定该如何称呼这个... 不幸的是,我需要知道如何删除那些未使用的人 :/ - Val
另一种方法是从完全没有依赖开始,然后逐个添加。但我怀疑你会为了很少的收益而做很多工作。 - Cerad
显示剩余4条评论
2个回答

3
如果你想知道一个软件包为什么被安装,可以运行命令why。例如,查看以下列表:
>composer show
doctrine/instantiator             1.0.5   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
phpdocumentor/reflection-common   1.0.1   Common reflection classes used by 
.....
input/output with nice error messages.

请查看实例化程序包。
>composer why doctrine/instantiator
phpspec/prophecy              1.8.0  requires  doctrine/instantiator (^1.0.2)
phpunit/phpunit-mock-objects  2.3.8  requires  doctrine/instantiator (^1.0.2)

你也可以尝试使用树状结构版本:

>composer why -t doctrine/instantiator
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
├──phpspec/prophecy 1.8.0 (requires doctrine/instantiator ^1.0.2)
│  └──phpunit/phpunit 4.8.36 (requires phpspec/prophecy ^1.3.1)
│     └──XXXXXXXX dev-master (requires (for development) phpunit/phpunit ~4.6)
└──phpunit/phpunit-mock-objects 2.3.8 (requires doctrine/instantiator ^1.0.2)
   └──phpunit/phpunit 4.8.36 (requires phpunit/phpunit-mock-objects ~2.3)
      └──XXXXXXXX dev-master (requires (for development) phpunit/phpunit ~4.6)

谢谢您的回答,我需要使用库来完成这个任务,有什么方法吗?这些库在我的package.json中列出。 - Val
有趣...试着移除一个,看看代码是否会出错。 - Matteo
1
那就是我正在做的事情,但不幸的是我有超过200个库和大量的代码页面。我需要一个月来清理这些 :'D - Val

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接