简体   繁体   English

如何通过Composer从供应商/软件包中仅安装一个目录? 还是在安装后删除目录?

[英]How can I install only one directory by Composer from the vendor/package? Or delete directories after installation?

Sorry my english isn't too good. 对不起,我的英语不太好。 So I have a problem with the composer. 所以我对作曲家有疑问。 It is that I can select which directory I would like to install from a package, or after installation delete them. 我可以从软件包中选择要安装的目录,也可以在安装后删除它们。 For example: "yiisoft/yii" this is the vendor/package. 例如:“ yiisoft / yii”这是供应商/软件包。 But I would like to install only the "yiisoft/yii/framework" directory. 但是我只想安装“ yiisoft / yii / framework”目录。 I don't like to keep the other directories. 我不喜欢保留其他目录。 I still find what will be the best solution for my problem. 我仍然找到解决我的问题的最佳解决方案。

You shouldn't mess with the vendor directory. 您不应该混淆供应商目录。 There are good reason to keep it all together in vendors . 有充分的理由将所有这些东西放在vendors If you really need to have certain files available from another path, use symlinks. 如果确实需要从其他路径获得某些文件,请使用符号链接。

For more information about this topic read this authoritative blog post about the Composer Vendor Directory by Igor Wiedler. 有关此主题的更多信息,请阅读Igor Wiedler撰写的有关Composer供应商目录的权威博客文章。

Alternatively you could copy the content somewhere else (and/or delete) with phing. 或者,您可以通过phing将内容复制到其他位置(和/或删除)。

When you install a software with composer, you install all the repository. 使用composer安装软件时,将安装所有存储库。 If you want to delete unused folder, you can use a particular feature of composer. 如果要删除未使用的文件夹,则可以使用composer的特定功能。 You can catch some events like post-install-cmd or post-update-cmd in this way: 您可以通过以下方式捕获一些事件,例如post-install-cmd或post-update-cmd:

{
    "scripts": {
        "post-install-cmd": "Sensorario\\Communityii\\ComposerCommands::postInstall",
        "post-update-cmd": "Sensorario\\Communityii\\ComposerCommands::postUpdate"
    }
}

In the root folder of your project you have composer.json, you will also need to add a file in PSR-0 standard: - composer.json - src/Sensorario/Communityii/ComposerCommands.php 在项目的根文件夹中,您有composer.json,还需要添加PSR-0标准的文件:-composer.json-src / Sensorario / Communityii / ComposerCommands.php

And this file can be like this: 这个文件可以像这样:

namespace Sensorario\\Communityii; 命名空间Sensorario \\ Communityii;

class ComposerCommands
{
    public static function postUpdate()
    {
        // remove unused folders
        shell_exec('rm vendor/yiisoft/yii/demos/ ... ');
    }
}

This code will run after 此代码将在之后运行

$ composer update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装作曲家后我没有供应商文件夹? - I have not got vendor folder after installation of composer? 将更改从供应商目录推送到作曲家程序包的最快方法 - The fastest way to push changes from vendor directory to composer package 如何从laravel软件包安装供应商软件包 - how to install vendor package from laravel package 如果我在多个目录中有多个composer.json,如何使用composer安装依赖项? - How can I install dependencies with composer if I have multiple composer.json in multiple directories? 在供应商目录中运行composer包的测试 - Running tests of a composer package in vendor directory 如何使用composer获取多个供应商目录? - How to get multiple vendor directories with composer? 我如何在没有依赖的情况下在composer中安装软件包 - how can I install package in composer without dependency 如何在/ src目录中安装composer包? - How can I install a composer package into the /src dir? 安装目录“/usr/local/bin”不可写 - 如何解决这个问题? 我正在尝试全局安装作曲家 - The installation directory "/usr/local/bin" is not writable - How to fix this? I am trying to install the composer globally 运行“Composer Install”后丢失“vendor”文件夹 - “vendor” folder missing after running “Composer Install”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM