Load asset libraries when a theme is activated

Created on 6 April 2024, 10 months ago
Updated 15 April 2024, 10 months ago

Problem/Motivation

Some design systems expect specific CSS & JS to be loaded with a theme/mode.

For example, Europa Component Library expects:

We heard some UI Skins users are using https://www.drupal.org/project/configurable_theme_libraries to achieve that, but it is confusing to have 2 different mechanisms for a single theme.

Proposed resolution

Add those properties to theme definition:

  • libraries with a list of dependencies. Works like in info.yml file. Libraries are not fully declared here. They need to be declared elsewhere. For example in {extension}.libraries.yml
  • libraries-override: which works like in info.yml https://www.drupal.org/node/2497313

Example:

light:
  label: "Light"
  key: data-mode
  target: body
  libraries:
    - foo/bar
    - vendor/baz
    libraries-override:
      - my_theme/global-styling: false

When the theme is activated, the library is loaded. When the theme is disabled, the library is unloaded.

Before starting

When the theme is disabled, the library is unloaded? Are we sure about that? What if the library was already loaded by anotehr trigger and it still expected?

Let's copy the same behaviour as https://www.drupal.org/project/configurable_theme_libraries

API changes

No breaking changes

Feature request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

Production build 0.71.5 2024