File tree 2 files changed +12
-5
lines changed
playground/worker/__tests__
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,6 @@ if (isBuild) {
28
28
// chunk
29
29
expect ( content ) . toMatch ( `new Worker("/assets` )
30
30
// inlined
31
- expect ( content ) . toMatch ( `new Worker("data:application/javascript ` )
31
+ expect ( content ) . toMatch ( `(window.URL||window.webkitURL).createObjectURL ` )
32
32
} )
33
33
}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
43
43
let url : string
44
44
if ( isBuild ) {
45
45
if ( query . inline != null ) {
46
- // bundle the file as entry to support imports and inline as base64
46
+ // bundle the file as entry to support imports and inline as blob
47
47
// data url
48
48
const rollup = require ( 'rollup' ) as typeof Rollup
49
49
const bundle = await rollup . rollup ( {
@@ -55,9 +55,16 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
55
55
format : 'es' ,
56
56
sourcemap : config . build . sourcemap
57
57
} )
58
- url = `data:application/javascript;base64,${ Buffer . from (
59
- output [ 0 ] . code
60
- ) . toString ( 'base64' ) } `
58
+
59
+ return `const blob = new Blob([atob(\"${ Buffer . from ( output [ 0 ] . code ) . toString ( 'base64' ) } \")], { type: 'text/javascript;charset=utf-8' });
60
+ export default function WorkerWrapper() {
61
+ const objURL = (window.URL || window.webkitURL).createObjectURL(blob);
62
+ try {
63
+ return new Worker(objURL);
64
+ } finally {
65
+ (window.URL || window.webkitURL).revokeObjectURL(objURL);
66
+ }
67
+ }`
61
68
} finally {
62
69
await bundle . close ( )
63
70
}
You can’t perform that action at this time.
0 commit comments