2

I have a Laravel App and I want to install require dependencies but I was wondering how does composer know whether to load dev dependencies or production dependencies?

just got confused by this concept so if somebody could clarify this concept for me than that would be of great help.

Dhaval Chheda
  • 4,637
  • 5
  • 24
  • 44
  • Possible duplicate of [What is the difference between require and require-dev sections in composer.json?](https://stackoverflow.com/questions/19117871/what-is-the-difference-between-require-and-require-dev-sections-in-composer-json) – Chin Leung Sep 25 '17 at 18:16

2 Answers2

2

When you run composer install --dev, composer installs all packages including require-dev. This is the default behaviour, exclusion of the flag would result in the same action.

When you run composer install --no-dev, composer skips the require-dev packages.

Also, composer will not install the require-dev package of a required package unless you specifically ask it to do so

Paras
  • 9,258
  • 31
  • 55
  • Was wonder about the the `require-dev` package of a `required` package. Is it documented somewhere that it wont be installed? – Raheel Hasan Nov 11 '22 at 02:29
0

The regular require dependencies are such packages that you will ALWAYS use, meaning that the framework itself (in this case Laravel), your application code and/or other 3rd party code is dependent on such packages. These dependencies are often referred as prod dependencies since you use them in production (because without them, your app wouldn't run)

The require-dev dependencies are "optional", in the sense that your core application logic would run, but you would not be able to run "development" stuff, such as Unit tests (phpunit/phpunit package) and instantiate fake data (fzaninotto/faker).

I hope this helps!

idelara
  • 1,786
  • 4
  • 24
  • 48
  • I understand the difference but how does composer know whether the environment is production or development? – Dhaval Chheda Sep 25 '17 at 18:46
  • composer install will install the composer.json dependencies , so what I don't understand is how does composer know what the current environment is ? – Dhaval Chheda Sep 25 '17 at 18:56
  • Composer always installs the `require` and `require-dev` of the "top-level" or root package by default. It won't install the `require-dev` of a `required` package unless you traverse to that install and manually `composer install` in someone else's directory. – user176717 Sep 25 '17 at 20:59