Skip to content

Commit

Permalink
chore: skip data uri by load fallback plugin for native data uri hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
sapphi-red committed Sep 25, 2024
1 parent 5adb440 commit 04c717f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/vite/src/node/plugins/loadFallback.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import fsp from 'node:fs/promises'
import type { RolldownPlugin } from 'rolldown'
import { cleanUrl } from '../../shared/utils'
import type { Plugin } from '../plugin'

/**
* A plugin to provide build load fallback for arbitrary request with queries.
*/
export function buildLoadFallbackPlugin(): Plugin {
export function buildLoadFallbackPlugin(): RolldownPlugin {
return {
name: 'vite:load-fallback',
async load(id) {
try {
const cleanedId = cleanUrl(id)
const content = await fsp.readFile(cleanedId, 'utf-8')
this.addWatchFile(cleanedId)
return content
} catch {
const content = await fsp.readFile(id, 'utf-8')
this.addWatchFile(id)
return content
}
load: {
filter: {
id: {
exclude: [/^data:/],
},
},
async handler(id) {
try {
const cleanedId = cleanUrl(id)
const content = await fsp.readFile(cleanedId, 'utf-8')
this.addWatchFile(cleanedId)
return content
} catch {
const content = await fsp.readFile(id, 'utf-8')
this.addWatchFile(id)
return content
}
},
},
}
}

0 comments on commit 04c717f

Please sign in to comment.