Skip to content

Commit ec0efe8

Browse files
authored
fix(data-uri): only match ids starting with data: (#18241)
1 parent b916ab6 commit ec0efe8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

packages/vite/src/node/plugins/dataUri.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function dataURIPlugin(): Plugin {
2222
},
2323

2424
resolveId(id) {
25-
if (!dataUriRE.test(id)) {
25+
if (!id.trimStart().startsWith('data:')) {
2626
return
2727
}
2828

playground/data-uri/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="plain"></div>
22
<div class="base64"></div>
3+
<div class="comma"></div>
34

45
<script type="module">
56
import msg from "data:text/javascript, export default 'hi'"
@@ -8,6 +9,9 @@
89
import base64Msg from 'data:text/javascript;base64, ZXhwb3J0IGRlZmF1bHQgJ2hpJw=='
910
text('.base64', base64Msg)
1011

12+
import { comma } from 'comma/foo?number=1,2,3'
13+
text('.comma', comma)
14+
1115
function text(el, text) {
1216
document.querySelector(el).textContent = text
1317
}

playground/data-uri/vite.config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineConfig } from 'vite'
2+
3+
export default defineConfig({
4+
plugins: [
5+
{
6+
name: 'post-plugin',
7+
enforce: 'post',
8+
resolveId(id) {
9+
if (id.replace(/\?.*$/, '') === 'comma/foo') {
10+
return id
11+
}
12+
},
13+
load(id) {
14+
if (id.replace(/\?.*$/, '') === 'comma/foo') {
15+
return `export const comma = 'hi'`
16+
}
17+
},
18+
},
19+
],
20+
})

0 commit comments

Comments
 (0)