Skip to content

Commit

Permalink
fix: use data: imports from vitejs#9470
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Aug 18, 2024
1 parent df98149 commit 7291698
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1309,18 +1309,18 @@ async function loadConfigFromBundledFile(
// for esm, before we can register loaders without requiring users to run node
// with --experimental-loader themselves, we have to do a hack here:
// write it to disk, load it with native Node ESM, then delete the file.
// convert to base64, load it with native Node ESM.
if (isESM) {
bundledCode = await transformViteConfigDynamicImport(bundledCode, fileName)
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (await import(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
return (
await import(
'data:text/javascript;base64,' +
Buffer.from(bundledCode).toString('base64')
)
).default
} catch (e) {
throw new Error(`${e.message} at ${fileName}`)
}
}
// for cjs, we can register a custom loader via `_require.extensions`
Expand Down

0 comments on commit 7291698

Please sign in to comment.