Laravel - Difference b/w require and require-dev sections in composer.json - Important Interview Question

Laravel - Difference b/w require and require-dev sections in composer.json - Important Interview Question

Normally, Application runs 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 or packages which are required for running an application in

  • Staging
  • Production

environments, whereas the dependencies or packages 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.

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

        

Thanks!

Waleed Mubarik

Sr. Software Engineer | PHP | Laravel | MySQL | Docker | AWS

2 年

Thanks for sharing.

要查看或添加评论,请登录

Shahzad Ahmed的更多文章

社区洞察

其他会员也浏览了