The accepted answer is correct. However, I've just come across a tool for that: https://asset-packagist.org/. Instead of specifying a separate repository source for each library, specify just this one additional:
"repositories": [
{ . . . },
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
This will allow you to then require libraries as needed.
"require": {
"bower-asset/bootstrap": "^3.3",
"npm-asset/jquery": "^2.2"
}
Note: Take note of the paths above: they are not pathed by user, but by type.
For a Drupal project, you should specify the newly available installer types and that each type is to be downloaded to the Drupal libraries
directory:
"extra": {
"installer-types": [
"component",
"bower-asset",
"npm-asset"
],
"installer-paths": {
"web/libraries": [
"type:drupal-library",
"type:component",
"type:bower-asset",
"type:npm-asset"
],
}
}
Additionally, when necessary, as in the case of the colorbox
module, you can specify a per-project library path. Instead of it being downloaded as libraries/jquery-colorbox
, you can tell it to download to libraries/colorbox
as required by the Drupal module, noted in its documentation.
For Drupal 8.x : Download the Colorbox plugin and unpack in /libraries (at the root of your site). Make sure the path to the plugin file becomes: "/libraries/colorbox/jquery.colorbox-min.js".
Here's how:
Note: the custom per-project libraries path is specified before the generic asset-type libraries path--first applicable, first used.
"extra": {
...
"installer-paths": {
"web/libraries/colorbox": ["npm-asset/jquery-colorbox"],
"web/libraries": [
"type:drupal-library",
"type:component",
"type:bower-asset",
"type:npm-asset"
],
}
}
Source: Hawkeye "Derek DeRaps" Tenderwolf
https://drupal.tv/external-video/2018-07-15/how-using-drupal-project-composer-craft-your-perfect-start-state