Theme CSS libraries always loaded after module libraries 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 &lt;style&gt; 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 &lt;style&gt; 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 &lt;style&gt; 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;
The proper way to modify the loading order is weight property as described here.  The lower the weight the further up your library should go.

Try something like the following in your trent/trent.libraries.yml

bootstrap:
  css:
    base:
      libraries/bootstrap/bootstrap.min.css: {weight: -50}


You might have to adjust the number to get it to desired position.

NOTE: weight is in the process of being replaced by dependencies. Work done can be seen in this issue and when ready this sort of problem will be easier to tackle.