#! code: Drupal 9: Deleting And Ignoring Drupal Composer Directories From Git

Drupal CMS

Composer is an excellent way of managing dependencies but in order to use it properly it does require a build and deployment process.

The two ways of deploying a site built with composer is to either generate an artefact with the composer dependencies installed, or to install composer as part of the deployment process. Both of these approaches require not committing the vendor directory and other third party libraries (like Drupal core for example) to the git repository.

Many developers tend to go for the approach of committing the composer dependencies to the repository in order to simplify their workflow. This approach, while simple, does have its problems. I have talked about the problems of committing the composer vendor directory in detail in a previous article.

If you need to swap from a vendor in git approach to a deployed application approach then there are some thing you’ll need to do in order to remove those directories from your codebase.

The best way to remove the vendor directories from your codebase is to automate it. This means that if you ever want to test your deployment process then you can run a single command to remove all of the non-custom files. This is also a useful way of triggering a full re-install of the project.

Create a file called nuke.sh and add it somewhere in your project (preferably outside of your webroot). This file contains a number of deletion (i.e. rm) commands that go through your codebase and removes any vendor, Drupal core or contributed code. I normally create this file in “scripts/nuke.sh”.

Read more.