Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Adding a external JavaScript library to composer

Parent Feed: 

Some module require that you download external Javascript-libraries, and in drupal 8 that should be done in Composer. 

The module Masonry require the JavaScript library with the same name. So we need to include the package in composer.json, like:
 


"repositories":[
    {
        "type":"composer",
        "url":"https://packages.drupal.org/8"
    },
    {
        "type": "package",
        "package": {
            "name": "desandro/masonry",
            "version": "master",
            "type": "drupal-library",
            "dist": {
                "url": "https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js",
                "type": "file"
            }
        }
    },


And in the require part that is:


"require":{
    ...
    "desandro/masonry":"master",
    ...
},

And then we need to add libraries in extra part of we do not have that:


"extra":{
...
"web/libraries/{$name}":[
    "type:drupal-library"
],
...

So to install the library, you just need to run


composer require desandro/masonry

Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web