How do you disable the CSS from a core module in Drupal 8 using libraries-override? I'm trying to disable the CSS styles from the layout discovery module in my theme.info.yml file. I've tried several options, but I can't seem to get it to work. This is what I have now.

libraries-override:
  core/layout_discovery:
    css:
      theme:
        core/modules/layout_discovery/layouts/twocol/twocol.css: false


The CSS styles can be removed using stylesheets-remove at the moment, but that property has been deprecated. It does seem work at the moment, though.

I would like to find the proper way to remove the CSS stules using libraries-override, if I can.

stylesheets-remove:
  - core/modules/layout_discovery/layouts/onecol/onecol.css
Seems you are missing a starting / on the full path. And the name of the overriding library looks wrong as well. There's no library core/layout_discovery. It must be layout_discovery/twocol instead.

libraries-override:
  layout_discovery/twocol:
    css:
      theme:
        /core/modules/layout_discovery/layouts/twocol/twocol.css: false


Source: Overriding and extending libraries



Alternatively, unsetting libraries via hook_page_attachments_alter() does the trick as well. Here comes a working code snippet to be placed in your theme's *.theme file. Replacy MYTHEME with the machine name of your theme.

/**
 * Implements hook_page_attachments_alter().
 */
function MYTHEME_page_attachments_alter(array &amp;$attachments) {

  foreach ($attachments['#attached']['library'] as $key =&gt; $library) {

    // Install the Devel submodule Kint for debugging.
    // Check all libs:
    // ksm($attachments['#attached']['library']);

    // Here I disable the core base library.
    // Looks pretty ugly afterwards.
    if ($library == 'system/base') {
      unset($attachments['#attached']['library'][$key]);
    }

    // So for you it must be like following.
    // Simply try to find the right name via ksm($library);
    // or the other ksm() command from above.
    if ($library == 'layout_discovery/twocol') {
      unset($attachments['#attached']['library'][$key]);
    }
  }
}