What is the difference between require and require-dev sections in composer.json?

前端 未结 6 497
北海茫月
北海茫月 2020-11-28 20:38

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

I just walk through Nettuts+ Tutorial, so I h

6条回答
  •  醉梦人生
    2020-11-28 20:43

    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

    • staging
    • production

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

    • developing
    • testing

    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

    • 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

提交回复
热议问题