@@ -322,21 +322,18 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
322322 urlCode = 'self.location.href'
323323 } else if ( inlineRE . test ( id ) ) {
324324 const chunk = await bundleWorkerEntry ( config , id )
325- const encodedJs = `const encodedJs = "${ Buffer . from (
326- chunk . code ,
327- ) . toString ( 'base64' ) } ";`
325+ const jsContent = `const jsContent = ${ JSON . stringify ( chunk . code ) } ;`
328326
329327 const code =
330328 // Using blob URL for SharedWorker results in multiple instances of a same worker
331329 workerConstructor === 'Worker'
332- ? `${ encodedJs }
333- const decodeBase64 = (base64) => Uint8Array.from(atob(base64), c => c.charCodeAt(0));
330+ ? `${ jsContent }
334331 const blob = typeof self !== "undefined" && self.Blob && new Blob([${
335332 workerType === 'classic'
336333 ? ''
337334 : // `URL` is always available, in `Worker[type="module"]`
338335 `'URL.revokeObjectURL(import.meta.url);',`
339- } decodeBase64(encodedJs) ], { type: "text/javascript;charset=utf-8" });
336+ } jsContent ], { type: "text/javascript;charset=utf-8" });
340337 export default function WorkerWrapper(options) {
341338 let objURL;
342339 try {
@@ -349,7 +346,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
349346 return worker;
350347 } catch(e) {
351348 return new ${ workerConstructor } (
352- " data:text/javascript;base64," + encodedJs ,
349+ ' data:text/javascript;charset=utf-8,' + encodeURIComponent(jsContent) ,
353350 ${ workerTypeOption }
354351 );
355352 }${
@@ -362,10 +359,10 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
362359 : ''
363360 }
364361 }`
365- : `${ encodedJs }
362+ : `${ jsContent }
366363 export default function WorkerWrapper(options) {
367364 return new ${ workerConstructor } (
368- " data:text/javascript;base64," + encodedJs ,
365+ ' data:text/javascript;charset=utf-8,' + encodeURIComponent(jsContent) ,
369366 ${ workerTypeOption }
370367 );
371368 }
0 commit comments