如何从供应商目录生成 laravel composer.json?

How to generate laravel composer.json from a vendor directory?

在我的 Laravel 项目中,composer.jsoncomposer.lock 文件被删除,我不知道如何从现有的 [=15] 重建 composer.json 文件=]目录.

备注

使用此方法的缺点是主 composer.json 文件将包含现有或子包或多个包所需的一些包。但不用担心它只会安装一次。但是版本可能有问题。

建议

我建议你使用一些像git这样的版本控制来克服未来的这种情况。

can't guarantee about the following method i am going to present as its not a usual case. but might work.

在项目根目录中像这样创建一个新的 composer.json 文件。如果你愿意,你可以使用 composer init 命令。

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "5.6",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "Blog\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}
  • 转到 vendor 文件夹中的每个包文件夹并找到 包的 composer.json 文件。从该文件中找到该 composer.json 文件中该包的 "name"
  • 将包的名称添加到 main composer.json 文件的 "require" 部分。如果您想将该包添加到开发中,请将其添加到 "require-dev" 部分。

  • composer installcomposer update

  • composer dump-autoload