How to use composer to install libraries for the Webform module

Last updated on
13 November 2026

For anybody facing the question of what is the best-recommended method for installing/updating/managing all libraries locally required by the Webform module, and avoid using CDN's, the answer is to install libraries using Composer.

The Webform module comes shipped with a "composer.libraries.json" file containing information about all up-to-date libraries required by the module itself, and so we will be using this file to install all libraries by merging the "composer.libraries.json" with the "composer.json" file of our Drupal website.

By default, the Webform module downloads libraries from external CDN's, which breaks GDPR laws, as it's not allowed to load code from external sources without user consent, see #3343915: Allow to disable (dynamic) CDN loading of libraries in general.

Composer Merge plugin

The Composer Merge Plugin merges multiple "composer.json" files at Composer runtime, to download external libraries. From the project directory, open a terminal and run this:

composer require wikimedia/composer-merge-plugin

Now, either use Composer (easiest), or the advanced Drush command to complete the process.

Composer

Using Composer is the easiest, and recommended method.

Add Webform libraries in composer.json

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

* note: the web represents the folder where drupal lives like: ex. docroot.

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

From now on, every time the "composer.json" file is updated, it will also read the content of "composer.libraries.json" file located at web/modules/contrib/webform/ and update accordingly.

Install the Webform libraries

Run this Composer command to install the Webform libraries:

composer require drupal/webform

Drush

For more control over the libraries, you can use Drush.

Append webform libraries in a custom file

Generate a custom file according to options set in webform libraries config page running:

drush webform:libraries:composer > DRUPAL_ROOT/composer.libraries.json

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

        "merge-plugin": {
            "include": [
                "composer.libraries.json"
            ]
        },

From now on, every time the "composer.json" file is updated, it will also read the content of "composer.libraries.json" file and update accordingly. 

But in this case you need to update this file after dependencies updates or config changes in your webform libraries config page by running again:

drush webform:libraries:composer > DRUPAL_ROOT/composer.libraries.json

 Install the Webform libraries

Run this Composer command to install the Webform libraries:

composer require drupal/webform

Install libraries as a CDN

In order for the "composer.json" file to install all the libraries mentioned as a CDN inside the "composer.libraries.json", from a terminal, run composer update --lock .

This method will assure that all the libraries will be served from CDN and automatically updated once the "composer.libraries.json" is updated with new versions of the Webform module.

Notice that this update ALL your dependencies, not just the webform libraries.

Help improve this page

Page status: No known problems

You can: