Skip to content

Commit

Permalink
fix: import.meta compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
XiSenao committed Dec 12, 2023
1 parent 3e42611 commit a00f6f6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/vite/src/node/plugins/worker.ts
Expand Up @@ -165,10 +165,19 @@ export async function workerFileToUrl(
export function webWorkerPostPlugin(): Plugin {
return {
name: 'vite:worker-post',
resolveImportMeta(property, { chunkId, format }) {
resolveImportMeta(property, { format }) {
// document is undefined in the worker, so we need to avoid it in iife
if (property === 'url' && format === 'iife') {
return 'self.location.href'
if (format === 'iife') {
// compiling import.meta
if (!property) {
return `{
url: self.location.href
}`
}
// compiling import.meta.url
if (property === 'url') {
return 'self.location.href'
}
}

return null
Expand Down

0 comments on commit a00f6f6

Please sign in to comment.