File tree Expand file tree Collapse file tree
packages/vite/src/node/plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -463,13 +463,15 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
463463 }
464464 }
465465 }
466- // <tag style="... url(...) ..."></tag>
466+ // <tag style="... url(...) or image-set(...) ..."></tag>
467467 // extract inline styles as virtual css and add class attribute to tag for selecting
468468 const inlineStyle = node . attrs . find (
469469 ( prop ) =>
470470 prop . prefix === undefined &&
471471 prop . name === 'style' &&
472- prop . value . includes ( 'url(' ) , // only url(...) in css need to emit file
472+ // only url(...) or image-set(...) in css need to emit file
473+ ( prop . value . includes ( 'url(' ) ||
474+ prop . value . includes ( 'image-set(' ) ) ,
473475 )
474476 if ( inlineStyle ) {
475477 inlineModuleIndex ++
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ describe('css url() references', () => {
148148 expect ( imageSet ) . toContain ( 'image-set(url("data:image/png;base64,' )
149149 } )
150150
151- test ( 'image-set with multiple descriptor ' , async ( ) => {
151+ test ( 'image-set with gradient ' , async ( ) => {
152152 const imageSet = await getBg ( '.css-image-set-gradient' )
153153 expect ( imageSet ) . toContain ( 'image-set(url("data:image/png;base64,' )
154154 } )
@@ -160,6 +160,15 @@ describe('css url() references', () => {
160160 } )
161161 } )
162162
163+ test ( 'image-set with multiple descriptor as inline style' , async ( ) => {
164+ const imageSet = await getBg (
165+ '.css-image-set-multiple-descriptor-inline-style' ,
166+ )
167+ imageSet . split ( ', ' ) . forEach ( ( s ) => {
168+ expect ( s ) . toMatch ( assetMatch )
169+ } )
170+ } )
171+
163172 test ( 'relative in @import' , async ( ) => {
164173 expect ( await getBg ( '.css-url-relative-at-imported' ) ) . toMatch ( assetMatch )
165174 } )
Original file line number Diff line number Diff line change @@ -71,8 +71,8 @@ <h2>CSS url references</h2>
7171 CSS background image-set() (with multiple descriptor)
7272 </ span >
7373</ div >
74- <!-- image-set in style tags is not supported in Vite yet -->
75- <!-- <div
74+ < div
75+ class =" css-image-set-multiple-descriptor-inline-style "
7676 style ="
7777 background-image: -webkit-image-set(
7878 './nested/asset.png' type('image/png') 1x,
@@ -82,9 +82,9 @@ <h2>CSS url references</h2>
8282 "
8383>
8484 < span style ="background: #fff ">
85- CSS background image-set() (with multiple descriptor)
85+ CSS background image-set() inline style (with multiple descriptor)
8686 </ span >
87- </div> -->
87+ </ div >
8888< div class ="css-url-relative-at-imported ">
8989 < span style ="background: #fff "
9090 > CSS background (relative from @imported file in different dir)</ span
You can’t perform that action at this time.
0 commit comments