Howard
Howard

Reputation: 19805

How to stop PHP Composer autoload require-dev library?

I use PHPUnit for testing and development only, I don't want my app to autoload them in production server, is it possible?

"require-dev": {
    "phpunit/phpunit": "4.2.*",
..

I see the file "autoload_classmap.php" contains lines such as..

return array(
    'File_Iterator' => $vendorDir . '/phpunit/php-file-iterator/File/Iterator.php',
    'File_Iterator_Facade' => $vendorDir . '/phpunit/php-file-iterator/File/Iterator/Facade.php',

Updated:

I want a clean production env and don't want to autoload phpunit, I only need phpunit during development. So, can composer generate two autoload.php so I can include them depending on my current env?

Upvotes: 3

Views: 1248

Answers (1)

Alister Bulman
Alister Bulman

Reputation: 35149

--no-dev : Skip installing packages listed in require-dev

composer install --no-dev --optimize-autoloader

You will probably also want to do: --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.

Upvotes: 6

Related Questions