composer.json에서 require와 require-dev 섹션의 차이점은 무엇입니까?
저는 composer를 사용하기 시작했고 그것에 대해 거의 알지 못하며 웹 애플리케이션 개발에 대한 경험이 거의 없습니다.
Nettuts + Tutorial 을 살펴 보았 기 때문에 작곡가에 대한 기본적인 질문이 있습니다.
{
"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"
}
- "require-dev"부분에 표시되는 내용은 composer install --dev 로만 다운로드 및 설치됩니다 .
- 작곡가의 문서 일부를 읽었지만 여전히 "require-dev"부분이있는 이유가 무엇인지 이해하지 못합니다. 항상 최신 안정 버전을 얻기보다는 특정 버전 의 패키지 를 얻고 싶기 때문 입니까?
다른 환경
일반적으로 소프트웨어는 다른 환경에서 실행됩니다.
development
testing
staging
production
서로 다른 환경에서 서로 다른 종속성
의 require
섹션 에서 선언 된 composer.json
종속성은 일반적으로 응용 프로그램 또는 패키지를 실행하는 데 필요한 종속성입니다.
staging
production
require-dev
섹션 에서 선언 된 종속성은 일반적으로
developing
testing
환경.
예를 들어, 실제로 응용 프로그램을 실행하는 데 사용되는 패키지 외에도 다음과 같은 소프트웨어 개발을 위해 패키지가 필요할 수 있습니다.
friendsofphp/php-cs-fixer
(코딩 스타일 문제 감지 및 수정)squizlabs/php_codesniffer
(코딩 스타일 문제 감지 및 수정)phpunit/phpunit
(테스트를 사용하여 개발 추진)- 기타
전개
이제 development
및 testing
환경에서 일반적으로
$ composer install
production
및 development
종속성을 모두 설치합니다 .
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
to install only production
dependencies.
Semantics
In other words, the sections
require
require-dev
indicate to composer
which packages should be installed when you run
$ composer install
or
$ composer install --no-dev
That is all.
Note Development dependencies of packages your application or package depend on will never be installed
For reference, see:
- https://getcomposer.org/doc/04-schema.md#require
- https://getcomposer.org/doc/04-schema.md#require-dev
According to composer's manual:
require-dev (root-only)
Lists packages required for developing this package, or running tests, etc. The dev requirements of the root package are installed by default. Both
install
orupdate
support the--no-dev
option that prevents dev dependencies from being installed.So running
composer install
will also download the development dependencies.The reason is actually quite simple. When contributing to a specific library you may want to run test suites or other develop tools (e.g. symfony). But if you install this library to a project, those development dependencies may not be required: not every project requires a test runner.
From the composer site (it's clear enough)
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, or running tests, etc. The dev requirements of the root package are installed by default. Both install or update support the --no-dev option that prevents dev dependencies from being installed.
Using require-dev in Composer you can declare the dependencies you need for development/testing the project but don't need in production. When you upload the project to your production server (using git) require-dev
part would be ignored.
Also check this answer posted by the author and this post as well.
require section This section contains the packages/dependencies which are better candidates to be installed/required in the production environment.
require-dev section: This section contains the packages/dependencies which can be used by the developer to test her code (or for the experiment purpose on her local machine and she wants these packages should not be installed on the production environment.)
General rule is that you want packages from require-dev section only in development (dev) environments, for example local environment.
Packages in require-dev section are packages which help you debug app, run tests etc.
At staging and production environment you probably want only packages from require section.
But anyway you can run composer install --no-dev and composer update --no-dev on any environment, command will install only packages from required section not from require-dev, but probably you want to run this only at staging and production environments not on local.
Theoretically you can put all packages in require section and nothing will happened, but you don't want developing packages at production environment because of the following reasons :
- speed
- potential of expose some debuging info
- etc
Some good candidates for require-dev are :
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
you can see what above packages are doing and you will see why you don't need them on production.
See more here : https://getcomposer.org/doc/04-schema.md
'programing' 카테고리의 다른 글
Twitter 부트 스트랩이로드되었는지 확인하는 방법은 무엇입니까? (0) | 2020.10.14 |
---|---|
MySQL에서 공백이있는 열 이름을 선택하는 방법 (0) | 2020.10.14 |
Git 기능 브랜치를 삭제할 적절한시기는 언제입니까? (0) | 2020.10.14 |
emacs가 터미널 모드인지 어떻게 감지합니까? (0) | 2020.10.14 |
특정 지역의 고객에게 서비스를 제공하는 데 가장 적합한 AWS 위치를 어떻게 결정할 수 있습니까? (0) | 2020.10.14 |