question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with <style> @import url("..."); </style>

See original GitHub issue

This is a great tool. However, it would be even better if it supported @import’s of stylesheets.

I realize that including stylesheets this way is not optimal, but it does get around IE’s limitation of 31 stylesheets, and is useful when in development - particularly with CMS’s that include a lot of stylesheets.

When I downloaded this tool to try it out I was working on a Drupal project, which happens to do this until you turn on CSS aggregation. But at that point it also changes the name of the CSS files and caches them.

I took a look at modifying browser-sync-client.js but it seems like it’s really only setup for altering <link> elements and ran short on time.

Thanks!

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
skh-commented, Oct 5, 2015

I have been using a similar one as mentioned by @gijsroge. Only difference is disabling @import based on the CSS aggregation setting (rather than the environment variable which isn’t part of core).

/**
 * Implements hook_css_alter().
 *
 * Disables @import CSS tags for compatibility with BrowserSync.
 */
function HOOK_css_alter(&$css) {

  // Aggregation must be disabled.
  if (!variable_get('preprocess_css')) {

    // Disable @import on each css file.
    foreach ($css as &$item) {

      // Compatibility with disabling stylesheets in theme.info (263967).
      if (file_exists($item['data'])) {
        $item['preprocess'] = FALSE;
      }
    }
  }
}
3reactions
taivucommented, Apr 13, 2017

similar to @skh-'s temp fix , but for Drupal 8:

/**
 * Implements hook_css_alter().
 *
 * Disables @import CSS tags for compatibility with BrowserSync CSS injection while developing.
 */
function YOURTHEMENAME_css_alter(&$css) {

  // get value from settings/local.settings
  $is_css_preprocess = \Drupal::config('system.performance')->get('css')['preprocess'];

  // Aggregation must be disabled.
  if (!$is_css_preprocess) {

    // Disable @import on each css file.
    foreach ($css as &$item) {

      // Compatibility with disabling stylesheets in theme.info (263967).
      if (file_exists($item['data'])) {
        $item['preprocess'] = FALSE;
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

overriding css styles with @import not working - Stack Overflow
Declaring style-override.css after style.css inside head will solve the problem, but I want to use @import inside a css file. Adding !important ...
Read more >
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >
@import path is not working (Example) | Treehouse Community
First I have issue with directory linking on the href to the css file. but I solved the linking issue. The code below...
Read more >
@import css not working | OutSystems
@import css not working · Open theme editor and click "Reset Theme Editor" · Create another theme (based on OutSystems UI) to do...
Read more >
import url from 'style.css?url' does not work #3833 - vitejs/vite
Describe the bug Attempting to import a stylesheet as a url fails. This is useful for injecting a stylesheet into shadow-dom via a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found