postcss / postcss-import

PostCSS plugin to inline at-import rules content
MIT License
1.38k stars 115 forks source link

URL's with a fragment or query aren't skipped and give a file not found error #537

Closed romainmenke closed 1 year ago

romainmenke commented 1 year ago
@import "foo.css#bar";
@import "foo.css?bar=baz";

These should be skipped for the same reason that url's with a protocol are skipped.


somewhat related to https://github.com/postcss/postcss-import/issues/536

romainmenke commented 1 year ago

Can be done with :

function isProcessableURL(uri) {
  if (/^(?:[a-z]+:)?\/\//i.test(uri)) {
    return false
  }

  try {
    // needs a base to parse properly
    const url = new URL(uri, "https://example.com")

    if (url.hash) {
      return false
    }

    if (url.search) {
      return false
    }
  } catch {} // Ignore

  return true
}