How to preload a css/js library programmatically after module installation? is there api for changing *.library.yml file?
Drupal allows modules to add dynamic library definitions by implementing hook_library_info_build(). Drupal core doesn't implement this hook, except in a test module.

function common_test_library_info_build() {
  $libraries = [];
  if (\Drupal::state()-&gt;get('common_test.library_info_build_test')) {
    $libraries['dynamic_library'] = [
      'version' =&gt; '1.0',
      'css' =&gt; [
        'base' =&gt; [
          'common_test.css' =&gt; [],
        ],
      ],
    ];
  }
  return $libraries;
}


If you instead need to alter the library definitions given from another module, hook_library_info_alter() is the correct hook to use.

function locale_library_info_alter(array &amp;$libraries, $module) {
  if ($module === 'core' &amp;&amp; isset($libraries['jquery.ui.datepicker'])) {
    $libraries['jquery.ui.datepicker']['dependencies'][] = 'locale/drupal.locale.datepicker';
    $libraries['jquery.ui.datepicker']['drupalSettings']['jquery']['ui']['datepicker'] = [
      'isRTL' =&gt; NULL,
      'firstDay' =&gt; NULL,
    ];
  }

  // When the locale module is enabled, we update the core/drupal library to
  // have a dependency on the locale/translations library, which provides
  // window.drupalTranslations, containing the translations for all strings in
  // JavaScript assets in the current language.
  // @see locale_js_alter()
  if ($module === 'core' &amp;&amp; isset($libraries['drupal'])) {
    $libraries['drupal']['dependencies'][] = 'locale/translations';
  }
}