Skip to content

Commit

Permalink
fix(worker): fix importScripts injection breaking iife code (#17827)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Aug 6, 2024
1 parent 6ae0615 commit bb4ba9f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/slash@3.0.0.js
playground/ssr-html/public/slash@3.0.0.js
playground/worker/classic-worker.js
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
}
if (injectEnv) {
const s = new MagicString(raw)
s.prepend(injectEnv)
s.prepend(injectEnv + ';\n')
return {
code: s.toString(),
map: s.generateMap({ hires: 'boundary' }),
Expand Down
2 changes: 2 additions & 0 deletions playground/worker/classic-worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(() => {})() // this is to test `importScripts` injection doesn't break the code

let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev

Expand Down

0 comments on commit bb4ba9f

Please sign in to comment.