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 = (
2776
2776
filename : string ,
2777
2777
dir : string ,
2778
2778
rootFile : string ,
2779
+ mime : string | undefined ,
2779
2780
) => {
2780
2781
const resolved = await resolvers . less (
2781
2782
environment ,
@@ -2784,6 +2785,12 @@ const makeLessWorker = (
2784
2785
)
2785
2786
if ( ! resolved ) return undefined
2786
2787
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
+
2787
2794
const result = await rebaseUrls (
2788
2795
environment ,
2789
2796
resolved ,
@@ -2829,7 +2836,12 @@ const makeLessWorker = (
2829
2836
opts : any ,
2830
2837
env : any ,
2831
2838
) : 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
+ )
2833
2845
if ( result ) {
2834
2846
return {
2835
2847
filename : path . resolve ( result . resolved ) ,
Original file line number Diff line number Diff line change @@ -108,6 +108,13 @@ test('less', async () => {
108
108
await untilUpdated ( ( ) => getColor ( atImport ) , 'blue' )
109
109
} )
110
110
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
+
111
118
test ( 'stylus' , async ( ) => {
112
119
const imported = await page . $ ( '.stylus' )
113
120
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'
3
3
import './sugarss.sss'
4
4
import './sass.scss'
5
5
import './less.less'
6
+ import './less-plugin.less'
6
7
import './stylus.styl'
7
8
import './manual-chunk.css'
8
9
You can’t perform that action at this time.
0 commit comments