This is https://www.droptica.com/blog/10-tricks-work-efficiently-composer-drupa… a great article about how to speed things up with composer, reduce Composer’s hunger for memory with Drupal Optimizations, control the available memory limit and discover the outdated command and the --dry-run option.
Some other useful composer tips:
--dev and --no-dev
composer require drupal/project-name --dev
This will install the module - project as a dev package - module. Usually we want this while we are developing a new project locally. After that when we go live we can do this:
composer install --no-dev
by doing this we make sure that no dev modules are installed in our production server.
Here is an example of my local composer.json file with all the --dev packages - projects installed
"require-dev": {
"consolidation/robo": "^3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"drupal/coder": "^8.3",
"drupal/devel": "^4.1",
"drupal/stage_file_proxy": "^2.0",
"drupal/twig_vardumper": "^3.0",
"kint-php/kint": "^4.1"
}
}
As you can see I am using devel, coder, stage_file_proxy etc for the local development process. I installed stage_file_proxy like this
composer require --dev drupal/stage_file_proxy
Of course you can add multiple modules like this:
composer require drupal/stage_file_proxy drupal/devel --dev
--no-update
Let's say you want to install a new module for testing but you want to avoid any updates that composer will try to run along with any
composer require drupal/project
When this command is launched, in addition to installing the added package, other dependencies will also be automatically updated, which may result in an "unwanted" update of the kernel and other modules and libraries.
We can avoid this by adding --no-update with our composer require command:
composer require drupal/project --no-update
Combined with the above --dev feature we add multiple modules like this
composer require drupal/stage_file_proxy drupal/devel --dev --no-update