From df6f32f4bc893dabebc2afbf68533e7cb8654ccb Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Mon, 4 Sep 2023 02:23:34 +0800 Subject: [PATCH] fix: add source map to Web Workers (fix #14216) (#14217) --- 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 202c8723f45218..ef98a4f2eddb23 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 ||