From 4825712cbaae42ef61f4f5136fa83c5ce77beb38 Mon Sep 17 00:00:00 2001 From: YourAdHere <63565008+YourAdIsHere@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:49:48 -0700 Subject: [PATCH] Add support for css @import rules --- src/bundle/rewriters/css.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bundle/rewriters/css.ts b/src/bundle/rewriters/css.ts index aac2036..84b3839 100644 --- a/src/bundle/rewriters/css.ts +++ b/src/bundle/rewriters/css.ts @@ -1,7 +1,11 @@ -import { encodeUrl } from "./url" +import { encodeUrl } from "./url"; export function rewriteCss(css: string, origin?: URL) { css = css.replace(/(?<=url\("?'?)[^"'][\S]*[^"'](?="?'?\);?)/g, (match) => encodeUrl(match, origin)); - + //painful regex simulator + css = css.replace(/@import\s+(['"])?([^'"\);]+)\1?\s*(?:;|$)/g, (match, quote, url) => { + return `@import ${quote || ""}${encodeUrl(url.trim(), origin)}${quote || ""};`; + }); return css; -} \ No newline at end of file + +}