composer.json 中的 require 和 require-dev 部分有什么区别? [英] What is the difference between require and require-dev sections in composer.json?

查看:24
本文介绍了composer.json 中的 require 和 require-dev 部分有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用composer,我对它知之甚少,对Web应用程序开发有一点经验.

I'm beginning using composer, I know so little about it and have a little experience with web application development.

我只是通过 Nettuts+ 教程,所以我有一个关于作曲家的基本问题.

I just walk through Nettuts+ Tutorial, so I have basic question about composer.

{
  "require": {
    "laravel/framework": "4.0.*",
    "way/generators": "dev-master",
    "twitter/bootstrap": "dev-master",
    "conarwelsh/mustache-l4": "dev-master"
  },
  "require-dev": {
    "phpunit/phpunit": "3.7.*",
    "mockery/mockery": "0.7.*"
  },
  "autoload": {
    "classmap": [
      "app/commands",
      "app/controllers",
      "app/models",
      "app/database/migrations",
      "app/database/seeds",
      "app/tests/TestCase.php"
    ]
  },
  "scripts": {
    "post-update-cmd": "php artisan optimize"
  },
  "minimum-stability": "dev"
}

  1. "require-dev" 部分中出现的任何内容,都只能通过composer install --dev 下载和安装?
  2. 我阅读了一些 composer 的文档,但仍然不明白我们有 "require-dev" 部分的原因是什么?是不是因为我们想要获取软件包的特定版本,而不是始终获取最新的稳定版本?
  1. Whatever appears in "require-dev" part, will only be downloaded and installed with composer install --dev?
  2. I read some of composer's documentation but still don't understand what is the reason we have "require-dev" part? Is it because of we want to get specific version of the package rather always getting the latest stable version?

推荐答案

不同环境

通常,软件会在不同的环境中运行:

Different Environments

Typically, software will run in different environments:

  • 开发
  • 测试
  • 暂存
  • 生产

composer.jsonrequire 部分中声明的依赖项通常是在

The dependencies which are declared in the require section of composer.json are typically dependencies which are required for running an application or a package in

  • 暂存
  • 生产

环境,而在 require-dev 部分中声明的依赖项通常是在

environments, whereas the dependencies declared in the require-dev section are typically dependencies which are required in

  • 开发中
  • 测试

环境.

例如,除了用于实际运行应用程序的包之外,可能还需要用于开发软件的包,例如:

For example, in addition to the packages used for actually running an application, packages might be needed for developing the software, such as:

  • friendsofphp/php-cs-fixer(检测和修复编码风格问题)
  • squizlabs/php_codesniffer(检测和修复编码风格问题)
  • phpunit/phpunit(使用测试驱动开发)
  • 等等
  • friendsofphp/php-cs-fixer (to detect and fix coding style issues)
  • squizlabs/php_codesniffer (to detect and fix coding style issues)
  • phpunit/phpunit (to drive the development using tests)
  • etc.

现在,在 developmenttesting 环境中,您通常会运行

Now, in development and testing environments, you would typically run

$ composer install

安装 productiondevelopment 依赖项.

to install both production and development dependencies.

但是,在 stagingproduction 环境中,您只想安装运行应用程序所需的依赖项,并且作为部署过程的一部分,您通常会运行

However, in staging and production environments, you only want to install dependencies which are required for running the application, and as part of the deployment process, you would typically run

$ composer install --no-dev

仅安装 production 依赖项.

换句话说,部分

  • 要求
  • 需要开发

composer指示在运行时应该安装哪些包

indicate to composer which packages should be installed when you run

$ composer install

$ composer install --no-dev

就是这样.

注意永远不会安装您的应用程序或包所依赖的包的开发依赖项

Note Development dependencies of packages your application or package depend on will never be installed

参考见:

这篇关于composer.json 中的 require 和 require-dev 部分有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆