Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install third party libraries in Drupal 8 with Composer that are not on packagist?

What is the best way to install a third party library in Drupal 8 that is not on packagist?

For example I have the Color Field module, which can use the jQuery Simple Color Picker library to provide a better user experience.

The most obvious solution is to just add the library manually, but that's not really maintainable.

My second idea was to add the git repository to my composer.json, as shown below, but it doesn't work because the target repository doesn't have a composer.json file.

"repositories": [
    {
        "name": "jquery-simple-color",
        "type": "git",
        "url": "https://github.com/recurser/jquery-simple-color.git"
    }
],
"require": {
    "jquery-simple-color/": "1.2.1"
}

Should I just fork the git repository and add a composer.json file there?

like image 432
Chris Avatar asked Mar 30 '17 14:03

Chris


People also ask

Do I need Composer for Drupal?

As previously mentioned, Composer is a recommended way to install Drupal. However, if, for some reason, you do not want or cannot use Composer, there are other solutions. For example, you can use Drush and install Drupal from the command line.


1 Answers

You was on the right track, in your composer.json you can make your own "packages" for example:

"repositories": [
  {
    "type": "package",
    "package": {
      "name": "jquery/simplecolor",
      "version": "1.2.1",
      "dist": {
        "url": "https://github.com/recurser/jquery-simple-color/archive/v1.2.1.zip",
        "type": "zip"
      },
      "type": "drupal-library"
    }
  }
]

And then include it trough

  "jquery/simplecolor": "1.2.1,
like image 51
melvin Avatar answered Nov 04 '22 12:11

melvin