fix(worker): fix importScripts injection breaking iife code (#17827)

This commit is contained in:
Hiroshi Ogawa 2024-08-06 23:08:34 +09:00 committed by GitHub
parent 6ae0615416
commit bb4ba9f448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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' }),

View File

@ -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