php require 和 require-dev 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16679589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between require and require-dev?
提问by slier
I'm new to the composer
and I would like to know the difference between require
and require-dev
.
The composer website doesn't offer a good explanation the difference between these two.
我是新来的composer
,我想知道的区别require
和require-dev
。作曲家网站没有很好地解释这两者之间的区别。
The part that I don't get is Lists packages required for developing this package, or running tests, etc.
from Composer Official Docs.
我没有得到的部分Lists packages required for developing this package, or running tests, etc.
来自Composer 官方文档。
采纳答案by Scott Tesler
The require-dev
packages are packages that aren't necessaryfor your project to work and shouldn'tbe included in the productionversion of your project.
这些require-dev
包是项目运行所不需要的包,不应包含在项目的生产版本中。
Typically, these are packages such as phpunit/phpunit
that you would only use during development.
通常,这些是phpunit/phpunit
您只会在开发过程中使用的包。
回答by Scott Tesler
seems clear to me:
对我来说似乎很清楚:
require
Lists packages required by this package. The package will not be installed unless those requirements can be met.
require-dev (root-only)
Lists packages required for developing this package(1), or running tests, etc. The dev requirements of the root package only will be installed if install is run with
--dev
or if update is run without--no-dev
.
要求
列出此包所需的包。除非满足这些要求,否则不会安装该软件包。
需要开发(仅限 root)
列出开发此包(1)或运行测试等所需的包。只有在使用 install 运行 install
--dev
或不使用 update运行时,才会安装根包的 dev 要求--no-dev
。
http://getcomposer.org/doc/04-schema.md
http://getcomposer.org/doc/04-schema.md
1. the packages used to develop a package
1.用于开发包的包
回答by Nathan Craike
The key distinction is that Composer will only install require-dev
dependencies for the "root package" – the directory where you run composer install
. The documentationdescribes this as:
关键区别在于 Composer 只会require-dev
为“根包”安装依赖项——您运行composer install
. 文档将其描述为:
The root package is the package defined by the
composer.json
at the root of your project. It is the maincomposer.json
that defines your project requirements.
根包是由
composer.json
项目根目录下的定义的包。它是composer.json
定义您的项目要求的主要内容。
…and the require-dev
documentationspecifies that it is "root-only".
......并且require-dev
文档指定它是“仅root”。
In practice, this means that a package's require-dev
dependencies aren't used if the package is being installed as a dependency for something else (ie it's installed to another project's vendor
folder).
在实践中,这意味着require-dev
如果包作为其他东西的依赖项安装(即它安装到另一个项目的vendor
文件夹),则不会使用包的依赖项。
So if you have phpunit
in the require-dev
list for YourProject, and I clone down YourProjectand run composer install
in the yourproject/
directory, Composer will install phpunit
to yourproject/vendor/
, because it's likely I'm doing some developmenton YourProject. As part of doing development I'll probably want to run YourProject's test suite, and to do that I'll need phpunit
.
因此,如果您phpunit
在YourProjectrequire-dev
列表中,并且我克隆了YourProject并在该目录中运行,Composer 将安装到,因为我可能正在对YourProject进行一些开发。作为开发的一部分,我可能想要运行YourProject的测试套件,为此我需要.composer install
yourproject/
phpunit
yourproject/vendor/
phpunit
But, if I add YourProjectas a dependency of MyProject, installing the myproject
package will install the yourproject
package as well, but it will not install phpunit
.
但是,如果我将YourProject添加为MyProject的依赖项,则安装myproject
包也会安装yourproject
包,但不会安装phpunit
.
You canoverride this behaviour with the --dev
and --no-dev
options, but the default behaviour is based on whether the package concerned is the root package.
您可以使用--dev
和--no-dev
选项覆盖此行为,但默认行为取决于相关包是否为根包。