How to load an asset from a parent theme after an asset from your child theme

Or, more generally, how to load a library in Drupal, or an element of a library, after another given library or component in a library.

It’s easy to load a library before your library— just make it a dependency of your library:

This will cause it to be loaded first.

But what if you want it to be loaded afterwards?

This is what we wanted to do with a subtheme of Bulma.

Overriding and extending libraries documents how this works.

Unfortunately, there are bugs prevening it from working easily, or well.

The approach Octavia takes is this:

/**
 * Implements hook_library_info_alter().
 */
function octavia_library_info_alter(&$libraries, $extension) {
  if ($extension === 'bulma' && isset($libraries['global'])) {
    // Since the replaced library files are no longer located in a directory
    // relative to the original extension, specify an absolute path (relative
    // to DRUPAL_ROOT / base_path()) to the new location.
    $css_file = '/' . drupal_get_path('theme', 'octavia') . '/dist/css/bulma.css';
    $libraries['global']['css']['base'] = [
      $css_file => [],
    ];    
  }
}