How to set/get base_path in D8?
You're looking for $base_url global:

global $base_url;


If you want to have this in a preprocess function, you'd have to call it within that function; for example:

function YOUR_THEME_preprocess_whatever(&amp;$variables) {
  global $base_url;
  // Now you can use it.
  $variables['base_url'] = $base_url;
}