Recommended Method for Installing, Updating, and Managing Contributed Module Libraries Using Composer

Last updated on
26 September 2024

This page has not yet been reviewed by Extending Drupal maintainer(s) and added to the menu.

This documentation needs review. See "Help improve this page" in the sidebar.

The best-recommended method for handling libraries required by the Contrib modules is through Composer. The Contrib  modules includes a composer.libraries.json file that lists all the required libraries. To install and manage these libraries, you will merge the Contrib composer.libraries.json with your site's composer.json file.

Step-by-Step Instructions:

  1. Install Composer Merge Plugin: To merge the composer.libraries.json file into your main composer.json, install the Composer Merge Plugin. From the project directory, open a terminal and run:

    
    

    composer require wikimedia/composer-merge-plugin

  2. Modify composer.json: Edit the composer.json file of your Drupal website, and under the "extra": { section, add:

    
    

    "merge-plugin": { "include": [ "web/modules/contrib/*/composer.libraries.json" ] }

    Note: The web folder represents the directory where Drupal is installed (e.g., docroot).

    From now on, whenever the composer.json file is updated, it will also read the composer.libraries.json located at web/modules/contrib/*/ and update accordingly.

Help improve this page

Page status: Needs review

You can: