Skip to content

Commit

Permalink
fix: process "data:" in import correctly (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 21, 2022
1 parent 6ca343a commit 600ca80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vite-node/src/externalize.ts
Expand Up @@ -59,6 +59,11 @@ async function _shouldExternalize(
if (isNodeBuiltin(id))
return id

// data: should be processed by native import,
// since it is a feature of ESM
if (id.startsWith('data:'))
return id

id = patchWindowsImportPath(id)

if (matchExternalizePattern(id, options?.inline))
Expand Down
6 changes: 6 additions & 0 deletions test/core/test/imports.test.ts
Expand Up @@ -26,3 +26,9 @@ test('dynamic absolute import works', async() => {

expect(timeout).toBe(dynamicTimeout)
})

test('data with dynamic import works', async() => {
const dataUri = 'data:text/javascript;charset=utf-8,export default "hi"'
const { default: hi } = await import(dataUri)
expect(hi).toBe('hi')
})

0 comments on commit 600ca80

Please sign in to comment.