Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Jun 18, 2024
1 parent 7b240e4 commit 0b5b77c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
workerConstructor === 'Worker'
? `${encodedJs}
const decodeBase64 = (base64) => Uint8Array.from(atob(base64), c => c.charCodeAt(0));
const blob = typeof window !== "undefined" && window.Blob && new Blob([${
const blob = typeof self !== "undefined" && self.Blob && new Blob([${
workerType === 'classic'
? ''
: // `URL` is always available, in `Worker[type="module"]`
Expand All @@ -314,11 +314,11 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
export default function WorkerWrapper(options) {
let objURL;
try {
objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
if (!objURL) throw ''
const worker = new ${workerConstructor}(objURL, ${workerTypeOption});
worker.addEventListener("error", () => {
(window.URL || window.webkitURL).revokeObjectURL(objURL);
(self.URL || self.webkitURL).revokeObjectURL(objURL);
});
return worker;
} catch(e) {
Expand All @@ -331,7 +331,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
// otherwise the worker fails to run
workerType === 'classic'
? ` finally {
objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
objURL && (self.URL || self.webkitURL).revokeObjectURL(objURL);
}`
: ''
}
Expand Down

0 comments on commit 0b5b77c

Please sign in to comment.