Skip to content

Commit 04c717f

Browse files
committed
chore: skip data uri by load fallback plugin for native data uri handling
1 parent 5adb440 commit 04c717f

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed
+20-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import fsp from 'node:fs/promises'
2+
import type { RolldownPlugin } from 'rolldown'
23
import { cleanUrl } from '../../shared/utils'
3-
import type { Plugin } from '../plugin'
44

55
/**
66
* A plugin to provide build load fallback for arbitrary request with queries.
77
*/
8-
export function buildLoadFallbackPlugin(): Plugin {
8+
export function buildLoadFallbackPlugin(): RolldownPlugin {
99
return {
1010
name: 'vite:load-fallback',
11-
async load(id) {
12-
try {
13-
const cleanedId = cleanUrl(id)
14-
const content = await fsp.readFile(cleanedId, 'utf-8')
15-
this.addWatchFile(cleanedId)
16-
return content
17-
} catch {
18-
const content = await fsp.readFile(id, 'utf-8')
19-
this.addWatchFile(id)
20-
return content
21-
}
11+
load: {
12+
filter: {
13+
id: {
14+
exclude: [/^data:/],
15+
},
16+
},
17+
async handler(id) {
18+
try {
19+
const cleanedId = cleanUrl(id)
20+
const content = await fsp.readFile(cleanedId, 'utf-8')
21+
this.addWatchFile(cleanedId)
22+
return content
23+
} catch {
24+
const content = await fsp.readFile(id, 'utf-8')
25+
this.addWatchFile(id)
26+
return content
27+
}
28+
},
2229
},
2330
}
2431
}

0 commit comments

Comments
 (0)