How to get node's view mode in hook_page_attachments?
To attach a library only when a node in a certain view mode is displayed you can use hook_entity_view/hook_ENTITY_TYPE_view like following.

/**
 * Implements hook_ENTITY_TYPE_view().
 */
function MYMODULE_node_view(array &amp;$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  $node = $entity;
  if ($node-&gt;bundle() === 'page') {
    if ($view_mode === 'full') {
      $build['#attached']['library'][] = 'MYMODULE/foo';
    }
    elseif ($view_mode === 'default') {
      $build['#attached']['library'][] = 'MYMODULE/bar';
    }
  }
}