diff --git a/.prettierignore b/.prettierignore index 0fc71ddd1..95541be45 100644 --- a/.prettierignore +++ b/.prettierignore @@ -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 diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index dcaed0473..2e614ec7e 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -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' }), diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js index be6fa357e..d68c61c14 100644 --- a/playground/worker/classic-worker.js +++ b/playground/worker/classic-worker.js @@ -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