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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:32:25  来源:igfitidea点击:

What's the difference between require and require-dev?

phpinstallationcomposer-php

提问by slier

I'm new to the composerand I would like to know the difference between requireand require-dev. The composer website doesn't offer a good explanation the difference between these two.

我是新来的composer,我想知道的区别requirerequire-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-devpackages 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/phpunitthat 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 --devor 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-devdependencies 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.jsonat the root of your project. It is the main composer.jsonthat defines your project requirements.

根包是由composer.json项目根目录下的定义的包。它是composer.json定义您的项目要求的主要内容。

…and the require-devdocumentationspecifies that it is "root-only".

......并且require-dev文档指定它是“仅root”。

In practice, this means that a package's require-devdependencies aren't used if the package is being installed as a dependency for something else (ie it's installed to another project's vendorfolder).

在实践中,这意味着require-dev如果包作为其他东西的依赖项安装(即它安装到另一个项目的vendor文件夹),则不会使用包的依赖项。

So if you have phpunitin the require-devlist for YourProject, and I clone down YourProjectand run composer installin the yourproject/directory, Composer will install phpunitto 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.

因此,如果您phpunitYourProjectrequire-dev列表中,并且我克隆了YourProject并在该目录中运行,Composer 将安装到,因为我可能正在对YourProject进行一些开发。作为开发的一部分,我可能想要运行YourProject的测试套件,为此我需要.composer installyourproject/phpunityourproject/vendor/phpunit

But, if I add YourProjectas a dependency of MyProject, installing the myprojectpackage will install the yourprojectpackage as well, but it will not install phpunit.

但是,如果我将YourProject添加为MyProject的依赖项,则安装myproject包也会安装yourproject包,但不会安装phpunit.

You canoverride this behaviour with the --devand --no-devoptions, but the default behaviour is based on whether the package concerned is the root package.

可以使用--dev--no-dev选项覆盖此行为,但默认行为取决于相关包是否为根包