File tree Expand file tree Collapse file tree 3 files changed +37
-10
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 3 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -1748,16 +1748,26 @@ const UrlRewritePostcssPlugin: PostCSS.PluginCreator<{
17481748 const replacerForDeclaration = ( rawUrl : string ) => {
17491749 return opts . replacer ( rawUrl , importer )
17501750 }
1751- const rewriterToUse = isCssImageSet
1752- ? rewriteCssImageSet
1753- : rewriteCssUrls
1754- promises . push (
1755- rewriterToUse ( declaration . value , replacerForDeclaration ) . then (
1756- ( url ) => {
1757- declaration . value = url
1758- } ,
1759- ) ,
1760- )
1751+ if ( isCssUrl && isCssImageSet ) {
1752+ promises . push (
1753+ rewriteCssUrls ( declaration . value , replacerForDeclaration )
1754+ . then ( ( url ) => rewriteCssImageSet ( url , replacerForDeclaration ) )
1755+ . then ( ( url ) => {
1756+ declaration . value = url
1757+ } ) ,
1758+ )
1759+ } else {
1760+ const rewriterToUse = isCssImageSet
1761+ ? rewriteCssImageSet
1762+ : rewriteCssUrls
1763+ promises . push (
1764+ rewriterToUse ( declaration . value , replacerForDeclaration ) . then (
1765+ ( url ) => {
1766+ declaration . value = url
1767+ } ,
1768+ ) ,
1769+ )
1770+ }
17611771 }
17621772 } )
17631773 if ( promises . length ) {
Original file line number Diff line number Diff line change @@ -228,6 +228,11 @@ describe('css url() references', () => {
228228 } )
229229 } )
230230
231+ test ( 'image-set and url exist at the same time.' , async ( ) => {
232+ const imageSet = await getBg ( '.image-set-and-url-exsiting-at-same-time' )
233+ expect ( imageSet ) . toMatch ( assetMatch )
234+ } )
235+
231236 test ( 'relative in @import' , async ( ) => {
232237 expect ( await getBg ( '.css-url-relative-at-imported' ) ) . toMatch ( assetMatch )
233238 } )
Original file line number Diff line number Diff line change @@ -102,6 +102,18 @@ <h2>CSS url references</h2>
102102 CSS background image-set() inline style (with multiple descriptor)
103103 </ span >
104104</ div >
105+ < div
106+ class ="image-set-and-url-exsiting-at-same-time "
107+ style ="
108+ background-image: image-set(url('./nested/asset.png')),
109+ url('./nested/asset.png');
110+ background-size: 10px 10px;
111+ "
112+ >
113+ < span style ="background: #fff "
114+ > CSS background image-set() and url existing at the same time</ span
115+ >
116+ </ div >
105117< div class ="css-url-relative-at-imported ">
106118 < span style ="background: #fff "
107119 > CSS background (relative from @imported file in different dir)</ span
You can’t perform that action at this time.
0 commit comments