@@ -322,21 +322,18 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
322
322
urlCode = 'self.location.href'
323
323
} else if ( inlineRE . test ( id ) ) {
324
324
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 ) } ;`
328
326
329
327
const code =
330
328
// Using blob URL for SharedWorker results in multiple instances of a same worker
331
329
workerConstructor === 'Worker'
332
- ? `${ encodedJs }
333
- const decodeBase64 = (base64) => Uint8Array.from(atob(base64), c => c.charCodeAt(0));
330
+ ? `${ jsContent }
334
331
const blob = typeof self !== "undefined" && self.Blob && new Blob([${
335
332
workerType === 'classic'
336
333
? ''
337
334
: // `URL` is always available, in `Worker[type="module"]`
338
335
`'URL.revokeObjectURL(import.meta.url);',`
339
- } decodeBase64(encodedJs) ], { type: "text/javascript;charset=utf-8" });
336
+ } jsContent ], { type: "text/javascript;charset=utf-8" });
340
337
export default function WorkerWrapper(options) {
341
338
let objURL;
342
339
try {
@@ -349,7 +346,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
349
346
return worker;
350
347
} catch(e) {
351
348
return new ${ workerConstructor } (
352
- " data:text/javascript;base64," + encodedJs ,
349
+ ' data:text/javascript;charset=utf-8,' + encodeURIComponent(jsContent) ,
353
350
${ workerTypeOption }
354
351
);
355
352
}${
@@ -362,10 +359,10 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
362
359
: ''
363
360
}
364
361
}`
365
- : `${ encodedJs }
362
+ : `${ jsContent }
366
363
export default function WorkerWrapper(options) {
367
364
return new ${ workerConstructor } (
368
- " data:text/javascript;base64," + encodedJs ,
365
+ ' data:text/javascript;charset=utf-8,' + encodeURIComponent(jsContent) ,
369
366
${ workerTypeOption }
370
367
);
371
368
}
0 commit comments