Skip to content

Commit bb4ba9f

Browse files
authoredAug 6, 2024··
fix(worker): fix importScripts injection breaking iife code (#17827)
1 parent 6ae0615 commit bb4ba9f

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed
 

‎.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ playground/html/invalid.html
1111
playground/html/valid.html
1212
playground/external/public/slash@3.0.0.js
1313
playground/ssr-html/public/slash@3.0.0.js
14+
playground/worker/classic-worker.js

‎packages/vite/src/node/plugins/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
265265
}
266266
if (injectEnv) {
267267
const s = new MagicString(raw)
268-
s.prepend(injectEnv)
268+
s.prepend(injectEnv + ';\n')
269269
return {
270270
code: s.toString(),
271271
map: s.generateMap({ hires: 'boundary' }),

‎playground/worker/classic-worker.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(() => {})() // this is to test `importScripts` injection doesn't break the code
2+
13
let base = `/${self.location.pathname.split('/')[1]}`
24
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
35

0 commit comments

Comments
 (0)
Please sign in to comment.