Laravel 没有安装 Laravel 发行包的 require-dev 包
Posted
技术标签:
【中文标题】Laravel 没有安装 Laravel 发行包的 require-dev 包【英文标题】:Laravel not installing require-dev packages of Laravel distro package 【发布时间】:2019-09-12 17:56:03 【问题描述】:我创建了一个 Laravel 发行包,其中包含我所有网站都使用的所有 Laravel 包。 我还创建了一个使用这个发行包的自定义 Laravel 网站。
不幸的是,当我在第二个作曲家文件上运行 composer install --dev 时,它不会从 laravel-distro 作曲家包中安装 require-dev 包,例如phpunit/phpunit
Laravel 发行版作曲家配置:
$ cat laravel-distro/composer.json
"name": "dennis00/laravel-distro",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require":
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"laravel/installer": "^2.0.1"
,
"require-dev":
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.5"
,
"config":
"optimize-autoloader": true,
"preferred-install": "dist",
"vendor-dir": "vendor",
"sort-packages": true
,
"extra":
"laravel":
"dont-discover": []
,
"scripts":
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
,
"autoload":
"psr-4":
"App\\": "app/"
,
"autoload-dev":
"psr-4":
"Tests\\": "tests/"
,
"minimum-stability": "dev",
"prefer-stable": true
Laravel-示例作曲家配置:
$ cat laravel-example/composer.json
"name": "dennis00/laravel-example",
"description": "Example of Laravel Distro",
"type": "project",
"license": "GPL-2.0+",
"minimum-stability": "dev",
"repositories": [
"type": "composer",
"url": "https://packages.drupal.org/8"
],
"autoload":
"classmap": [
"scripts/composer/ScriptHandler.php"
]
,
"scripts":
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
,
"require":
"dennis00/laravel-distro": "dev-master@dev",
"laravel/horizon": "^4.0@dev"
你可以看到这里缺少 require-dev 包。
root@f506ece6f4ea:/var/www/html# ls vendor
autoload.php cakephp dennis00 doctrine egulias fideloper jakub-onderka laravel monolog nette ocramius paragonie phpstan psy ramsey symfony vlucas
bin composer dnoegel dragonmantank erusev guzzlehttp jean85 league nesbot nikic opis phpoption psr ralouphie swiftmailer tijsverkoyen
root@f506ece6f4ea:/var/www/html# ls vendor_backup/
autoload.php bin dnoegel dragonmantank erusev filp hamcrest laravel mockery myclabs nikic opis phar-io phpoption phpunit psy sebastian symfony tijsverkoyen webmozart
beyondcode composer doctrine egulias fideloper fzaninotto jakub-onderka league monolog nesbot nunomaduro paragonie phpdocumentor phpspec psr ramsey swiftmailer theseer vlucas
root@f506ece6f4ea:/var/www/html#
【问题讨论】:
【参考方案1】:不会的,这是故意的。
由于包位于第一个基本 package.json 文件的 require-dev
部分,因此只有在该包上运行 composer install
时才会安装。
当您将该包拉入另一个项目时,composer 只会从包中安装那些不在require-dev
中的依赖项。
这是因为require-dev
仅用于该软件包的开发,不应要求在其他用途中使用该软件包。如果您在使用基础包时需要安装这些包,则必须将它们放在require
而不是require-dev
。
【讨论】:
以上是关于Laravel 没有安装 Laravel 发行包的 require-dev 包的主要内容,如果未能解决你的问题,请参考以下文章