feat: Resolve relative URLs in property values by alex-ketch · Pull Request #18 · unlight/postcss-import-url

Hi @unlight, and thanks for this plugin!

I encountered a need for converting relative paths referenced in remote files to be absolute, as otherwise it the relative files would fail to resolve, and cause build issues down the pipeline.
Let me know if this PR is something you'd want to accept or not.
But for our use case, resolving assets paths to be absolute allows for chaining with other plugins to either download the assets or inline them as base64.

I've added tests which should illustrate the resolution better, but here's the idea:

/* myFile.css */
@import url("https://example.com/styles.css");
/* https://example.com/styles.css */
@font-family {
  src: url("./relative/path/font.woff");
}

Output

/* myFile-compiled.css */
@font-family {
-  src: url("./relative/path/font.woff");
+  src: url("https://example.com/relative/path/font.woff");
}

One question though, I didn't put this functionality behind an option flag as I didn't think keeping asset paths relative would be a desirable very often, but I can see how that might be misconception on my part, or even a breaking change for some setups.
I'd appreciate your guidance on how, and if, you'd like this to work.

Thanks again 👋