5

While I'm familiar with the basics of composer.json and specifying dependencies under the require key I haven't quite understood the purpose of require-dev — Composer's documentation states:

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.

In the abstract it makes sense, but I'm having a hard to imagining the situations when I'd need this functionality.

  1. What are the practical use cases of require-dev in a workflow?
  2. Is there an exemplar package (or packages) which should reside in require-dev but not in require?
Mark Fox
  • 8,694
  • 9
  • 53
  • 75

1 Answers1

11

One common example is phpunit, which you need in development to run your test suite, but generally won't need in production. It could also be build tools or such things. There is no huge harm in putting everything into require though, it just means you have more code installed on your prod machines, and might slow down your builds a bit depending on how you do them.

Seldaek
  • 40,986
  • 9
  • 97
  • 77
  • Gotchya, so it has nothing to do with dependencies under development? – Mark Fox Aug 30 '13 at 00:18
  • 1
    Nope it really means dependencies needed to develop your package, it does not relate to the stability of the dependencies themselves. – Seldaek Aug 30 '13 at 10:03
  • How do you set-up your production machine to allow composer to recognize that it is on a production machine when you run 'composer install' ? – JoeTidee Jan 28 '15 at 13:59
  • 1
    You don't really set up the machine, you set up your deploy script so that it runs `composer install --no-dev` – Seldaek Jan 28 '15 at 19:14
  • So the only benefit is that your `vendor` folder is smaller on your production machine? Because if I use for example PHPUnit then the files in the venoder/PHPUnit would only be included when I call the class, right? And this does never happen on production machine. – Adam Jun 01 '17 at 10:51
  • @Adam yeah that's about right. Also in case you have tooling that requires special extensions to be installed in development for example (say xdebug or the ast extension), if you put them in require you would need to install xdebug in prod environments to be able to run composer installs there which is generally a bad idea. – Seldaek Jun 01 '17 at 14:43