Composer 2 cheatsheet

Composer 2: Autoloading and production

7 common Composer 2 tasks.

Regenerate the autoloader

Rebuild the autoload files after adding classes or changing the autoload section.

composer dump-autoload

Optimize the autoloader

Generate a class map for faster autoloading in production.

composer dump-autoload --optimize

Install for production

Install without development packages and with an optimized autoloader.

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

Run a script

Run a script defined in the scripts section of composer.json.

composer run-script test

Allow a plugin

Composer 2.2 and later ask you to allow plugins explicitly. Allow one by name.

composer config allow-plugins.vendor/plugin true

Clear Composer's cache

Delete the packages Composer has downloaded and cached.

composer clear-cache

Install a tool globally

Install a package into your global Composer folder, for command-line tools.

composer global require laravel/installer

Was this page helpful?