File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1
1
import fs from 'node:fs'
2
+ import path from 'node:path'
2
3
import { describe , expect , test } from 'vitest'
3
4
import {
4
5
asyncFlatten ,
@@ -9,6 +10,7 @@ import {
9
10
isFileReadable ,
10
11
isWindows ,
11
12
posToNumber ,
13
+ processSrcSetSync ,
12
14
resolveHostname ,
13
15
shouldServe
14
16
} from '../utils'
@@ -270,3 +272,15 @@ describe('isFileReadable', () => {
270
272
} )
271
273
}
272
274
} )
275
+
276
+ describe ( 'processSrcSetSync' , ( ) => {
277
+ test ( 'prepend base URL to srcset' , async ( ) => {
278
+ const devBase = '/base/'
279
+ expect (
280
+ processSrcSetSync (
281
+ './nested/asset.png 1x, ./nested/asset.png 2x' ,
282
+ ( { url } ) => path . posix . join ( devBase , url )
283
+ )
284
+ ) . toBe ( '/base/nested/asset.png 1x, /base/nested/asset.png 2x' )
285
+ } )
286
+ } )
Original file line number Diff line number Diff line change @@ -94,20 +94,16 @@ const processNodeUrl = (
94
94
const devBase = config . base
95
95
if ( startsWithSingleSlashRE . test ( url ) ) {
96
96
// prefix with base (dev only, base is never relative)
97
- const fullUrl = joinUrlSegments ( devBase , url )
97
+ const fullUrl = path . posix . join ( devBase , url )
98
98
overwriteAttrValue ( s , sourceCodeLocation , fullUrl )
99
99
} else if (
100
100
url . startsWith ( '.' ) &&
101
101
originalUrl &&
102
102
originalUrl !== '/' &&
103
103
htmlPath === '/index.html'
104
104
) {
105
- const replacer = ( url : string ) =>
106
- path . posix . join (
107
- devBase ,
108
- path . posix . relative ( originalUrl , devBase ) ,
109
- url . slice ( 1 )
110
- )
105
+ // prefix with base (dev only, base is never relative)
106
+ const replacer = ( url : string ) => path . posix . join ( devBase , url )
111
107
112
108
// #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets
113
109
// path will add `/a/` prefix, it will caused 404.
You can’t perform that action at this time.
0 commit comments