Skip to content

Commit

Permalink
add revokeObjectURL
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerios committed May 20, 2021
1 parent 662e909 commit 57bdd4f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
sourcemap: config.build.sourcemap
})

return `export default function WorkerWrapper() {
const blob = new Blob([atob(\"${Buffer.from(output[0].code).toString('base64')}\")], { type: 'text/javascript;charset=utf-8' });
return new Worker((window.URL || window.webkitURL).createObjectURL(blob));
return `const blob = new Blob([atob(\"${Buffer.from(output[0].code).toString('base64')}\")], { type: 'text/javascript;charset=utf-8' });
export default function WorkerWrapper() {
const objURL = (window.URL || window.webkitURL).createObjectURL(blob);
try {
return new Worker(objURL);
} finally {
(window.URL || window.webkitURL).revokeObjectURL(objURL);
}
}`
} finally {
await bundle.close()
Expand Down

0 comments on commit 57bdd4f

Please sign in to comment.