How to use composer to install libraries for the Webform module
For anybody facing the question of what is the best-recommended method for installing/updating/managing all libraries required by the Webform module, 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.
1) Composer Merge plugin
The merging is accomplished by the aid of the Composer Merge Plugin plugin available on GitHub, so from the project directory, open a terminal and run:
composer require wikimedia/composer-merge-plugin
2) Merge the composer.libraries.json file
You have these two alternative options:
2.a) Using the file provided by the module
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.
2.b) Use drush to 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
3) Install libraries
You have these two alternative options:
3.a) 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. If you prefer just load the webform libraries, go for 3.b instead.
3.b) As local files
If you want to install all the mentioned libraries in a local directory on your webserver, typically web/libraries, then you need to run
composer update drupal/webform "drupal/webform-*" --with-dependencies
This method will ensure that composer will pull the libraries from the CDN source and store a copy in your libraries directory in your Drupal installation.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion