Optionally include libraries via composer

Created on 25 June 2020, over 4 years ago
Updated 3 April 2023, over 1 year ago

I couldn't find any documentation or issues explaining how to include the required JS libraries in your local site, so they don't load over a CDN, which we cannot use for our sites. I came up with the option(s) below. Hopefully this will help someone else and maybe the module will consider one of these options moving forward.

Asset Packagist is a convenient way to require bower and npm packages via composer. When used with oomphinc/composer-installers-extender you can specify where the packages are installed, allowing you to place the required JS library packages into the Drupal libraries folder.

Unfortunately, when included this way, the folder structure of the libraries differs from what is defined in the module's fullcalendar_view.libraries.yml file. The attached patch changes these references to the paths expected when including the npm packages via Asset Packagist.

Besides applying the patch do the following to get this setup in your project:

Add the following to your project composer.json in the "repositories" section.

        "assets": {
            "type": "composer",
            "url": "https://asset-packagist.org"
        },

Make sure you have required the oomphinc/composer-installers-extender package.

Add the following to your project composer.json in the "extra" section.

        "installer-types": [
            "bower-asset",
            "npm-asset"
        ],
        "installer-paths": {
            "docroot/libraries/{$name}": [
                "type:bower-asset",
                "type:npm-asset"
            ]
        }

Lastly, require all the packages which the most recent version of the Drupal fullcalendar_view module depends upon, locked to the version defined in fullcalendar_view.libraries.yml.

        "npm-asset/fullcalendar": "4.4.2",
        "npm-asset/fullcalendar--core": "4.4.2",
        "npm-asset/fullcalendar--daygrid": "4.4.2",
        "npm-asset/fullcalendar--interaction": "4.4.2",
        "npm-asset/fullcalendar--list": "4.4.2",
        "npm-asset/fullcalendar--moment": "4.4.2",
        "npm-asset/fullcalendar--rrule": "4.4.2",
        "npm-asset/fullcalendar--timegrid": "4.4.2",
        "npm-asset/jsframe.js": "1.5.16",
        "npm-asset/moment": "2.26.0",
        "npm-asset/rrule": "2.6.4",

Another option would be to do what Webform did β†’ by including a custom composer.libraries.json with custom repository definitions that you can then include in your composer.json with the composer merge-plugin. This might be a better option for the community because the required JS library version constraints could be managed and maintained by the fullcalendar_view module maintainers as the module is updated.

πŸ“Œ Task
Status

Closed: outdated

Version

5.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States timwood Rockville, Maryland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024