From 8e9e383cdefc4c1bc3689cfe0ab5afbe24342833 Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:43:56 +0800 Subject: [PATCH] fix: add source map to Web Workers --- packages/vite/src/node/plugins/worker.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index 5c77012b02427e..06535530a6d897 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -274,9 +274,15 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin { injectEnv = module?.transformResult?.code || '' } } - return { - code: injectEnv + raw, + if (injectEnv) { + const s = new MagicString(raw) + s.prepend(injectEnv) + return { + code: s.toString(), + map: s.generateMap({ hires: 'boundary' }), + } } + return } if ( query == null ||