Can you override a library per environment? In my libraries.yml file, I have something like this, being used to define "foo-bar" as a library that can be pulled in from various parts of the site:

foo-bar:
  version: 0.0.x
  js:
    js/foo-dev.js: {}


This works well on my local environment, but on our production and QA environments, I would like for it to look more like this:

foo-bar:
  version: 0.0.x
  js:
    js/foo-prod.js: {}


(The prod version will include optimizations that normally don't appear with minification alone).

Currently, we are using the sites/&lt;site>/settings.*.php files and the config-split module to have different configurations based on the environment, but is there a way to have the foo-bar library reference the dev-friendly version on one environment, and the production version on all others?
Look at hook_page_attachments. In the sample snippet provided behind that link there is a simple if-request which attaches a certain library only when a certain condition is met. Do the same.

MYTHEME/MYMODULE.libraries.yml

foo-bar-dev:
  version: 0.0.x
  js:
    js/foo-dev.js: {}
foo-bar-prod:
  version: 0.0.x
  js:
    js/foo-prod.js: {}


MYTHEME.theme/MYMODULE.module

function MYTHEME/MYMODULE_page_attachments(array &amp;$attachments) {

  // Conditionally attach an asset to the page.
  if (\Drupal::request()-&gt;getHost() == 'example.com') {
    $attachments['#attached']['library'][] = 'MYTHEME/MYMODULE/foo-bar-prod';
  }
  else {
    $attachments['#attached']['library'][] = 'MYTHEME/MYMODULE/foo-bar-dev';
  }
}




More info on base URL: how to get base url of a site?.