File tree Expand file tree Collapse file tree 5 files changed +31
-1
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 5 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -2776,6 +2776,7 @@ const makeLessWorker = (
27762776 filename : string ,
27772777 dir : string ,
27782778 rootFile : string ,
2779+ mime : string | undefined ,
27792780 ) => {
27802781 const resolved = await resolvers . less (
27812782 environment ,
@@ -2784,6 +2785,12 @@ const makeLessWorker = (
27842785 )
27852786 if ( ! resolved ) return undefined
27862787
2788+ // don't rebase URLs in JavaScript plugins
2789+ if ( mime === 'application/javascript' ) {
2790+ const file = path . resolve ( resolved ) // ensure os-specific flashes
2791+ return { resolved : file }
2792+ }
2793+
27872794 const result = await rebaseUrls (
27882795 environment ,
27892796 resolved ,
@@ -2829,7 +2836,12 @@ const makeLessWorker = (
28292836 opts : any ,
28302837 env : any ,
28312838 ) : Promise < Less . FileLoadResult > {
2832- const result = await viteLessResolve ( filename , dir , this . rootFile )
2839+ const result = await viteLessResolve (
2840+ filename ,
2841+ dir ,
2842+ this . rootFile ,
2843+ opts . mime ,
2844+ )
28332845 if ( result ) {
28342846 return {
28352847 filename : path . resolve ( result . resolved ) ,
Original file line number Diff line number Diff line change @@ -108,6 +108,13 @@ test('less', async () => {
108108 await untilUpdated ( ( ) => getColor ( atImport ) , 'blue' )
109109} )
110110
111+ test ( 'less-plugin' , async ( ) => {
112+ const body = await page . $ ( 'body' )
113+ expect ( await getBg ( body ) ) . toBe (
114+ 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wIAAgEBAFPIhPsAAAAASUVORK5CYII=")' ,
115+ )
116+ } )
117+
111118test ( 'stylus' , async ( ) => {
112119 const imported = await page . $ ( '.stylus' )
113120 const additionalData = await page . $ ( '.stylus-additional-data' )
Original file line number Diff line number Diff line change 1+ @plugin " less-plugin/test.js" ;
2+
3+ body {
4+ background-image : test();
5+ }
Original file line number Diff line number Diff line change 1+ functions . add ( 'test' , function test ( ) {
2+ const transparentPng =
3+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wIAAgEBAFPIhPsAAAAASUVORK5CYII='
4+ return `url(${ transparentPng } )`
5+ } )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import './imported.css'
33import './sugarss.sss'
44import './sass.scss'
55import './less.less'
6+ import './less-plugin.less'
67import './stylus.styl'
78import './manual-chunk.css'
89
You can’t perform that action at this time.
0 commit comments