From c07360d589f8810f5079f87485f7b6c7b606b4e8 Mon Sep 17 00:00:00 2001 From: yume-chan Date: Mon, 28 Aug 2023 15:09:17 +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..a85e56d9a52c19 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 ||