From a00f6f6cc228697e7c87aa24abe32c0d88dc846b Mon Sep 17 00:00:00 2001 From: FinalAshen <819712530@qq.com> Date: Tue, 12 Dec 2023 09:15:49 +0800 Subject: [PATCH] fix: import.meta compilation error --- packages/vite/src/node/plugins/worker.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index a656b6d07e6916..8d53b01cfe33f5 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -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