It is not recommended to installing JavaScript libraries using composer.json
, but it is possible.
Note: This repository type has a few limitations and should be avoided whenever possible:
Composer will not update the package unless you change the versionfield.Composer will not update the commit references, so if you use master as reference you will have to delete the package to force an update, and will have to deal with an unstable lock file.
(Composer docs)
If your package is available for download at an external source, e.g. as an archive, you could add it as custom package with type drupal-library
to the repositories
section of your Drupal project's composer.json
, and then require this package accordingly:
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"mypackage": {
"type": "package",
"package": {
"name": "myvendor/mypackage",
"version": "1.0.0",
"type": "drupal-library",
"dist": {
"url": "https://example.com/mypackage.zip",
"type": "zip"
}
}
}
},
"require": {
...
"composer/installers": "^1.2",
"myvendor/mypackage": "1.0.0"
},
"extra": {
"installer-paths": {
"public/core": ["type:drupal-core"],
"public/libraries/{$name}": ["type:drupal-library"],
"public/modules/contrib/{$name}": ["type:drupal-module"],
"public/profiles/contrib/{$name}": ["type:drupal-profile"],
"public/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/contrib/{$name}": ["type:drupal-drush"]
},
...
}
Check the Repositories documentation for Composer for more details or other source types.
composer require some/library
to manually add the library yourself.composer.json
, as they'd require either a wrapper package which almost never is the case, or a custom repository definition, which won't be picked up by the parent project's Composer installation.