Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 496 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to install third party libraries in Drupal 8 with Composer that are not on packagist?

#1
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][1], which can use the [jQuery Simple Color Picker library][2] 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?

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#2
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,
Reply

#3
The accepted answer is correct. However, I've just come across a tool for that:

[To see links please register here]

. 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
>
>

[To see links please register here]

Reply

#4
Last tip : using 'simplecolor' in 'repositories' leads to the creation of a folder named libraries/simplecolor, that is not what Drupal is waiting for.
As the folder needs to be libraries/jquery-simple-color, it's simpler to add :

"repositories": [ {
"type": "package",
"package": {
"name": "jquery/jquery-simple-color",
"version": "1.2.1",


and use :
composer require jquery/jquery-simple-color
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through