Different Environments
Typically, software will run in different environments:
development
testing
staging
production
Different Dependencies in Different Environments
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
environments, whereas the dependencies declared in the require-dev
section are typically dependencies which are required in
environments.
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
(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.
Deployment
Now, in development
and testing
environments, you would typically run
$ composer install
to install both production
and development
dependencies.
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
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:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…