File tree 2 files changed +6
-6
lines changed
playground/worker/__tests__ 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -65,5 +65,6 @@ if (isBuild) {
65
65
expect ( content ) . toMatch ( `new SharedWorker("/assets` )
66
66
// inlined
67
67
expect ( content ) . toMatch ( `(window.URL||window.webkitURL).createObjectURL` )
68
+ expect ( content ) . toMatch ( `window.Blob` )
68
69
} )
69
70
}
Original file line number Diff line number Diff line change @@ -75,15 +75,14 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
75
75
const content = Buffer . from ( code )
76
76
if ( query . inline != null ) {
77
77
// inline as blob data url
78
- return `const blob = new Blob([atob(\"${ content . toString (
79
- 'base64'
80
- ) } \")], { type: 'text/javascript;charset=utf-8' });
78
+ return `const encodedJs = "${ content . toString ( 'base64' ) } ";
79
+ const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
81
80
export default function WorkerWrapper() {
82
- const objURL = (window.URL || window.webkitURL).createObjectURL(blob);
81
+ const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
83
82
try {
84
- return new Worker(objURL);
83
+ return objURL ? new Worker(objURL) : new Worker("data:application/javascript;base64," + encodedJs, {type: "module"} );
85
84
} finally {
86
- (window.URL || window.webkitURL).revokeObjectURL(objURL);
85
+ objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
87
86
}
88
87
}`
89
88
} else {
You can’t perform that action at this time.
0 commit comments