My custom theme uses Bootstrap, which I'd obviously like to load before any module CSS libraries, but Drupal ignores any kind of ordering for themes, and Bootstrap CSS styles appear as @import
in a <style>
tag that always comes last, even if it's set to base. Modules however, respect SMAACS groupings and will move CSS @imports into different style tags.
How can I get the theme CSS files to load before module CSS files? Why is bootstrap ALWAYS at the bottom?
I've cleared the cache, disabled devel, tried aggregation on and off. Nothing makes a difference.
This is the code I am using.
/themes/custom/trent/trent.info.yml
core: 8.x
type: theme
name: "Trent"
description: "Test theme"
package: "Trent"
libraries:
- trent/bootstrap
/themes/custom/trent/trent.libraries.yml
bootstrap:
css:
base:
libraries/bootstrap/bootstrap.min.css: {}
/modules/custom/trent_news/trent_news.info.yml
name: Trent News
type: module
description: Displays news
core: 8.x
package: Trent
libraries:
- trent_news/trent-news
/modules/custom/trent_news/trent_news.libraries.yml
trent-news:
version: 1.x
css:
theme:
css/trent_news.css: {}
css/print.css: {}
I want bootstrap to move up higher but Drupal isn't respecting any setting; it just keeps it in that last <style>
tag no matter what. However, it does respect SMAACS ordering within that style tag, oddly enough. As I mentioned, I can change the module ordering (e.g. theme -> component) and the CSS imports will move into different <style>
tags accordingly.
UPDATE:
core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php:165
overrides and ignores any SMACCS setting (or group setting in *.libraries.yml) for theme CSS. It actually doesn't appear possible to move the import higher up before any module includes:
$options['group'] = $extension_type == 'theme' ? CSS_AGGREGATE_THEME : CSS_AGGREGATE_DEFAULT;