@@ -104,6 +104,7 @@ const commonjsProxyRE = /\?commonjs-proxy/
104
104
const inlineRE = / ( \? | & ) i n l i n e \b /
105
105
const inlineCSSRE = / ( \? | & ) i n l i n e - c s s \b /
106
106
const usedRE = / ( \? | & ) u s e d \b /
107
+ const varRE = / ^ v a r \( / i
107
108
108
109
const enum PreprocessLang {
109
110
less = 'less' ,
@@ -980,7 +981,7 @@ export const cssUrlRE =
980
981
export const cssDataUriRE =
981
982
/ (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " | [ ^ ' " ) ] + ) \s * \) /
982
983
export const importCssRE = / @ i m p o r t ( ' [ ^ ' ] + \. c s s ' | " [ ^ " ] + \. c s s " | [ ^ ' " ) ] + \. c s s ) /
983
- const cssImageSetRE = / i m a g e - s e t \( ( [ ^ ) ] + ) \ )/
984
+ const cssImageSetRE = / (?< = i m a g e - s e t \( ) ( (?: [ \w \- ] + \( [ ^ \) ] * \) | [ ^ ) ] ) * ) (? = \) ) /
984
985
985
986
const UrlRewritePostcssPlugin : PostCSS . PluginCreator < {
986
987
replacer : CssUrlReplacer
@@ -1001,7 +1002,9 @@ const UrlRewritePostcssPlugin: PostCSS.PluginCreator<{
1001
1002
const importer = declaration . source ?. input . file
1002
1003
return opts . replacer ( rawUrl , importer )
1003
1004
}
1004
- const rewriterToUse = isCssUrl ? rewriteCssUrls : rewriteCssImageSet
1005
+ const rewriterToUse = isCssImageSet
1006
+ ? rewriteCssImageSet
1007
+ : rewriteCssUrls
1005
1008
promises . push (
1006
1009
rewriterToUse ( declaration . value , replacerForDeclaration ) . then (
1007
1010
( url ) => {
@@ -1054,11 +1057,15 @@ function rewriteCssImageSet(
1054
1057
replacer : CssUrlReplacer
1055
1058
) : Promise < string > {
1056
1059
return asyncReplace ( css , cssImageSetRE , async ( match ) => {
1057
- const [ matched , rawUrl ] = match
1058
- const url = await processSrcSet ( rawUrl , ( { url } ) =>
1059
- doUrlReplace ( url , matched , replacer )
1060
- )
1061
- return `image-set(${ url } )`
1060
+ const [ , rawUrl ] = match
1061
+ const url = await processSrcSet ( rawUrl , async ( { url } ) => {
1062
+ // the url maybe url(...)
1063
+ if ( cssUrlRE . test ( url ) ) {
1064
+ return await rewriteCssUrls ( url , replacer )
1065
+ }
1066
+ return await doUrlReplace ( url , url , replacer )
1067
+ } )
1068
+ return url
1062
1069
} )
1063
1070
}
1064
1071
async function doUrlReplace (
@@ -1073,7 +1080,13 @@ async function doUrlReplace(
1073
1080
wrap = first
1074
1081
rawUrl = rawUrl . slice ( 1 , - 1 )
1075
1082
}
1076
- if ( isExternalUrl ( rawUrl ) || isDataUrl ( rawUrl ) || rawUrl . startsWith ( '#' ) ) {
1083
+
1084
+ if (
1085
+ isExternalUrl ( rawUrl ) ||
1086
+ isDataUrl ( rawUrl ) ||
1087
+ rawUrl . startsWith ( '#' ) ||
1088
+ varRE . test ( rawUrl )
1089
+ ) {
1077
1090
return matched
1078
1091
}
1079
1092
0 commit comments