mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix(data-uri): only match ids starting with data:
(#18241)
This commit is contained in:
parent
eae00b561e
commit
96084d6e75
@ -22,7 +22,7 @@ export function dataURIPlugin(): Plugin {
|
||||
},
|
||||
|
||||
resolveId(id) {
|
||||
if (!dataUriRE.test(id)) {
|
||||
if (!id.trimStart().startsWith('data:')) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<div class="plain"></div>
|
||||
<div class="base64"></div>
|
||||
<div class="comma"></div>
|
||||
|
||||
<script type="module">
|
||||
import msg from "data:text/javascript, export default 'hi'"
|
||||
@ -8,6 +9,9 @@
|
||||
import base64Msg from 'data:text/javascript;base64, ZXhwb3J0IGRlZmF1bHQgJ2hpJw=='
|
||||
text('.base64', base64Msg)
|
||||
|
||||
import { comma } from 'comma/foo?number=1,2,3'
|
||||
text('.comma', comma)
|
||||
|
||||
function text(el, text) {
|
||||
document.querySelector(el).textContent = text
|
||||
}
|
||||
|
20
playground/data-uri/vite.config.js
Normal file
20
playground/data-uri/vite.config.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
{
|
||||
name: 'post-plugin',
|
||||
enforce: 'post',
|
||||
resolveId(id) {
|
||||
if (id.replace(/\?.*$/, '') === 'comma/foo') {
|
||||
return id
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id.replace(/\?.*$/, '') === 'comma/foo') {
|
||||
return `export const comma = 'hi'`
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
Loading…
Reference in New Issue
Block a user