v1/web/modules/contrib/blazy/docs/COMPOSER.md

2.9 KiB


INSTALLING THIRD-PARTY LIBRARIES VIA COMPOSER

Until Drupal has an official core management of the 3rd-party front-end libraries, there are various ways to install third party bower (deprecated)/ npm asset libraries.

Check out any below suitable to your workflow:

It is up to you to decide which works best. Composer is not designed to manage JS, CSS or HTML framework assets. It is for PHP. Then come Composer plugins, and other workarounds to make Composer workflow easier. As many alternatives, it is not covered here. Please find more info on the above-mentioned issues.

VIA ASSET-PACKAGIST.ORG

If using asset-packagist.org, regardless cons, be sure to set up your composer.json correctly, some distros use it, see Slick project for the supporting distros to copy/ paste from their composer.json files. Be warned! Invalid json may break. Normally unwanted trailing commas.

  1. Add/ merge these lines, add commas as required:
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
  1. Add/ merge these lines, add commas as required:
    "extra": {
        "installer-types": [
            "bower-asset",
            "npm-asset"
        ],
        "installer-paths": {
            "web/libraries/{$name}": [
                "type:drupal-library",
                "type:bower-asset",
                "type:npm-asset"
            ],
            // ....
        }
    }
  1. Require composer-installers-extender:
    composer require oomphinc/composer-installers-extender

  2. Then require any libraries as usual only prefixed with npm-asset, or bower-asset (deprecated). The versions must be re-checked, just samples:

    • Install Blazy: composer require npm-asset/blazy:^1.8.2 <= not required at Blazy 2.6.
    • If using Slick, the namespace is slick-carousel, not slick. The supported versions are 1.6.0 - 1.8.0, not 1.8.1 up, use exact numbers: composer require npm-asset/slick-carousel:1.8.0
    • If using Splide: composer require npm-asset/splidejs--splide:^3
    • If using Colorbox, verify the latest supported version: composer require npm-asset/jquery-colorbox:^1.6.4
    • etc.
  3. To update:
    composer update --with-dependencies