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 + +}