Merge plugins with Composer

By Trystan Leach

A closeup of the inside of a computer, with a focus on the circuit board, in blue light.

When modules have library dependencies (like the dropzone js module), the default behavior of composer is to put the dependency in the vendor folder instead of web/libraries. But most of the time, that's not what we really want composer to do. Rather we would like the dependency (dropzone.js in this case) to go under the /libraries folder in the web directory. That's because the module has a composer.libraries.json file that defines enyo/dropzone dependency with type drupal-library and the correct paths to install.

In order to do that, we need few steps. First of all we need to install the merge plugin:

composer require wikimedia/composer-merge-plugin

and in your root composer.json file, you need to add this bit:

"extra": {
 "merge-plugin": {
   "include": [
     "web/modules/contrib/dropzonejs/composer.libraries.json"
   ]
 },
 "installer-paths": {
   "web/core": ["type:drupal-core"],
   "web/libraries/{$name}": ["type:drupal-library"],
   "web/modules/contrib/{$name}": ["type:drupal-module"],
   ...
 }
}

THEN you can add the dropzone js module and the dependency:

composer require drupal/dropzonejs enyo/dropzone

The merged composer.libraries.json defines enyo/dropzone as a drupal-library and sets the path, so Composer will install it to web/libraries/dropzone automatically.

Get ready to transform your operations

Sign up for a free trial and discover a world of possibilities to elevate your outreach and engagement strategies