Skip to content

Instantly share code, notes, and snippets.

@robdecker
Created December 8, 2019 04:49
Show Gist options
  • Save robdecker/1e44e411910af46756d2297593fd6cd0 to your computer and use it in GitHub Desktop.
Save robdecker/1e44e411910af46756d2297593fd6cd0 to your computer and use it in GitHub Desktop.
[Force <link> instead of <style> @import url() for stylesheets] #d8 #css
/**
* Implements hook_css_alter().
*/
function THEME_css_alter(&$css) {
// Use <link> as opposed to <style> @import during development if
// css preprocessing is turned off. This will allow tools like
// BrowserSync and LiveReload to work properly.
$preprocess_css = \Drupal::config('system.performance')->get('css.preprocess');
if (isset($preprocess_css) && $preprocess_css === FALSE) {
foreach ($css as $key => $value) {
$css[$key]['preprocess'] = FALSE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment