Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: process "data:" in import correctly #823

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: process "data:" in import correctly
  • Loading branch information
sheremet-va committed Feb 21, 2022
commit 33d2aa159a60066c1e067bfa812414a6ba007ec9
5 changes: 5 additions & 0 deletions packages/vite-node/src/externalize.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
})