forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: skip data uri by load fallback plugin for native data uri hand…
…ling
- Loading branch information
1 parent
5adb440
commit 04c717f
Showing
1 changed file
with
20 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}, | ||
}, | ||
} | ||
} |