我创建了一个Laravel发行版包,其中包含我所有网站使用的所有Laravel软件包。我还创建了一个使用此发行版包的自定义 Laravel 网站。
不幸的是,当我在第二个作曲家文件上运行作曲家安装 --dev 时,它不会从 laravel-distro 作曲家包中安装 require-dev 包,例如 phpunit/phpunit
Laravel-distro composer configuration:
$ 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
}
拉拉维尔示例作曲家配置:
$ 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#
不会,这是故意的。
由于包位于第一个 base package.json 文件的require-dev
部分中,因此仅当您在该包上运行composer install
时,才会安装该文件。
当您将该包拉入另一个项目时,composer 将仅从包中安装不在 require-dev
中的依赖项。
这是因为require-dev
仅用于开发该包,不应要求在其他内容中使用该包。如果您在使用基本软件包时需要安装这些软件包,则必须将它们放在 require
而不是 require-dev
.